24 :
data_(contents.data.data()),
25 size_(contents.data.size()),
26 owned_(contents.heap_allocated) {
53 static inline const char* DecodeEntry(
const char* p,
const char* limit,
57 if (limit - p < 3)
return NULL;
58 *shared =
reinterpret_cast<const unsigned char*
>(p)[0];
59 *non_shared =
reinterpret_cast<const unsigned char*
>(p)[1];
60 *value_length =
reinterpret_cast<const unsigned char*
>(p)[2];
61 if ((*shared | *non_shared | *value_length) < 128) {
66 if ((p =
GetVarint32Ptr(p, limit, non_shared)) == NULL)
return NULL;
67 if ((p =
GetVarint32Ptr(p, limit, value_length)) == NULL)
return NULL;
70 if (static_cast<uint32_t>(limit - p) < (*non_shared + *value_length)) {
91 return comparator_->
Compare(a, b);
96 return (value_.
data() + value_.
size()) - data_;
100 assert(index < num_restarts_);
106 restart_index_ = index;
111 value_ =
Slice(data_ + offset, 0);
119 : comparator_(comparator),
122 num_restarts_(num_restarts),
124 restart_index_(num_restarts_) {
125 assert(num_restarts_ > 0);
150 if (restart_index_ == 0) {
170 while (left < right) {
171 uint32_t mid = (left + right + 1) / 2;
174 const char* key_ptr = DecodeEntry(data_ + region_offset,
176 &shared, &non_shared, &value_length);
177 if (key_ptr == NULL || (shared != 0)) {
181 Slice mid_key(key_ptr, non_shared);
182 if (
Compare(mid_key, target) < 0) {
199 if (
Compare(key_, target) >= 0) {
239 p = DecodeEntry(p, limit, &shared, &non_shared, &value_length);
240 if (p == NULL || key_.size() <
shared) {
245 key_.append(p, non_shared);
246 value_ =
Slice(p + non_shared, value_length);
247 while (restart_index_ + 1 < num_restarts_ &&
261 if (num_restarts == 0) {
Iter(const Comparator *comparator, const char *data, uint32_t restarts, uint32_t num_restarts)
const char * data() const
const char * GetVarint32Ptr(const char *p, const char *limit, uint32_t *v)
const Comparator *const comparator_
static Status Corruption(const Slice &msg, const Slice &msg2=Slice())
virtual void Seek(const Slice &target)
Block(const BlockContents &contents)
uint32_t DecodeFixed32(const char *ptr)
virtual Slice key() const
virtual Status status() const
Iterator * NewIterator(const Comparator *comparator)
virtual void SeekToFirst()
Iterator * NewErrorIterator(const Status &status)
Iterator * NewEmptyIterator()
void SeekToRestartPoint(uint32_t index)
virtual bool Valid() const
virtual int Compare(const Slice &a, const Slice &b) const =0
int Compare(const Slice &a, const Slice &b) const
virtual Slice value() const
uint32_t NumRestarts() const
uint32_t const num_restarts_
uint32_t GetRestartPoint(uint32_t index)
virtual void SeekToLast()
uint32_t NextEntryOffset() const