MCPcopy Create free account
hub / github.com/ElementsProject/elements / ApproximateOffsetOf

Method ApproximateOffsetOf

src/leveldb/table/table.cc:246–271  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

244}
245
246uint64_t Table::ApproximateOffsetOf(const Slice& key) const {
247 Iterator* index_iter =
248 rep_->index_block->NewIterator(rep_->options.comparator);
249 index_iter->Seek(key);
250 uint64_t result;
251 if (index_iter->Valid()) {
252 BlockHandle handle;
253 Slice input = index_iter->value();
254 Status s = handle.DecodeFrom(&input);
255 if (s.ok()) {
256 result = handle.offset();
257 } else {
258 // Strange: we can't decode the block handle in the index block.
259 // We'll just return the offset of the metaindex block, which is
260 // close to the whole file size for this case.
261 result = rep_->metaindex_handle.offset();
262 }
263 } else {
264 // key is past the last key in the file. Approximate the offset
265 // by returning the offset of the metaindex block (which is
266 // right near the end of the file).
267 result = rep_->metaindex_handle.offset();
268 }
269 delete index_iter;
270 return result;
271}
272
273} // namespace leveldb

Callers

nothing calls this directly

Calls 6

offsetMethod · 0.80
NewIteratorMethod · 0.45
SeekMethod · 0.45
ValidMethod · 0.45
valueMethod · 0.45
DecodeFromMethod · 0.45

Tested by

no test coverage detected