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).
9 #include "db/dbformat.h"
10 #include "rocksdb/status.h"
12 namespace ROCKSDB_NAMESPACE
{
19 // Build a hash-based index to speed up the lookup for "index block".
20 // BlockHashIndex accepts a key and, if found, returns its restart index within
22 class BlockPrefixIndex
{
24 // Maps a key to a list of data blocks that could potentially contain
25 // the key, based on the prefix.
26 // Returns the total number of relevant blocks, 0 means the key does
28 uint32_t GetBlocks(const Slice
& key
, uint32_t** blocks
);
30 size_t ApproximateMemoryUsage() const {
31 return sizeof(BlockPrefixIndex
) +
32 (num_block_array_buffer_entries_
+ num_buckets_
) * sizeof(uint32_t);
35 // Create hash index by reading from the metadata blocks.
36 // Note: table reader (caller) is responsible for keeping shared_ptr to
37 // underlying prefix extractor
38 // @params prefixes: a sequence of prefixes.
39 // @params prefix_meta: contains the "metadata" to of the prefixes.
40 static Status
Create(const SliceTransform
* hash_key_extractor
,
41 const Slice
& prefixes
, const Slice
& prefix_meta
,
42 BlockPrefixIndex
** prefix_index
);
46 delete[] block_array_buffer_
;
53 BlockPrefixIndex(const SliceTransform
* prefix_extractor
, uint32_t num_buckets
,
54 uint32_t* buckets
, uint32_t num_block_array_buffer_entries
,
55 uint32_t* block_array_buffer
)
56 : internal_prefix_extractor_(prefix_extractor
),
57 num_buckets_(num_buckets
),
58 num_block_array_buffer_entries_(num_block_array_buffer_entries
),
60 block_array_buffer_(block_array_buffer
) {}
62 InternalKeySliceTransform internal_prefix_extractor_
;
64 uint32_t num_buckets_
;
65 uint32_t num_block_array_buffer_entries_
;
67 uint32_t* block_array_buffer_
;
70 } // namespace ROCKSDB_NAMESPACE