1 // Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
2 // This source code is licensed under both the GPLv2 (found in the
3 // COPYING file in the root directory) and Apache 2.0 License
4 // (found in the LICENSE.Apache file in the root directory).
8 #include "rocksdb/status.h"
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
20 class BlockPrefixIndex
{
22 // Maps a key to a list of data blocks that could potentially contain
23 // the key, based on the prefix.
24 // Returns the total number of relevant blocks, 0 means the key does
26 uint32_t GetBlocks(const Slice
& key
, uint32_t** blocks
);
28 size_t ApproximateMemoryUsage() const {
29 return sizeof(BlockPrefixIndex
) +
30 (num_block_array_buffer_entries_
+ num_buckets_
) * sizeof(uint32_t);
33 // Create hash index by reading from the metadata blocks.
34 // @params prefixes: a sequence of prefixes.
35 // @params prefix_meta: contains the "metadata" to of the prefixes.
36 static Status
Create(const SliceTransform
* hash_key_extractor
,
37 const Slice
& prefixes
, const Slice
& prefix_meta
,
38 BlockPrefixIndex
** prefix_index
);
42 delete[] block_array_buffer_
;
49 BlockPrefixIndex(const SliceTransform
* internal_prefix_extractor
,
50 uint32_t num_buckets
, uint32_t* buckets
,
51 uint32_t num_block_array_buffer_entries
,
52 uint32_t* block_array_buffer
)
53 : internal_prefix_extractor_(internal_prefix_extractor
),
54 num_buckets_(num_buckets
),
55 num_block_array_buffer_entries_(num_block_array_buffer_entries
),
57 block_array_buffer_(block_array_buffer
) {}
59 const SliceTransform
* internal_prefix_extractor_
;
60 uint32_t num_buckets_
;
61 uint32_t num_block_array_buffer_entries_
;
63 uint32_t* block_array_buffer_
;
66 } // namespace rocksdb