OpenCBDC Transaction Processor
Loading...
Searching...
No Matches
index_comparator.cpp
Go to the documentation of this file.
1// Copyright (c) 2021 MIT Digital Currency Initiative,
2// Federal Reserve Bank of Boston
3// Distributed under the MIT software license, see the accompanying
4// file COPYING or http://www.opensource.org/licenses/mit-license.php.
5
7
8#include <cstdint>
9#include <cstring>
10#include <leveldb/slice.h>
11
12namespace cbdc::raft {
13 auto index_comparator::Compare(const leveldb::Slice& a,
14 const leveldb::Slice& b) const -> int {
15 assert(a.size() == b.size());
16 uint64_t a_val{0};
17 uint64_t b_val{0};
18 std::memcpy(&a_val, a.data(), sizeof(a_val));
19 std::memcpy(&b_val, b.data(), sizeof(b_val));
20 if(a_val == b_val) {
21 return 0;
22 }
23
24 if(a_val < b_val) {
25 return -1;
26 }
27
28 return 1;
29 }
30
31 auto index_comparator::Name() const -> const char* {
32 return "IndexComparator";
33 }
34
36 std::string* /* start */,
37 const leveldb::Slice& /* limit */) const {}
38
39 void index_comparator::FindShortSuccessor(std::string* /* key */) const {}
40}
void FindShortestSeparator(std::string *, const leveldb::Slice &) const override
Not implemented.
void FindShortSuccessor(std::string *) const override
Not implemented.
auto Compare(const leveldb::Slice &a, const leveldb::Slice &b) const -> int override
Compare the order of the two given LevelDB keys when converted to uint64_t.
auto Name() const -> const char *override
Return the comparator name.