YugabyteDB (2.13.1.0-b60, 21121d69985fbf76aa6958d8f04a9bfa936293b5)

Coverage Report

Created: 2022-03-22 16:43

/Users/deen/code/yugabyte-db/src/yb/rocksdb/table/block_builder.h
Line
Count
Source
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
//
6
// The following only applies to changes made to this file as part of YugaByte development.
7
//
8
// Portions Copyright (c) YugaByte, Inc.
9
//
10
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
11
// in compliance with the License.  You may obtain a copy of the License at
12
//
13
// http://www.apache.org/licenses/LICENSE-2.0
14
//
15
// Unless required by applicable law or agreed to in writing, software distributed under the License
16
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
17
// or implied.  See the License for the specific language governing permissions and limitations
18
// under the License.
19
//
20
// Copyright (c) 2011 The LevelDB Authors. All rights reserved.
21
// Use of this source code is governed by a BSD-style license that can be
22
// found in the LICENSE file. See the AUTHORS file for names of contributors.
23
24
#ifndef YB_ROCKSDB_TABLE_BLOCK_BUILDER_H
25
#define YB_ROCKSDB_TABLE_BLOCK_BUILDER_H
26
27
#include <stdint.h>
28
#include <vector>
29
30
#include "yb/rocksdb/types.h"
31
32
#include "yb/util/slice.h"
33
34
namespace rocksdb {
35
36
class BlockBuilder {
37
 public:
38
  BlockBuilder(const BlockBuilder&) = delete;
39
  void operator=(const BlockBuilder&) = delete;
40
41
  explicit BlockBuilder(int block_restart_interval,
42
                        KeyValueEncodingFormat key_value_encoding_format,
43
                        bool use_delta_encoding = true);
44
45
  // Reset the contents as if the BlockBuilder was just constructed.
46
  void Reset();
47
48
  // REQUIRES: Finish() has not been called since the last call to Reset().
49
  // REQUIRES: key is larger than any previously added key
50
  void Add(const Slice& key, const Slice& value);
51
52
  // Finish building the block and return a slice that refers to the
53
  // block contents.  The returned slice will remain valid for the
54
  // lifetime of this builder or until Reset() is called.
55
  Slice Finish();
56
57
  // Returns an estimate of the current (uncompressed) size of the block
58
  // we are building.
59
  size_t CurrentSizeEstimate() const;
60
61
  // Returns an estimated block size after appending key and value.
62
  size_t EstimateSizeAfterKV(const Slice& key, const Slice& value) const;
63
64
  size_t NumKeys() const;
65
66
  // Return true iff no entries have been added since the last Reset()
67
188M
  bool empty() const {
68
188M
    return buffer_.empty();
69
188M
  }
70
71
 private:
72
  const int block_restart_interval_;
73
  const bool use_delta_encoding_;
74
  const KeyValueEncodingFormat key_value_encoding_format_;
75
76
  std::string           buffer_;    // Destination buffer
77
  std::vector<uint32_t> restarts_;  // Restart points
78
  int                   counter_;   // Number of entries emitted since restart
79
  bool                  finished_;  // Has Finish() been called?
80
  std::string           last_key_;
81
};
82
83
}  // namespace rocksdb
84
85
#endif // YB_ROCKSDB_TABLE_BLOCK_BUILDER_H