/src/rocksdb/table/block_based/data_block_footer.cc
Line | Count | Source (jump to first uncovered line) |
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). |
5 | | // |
6 | | // Copyright (c) 2011 The LevelDB Authors. All rights reserved. |
7 | | // Use of this source code is governed by a BSD-style license that can be |
8 | | // found in the LICENSE file. See the AUTHORS file for names of contributors. |
9 | | |
10 | | #include "table/block_based/data_block_footer.h" |
11 | | |
12 | | #include "rocksdb/table.h" |
13 | | |
14 | | namespace ROCKSDB_NAMESPACE { |
15 | | |
16 | | const int kDataBlockIndexTypeBitShift = 31; |
17 | | |
18 | | // 0x7FFFFFFF |
19 | | const uint32_t kMaxNumRestarts = (1u << kDataBlockIndexTypeBitShift) - 1u; |
20 | | |
21 | | // 0x7FFFFFFF |
22 | | const uint32_t kNumRestartsMask = (1u << kDataBlockIndexTypeBitShift) - 1u; |
23 | | |
24 | | uint32_t PackIndexTypeAndNumRestarts( |
25 | | BlockBasedTableOptions::DataBlockIndexType index_type, |
26 | 27.5k | uint32_t num_restarts) { |
27 | 27.5k | if (num_restarts > kMaxNumRestarts) { |
28 | 0 | assert(0); // mute travis "unused" warning |
29 | 0 | } |
30 | | |
31 | 27.5k | uint32_t block_footer = num_restarts; |
32 | 27.5k | if (index_type == BlockBasedTableOptions::kDataBlockBinaryAndHash) { |
33 | 0 | block_footer |= 1u << kDataBlockIndexTypeBitShift; |
34 | 27.5k | } else if (index_type != BlockBasedTableOptions::kDataBlockBinarySearch) { |
35 | 0 | assert(0); |
36 | 0 | } |
37 | | |
38 | 27.5k | return block_footer; |
39 | 27.5k | } |
40 | | |
41 | | void UnPackIndexTypeAndNumRestarts( |
42 | | uint32_t block_footer, |
43 | | BlockBasedTableOptions::DataBlockIndexType* index_type, |
44 | 65.8k | uint32_t* num_restarts) { |
45 | 65.8k | if (index_type) { |
46 | 65.8k | if (block_footer & 1u << kDataBlockIndexTypeBitShift) { |
47 | 0 | *index_type = BlockBasedTableOptions::kDataBlockBinaryAndHash; |
48 | 65.8k | } else { |
49 | 65.8k | *index_type = BlockBasedTableOptions::kDataBlockBinarySearch; |
50 | 65.8k | } |
51 | 65.8k | } |
52 | | |
53 | 65.8k | if (num_restarts) { |
54 | 65.8k | *num_restarts = block_footer & kNumRestartsMask; |
55 | 65.8k | assert(*num_restarts <= kMaxNumRestarts); |
56 | 65.8k | } |
57 | 65.8k | } |
58 | | |
59 | | } // namespace ROCKSDB_NAMESPACE |