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:
Glauber Costa
2015-05-20 21:22:19 -04:00
parent 5134631fed
commit f1ad76cd33
2 changed files with 4 additions and 2 deletions

View File

@@ -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);
}

View File

@@ -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;
}