| 244 | } |
| 245 | |
| 246 | uint64_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 |
nothing calls this directly
no test coverage detected