From f1ad76cd339419eb0b5c1530777c9bbbc12b4e4e Mon Sep 17 00:00:00 2001 From: Glauber Costa Date: Wed, 20 May 2015 21:22:19 -0400 Subject: [PATCH] sstable: make comparison logic part of key With this, we will be able to override it if needed. Signed-off-by: Glauber Costa --- sstables/key.hh | 3 +++ sstables/partition.cc | 3 +-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/sstables/key.hh b/sstables/key.hh index 856dfcdf35..c703ca0ef6 100644 --- a/sstables/key.hh +++ b/sstables/key.hh @@ -59,6 +59,9 @@ public: std::vector 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); } diff --git a/sstables/partition.cc b/sstables/partition.cc index 476d3d143b..8f512e1395 100644 --- a/sstables/partition.cc +++ b/sstables/partition.cc @@ -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; }