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).
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.
10 #include "table/block_based/data_block_footer.h"
12 #include "rocksdb/table.h"
14 namespace ROCKSDB_NAMESPACE
{
16 const int kDataBlockIndexTypeBitShift
= 31;
19 const uint32_t kMaxNumRestarts
= (1u << kDataBlockIndexTypeBitShift
) - 1u;
22 const uint32_t kNumRestartsMask
= (1u << kDataBlockIndexTypeBitShift
) - 1u;
24 uint32_t PackIndexTypeAndNumRestarts(
25 BlockBasedTableOptions::DataBlockIndexType index_type
,
26 uint32_t num_restarts
) {
27 if (num_restarts
> kMaxNumRestarts
) {
28 assert(0); // mute travis "unused" warning
31 uint32_t block_footer
= num_restarts
;
32 if (index_type
== BlockBasedTableOptions::kDataBlockBinaryAndHash
) {
33 block_footer
|= 1u << kDataBlockIndexTypeBitShift
;
34 } else if (index_type
!= BlockBasedTableOptions::kDataBlockBinarySearch
) {
41 void UnPackIndexTypeAndNumRestarts(
42 uint32_t block_footer
,
43 BlockBasedTableOptions::DataBlockIndexType
* index_type
,
44 uint32_t* num_restarts
) {
46 if (block_footer
& 1u << kDataBlockIndexTypeBitShift
) {
47 *index_type
= BlockBasedTableOptions::kDataBlockBinaryAndHash
;
49 *index_type
= BlockBasedTableOptions::kDataBlockBinarySearch
;
54 *num_restarts
= block_footer
& kNumRestartsMask
;
55 assert(*num_restarts
<= kMaxNumRestarts
);
59 } // namespace ROCKSDB_NAMESPACE