]> git.proxmox.com Git - ceph.git/blob - ceph/src/rocksdb/table/block_builder.h
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / rocksdb / table / block_builder.h
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 // 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 #pragma once
11 #include <vector>
12
13 #include <stdint.h>
14 #include "rocksdb/slice.h"
15
16 namespace rocksdb {
17
18 class BlockBuilder {
19 public:
20 BlockBuilder(const BlockBuilder&) = delete;
21 void operator=(const BlockBuilder&) = delete;
22
23 explicit BlockBuilder(int block_restart_interval,
24 bool use_delta_encoding = true);
25
26 // Reset the contents as if the BlockBuilder was just constructed.
27 void Reset();
28
29 // REQUIRES: Finish() has not been called since the last call to Reset().
30 // REQUIRES: key is larger than any previously added key
31 void Add(const Slice& key, const Slice& value);
32
33 // Finish building the block and return a slice that refers to the
34 // block contents. The returned slice will remain valid for the
35 // lifetime of this builder or until Reset() is called.
36 Slice Finish();
37
38 // Returns an estimate of the current (uncompressed) size of the block
39 // we are building.
40 inline size_t CurrentSizeEstimate() const { return estimate_; }
41
42 // Returns an estimated block size after appending key and value.
43 size_t EstimateSizeAfterKV(const Slice& key, const Slice& value) const;
44
45 // Return true iff no entries have been added since the last Reset()
46 bool empty() const {
47 return buffer_.empty();
48 }
49
50 private:
51 const int block_restart_interval_;
52 const bool use_delta_encoding_;
53
54 std::string buffer_; // Destination buffer
55 std::vector<uint32_t> restarts_; // Restart points
56 size_t estimate_;
57 int counter_; // Number of entries emitted since restart
58 bool finished_; // Has Finish() been called?
59 std::string last_key_;
60 };
61
62 } // namespace rocksdb