sstables: Obtain the key from entries using get_key() rather than casting to bytes_view

The entry contains not only the key, but other stuff like
position. Why would casting to bytes_view give the view on just the
key and not the whole entry. Better to be explicit.
This commit is contained in:
Tomasz Grabiec
2015-07-15 14:04:48 +02:00
parent 0b5f908a0b
commit e9a050da78
2 changed files with 7 additions and 7 deletions

View File

@@ -33,7 +33,7 @@ namespace sstables {
* the extra information when not needed.
*
* This code should work in all kinds of vectors in whose's elements is possible to aquire
* a key view.
* a key view via get_key().
*/
template <typename T>
int sstable::binary_search(const T& entries, const key& sk, const dht::token& token) {
@@ -47,8 +47,7 @@ int sstable::binary_search(const T& entries, const key& sk, const dht::token& to
// creation by keeping only a key view, and then manually carrying out
// both parts of the comparison ourselves.
mid = low + ((high - low) >> 1);
auto mid_bytes = bytes_view(entries[mid]);
auto mid_key = key_view(mid_bytes);
key_view mid_key = entries[mid].get_key();
auto mid_token = partitioner.get_token(mid_key);
if (token == mid_token) {

View File

@@ -12,6 +12,7 @@
#include "streaming_histogram.hh"
#include "estimated_histogram.hh"
#include "column_name_helper.hh"
#include "sstables/key.hh"
#include <vector>
#include <unordered_map>
#include <type_traits>
@@ -43,8 +44,8 @@ struct index_entry {
uint64_t position;
disk_string<uint32_t> promoted_index;
explicit operator bytes_view() const {
return bytes_view(key);
key_view get_key() const {
return { bytes_view(key) };
}
};
@@ -52,8 +53,8 @@ struct summary_entry {
bytes key;
uint64_t position;
explicit operator bytes_view() const {
return key;
key_view get_key() const {
return { key };
}
bool operator==(const summary_entry& x) const {