mirror of
https://github.com/scylladb/scylladb.git
synced 2026-04-19 16:15:07 +00:00
sstable: make comparison logic part of key
With this, we will be able to override it if needed. Signed-off-by: Glauber Costa <glommer@cloudius-systems.com>
This commit is contained in:
@@ -59,6 +59,9 @@ public:
|
||||
|
||||
std::vector<bytes> explode(const schema& s) const;
|
||||
|
||||
int32_t tri_compare(key_view k) const {
|
||||
return compare_unsigned(bytes_view(_bytes), bytes_view(k));
|
||||
}
|
||||
operator key_view() const {
|
||||
return key_view(_bytes);
|
||||
}
|
||||
|
||||
@@ -40,7 +40,6 @@ int sstable::binary_search(const T& entries, const key& sk, const dht::token& to
|
||||
int low = 0, mid = entries.size(), high = mid - 1, result = -1;
|
||||
|
||||
auto& partitioner = dht::global_partitioner();
|
||||
auto sk_bytes = bytes_view(sk);
|
||||
|
||||
while (low <= high) {
|
||||
// The token comparison should yield the right result most of the time.
|
||||
@@ -53,7 +52,7 @@ int sstable::binary_search(const T& entries, const key& sk, const dht::token& to
|
||||
auto mid_token = partitioner.get_token(mid_key);
|
||||
|
||||
if (token == mid_token) {
|
||||
result = compare_unsigned(sk_bytes, mid_bytes);
|
||||
result = sk.tri_compare(mid_key);
|
||||
} else {
|
||||
result = token < mid_token ? -1 : 1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user