]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // Copyright (c) 2011-present, Facebook, Inc. All rights reserved. |
2 | // This source code is licensed under the BSD-style license found in the | |
3 | // LICENSE file in the root directory of this source tree. An additional grant | |
4 | // of patent rights can be found in the PATENTS file in the same directory. | |
5 | #pragma once | |
6 | ||
7 | #include <stdint.h> | |
8 | #include "rocksdb/status.h" | |
9 | ||
10 | namespace rocksdb { | |
11 | ||
12 | class Comparator; | |
13 | class Iterator; | |
14 | class Slice; | |
15 | class SliceTransform; | |
16 | ||
17 | // Build a hash-based index to speed up the lookup for "index block". | |
18 | // BlockHashIndex accepts a key and, if found, returns its restart index within | |
19 | // that index block. | |
20 | class BlockPrefixIndex { | |
21 | public: | |
22 | ||
23 | // Maps a key to a list of data blocks that could potentially contain | |
24 | // the key, based on the prefix. | |
25 | // Returns the total number of relevant blocks, 0 means the key does | |
26 | // not exist. | |
27 | uint32_t GetBlocks(const Slice& key, uint32_t** blocks); | |
28 | ||
29 | size_t ApproximateMemoryUsage() const { | |
30 | return sizeof(BlockPrefixIndex) + | |
31 | (num_block_array_buffer_entries_ + num_buckets_) * sizeof(uint32_t); | |
32 | } | |
33 | ||
34 | // Create hash index by reading from the metadata blocks. | |
35 | // @params prefixes: a sequence of prefixes. | |
36 | // @params prefix_meta: contains the "metadata" to of the prefixes. | |
37 | static Status Create(const SliceTransform* hash_key_extractor, | |
38 | const Slice& prefixes, const Slice& prefix_meta, | |
39 | BlockPrefixIndex** prefix_index); | |
40 | ||
41 | ~BlockPrefixIndex() { | |
42 | delete[] buckets_; | |
43 | delete[] block_array_buffer_; | |
44 | } | |
45 | ||
46 | private: | |
47 | class Builder; | |
48 | friend Builder; | |
49 | ||
50 | BlockPrefixIndex(const SliceTransform* internal_prefix_extractor, | |
51 | uint32_t num_buckets, | |
52 | uint32_t* buckets, | |
53 | uint32_t num_block_array_buffer_entries, | |
54 | uint32_t* block_array_buffer) | |
55 | : internal_prefix_extractor_(internal_prefix_extractor), | |
56 | num_buckets_(num_buckets), | |
57 | num_block_array_buffer_entries_(num_block_array_buffer_entries), | |
58 | buckets_(buckets), | |
59 | block_array_buffer_(block_array_buffer) {} | |
60 | ||
61 | const SliceTransform* internal_prefix_extractor_; | |
62 | uint32_t num_buckets_; | |
63 | uint32_t num_block_array_buffer_entries_; | |
64 | uint32_t* buckets_; | |
65 | uint32_t* block_array_buffer_; | |
66 | }; | |
67 | ||
68 | } // namespace rocksdb |