]>
git.proxmox.com Git - ceph.git/blob - 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.
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.
14 #include "rocksdb/slice.h"
20 BlockBuilder(const BlockBuilder
&) = delete;
21 void operator=(const BlockBuilder
&) = delete;
23 explicit BlockBuilder(int block_restart_interval
,
24 bool use_delta_encoding
= true);
26 // Reset the contents as if the BlockBuilder was just constructed.
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
);
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.
38 // Returns an estimate of the current (uncompressed) size of the block
40 inline size_t CurrentSizeEstimate() const { return estimate_
; }
42 // Returns an estimated block size after appending key and value.
43 size_t EstimateSizeAfterKV(const Slice
& key
, const Slice
& value
) const;
45 // Return true iff no entries have been added since the last Reset()
47 return buffer_
.empty();
51 const int block_restart_interval_
;
52 const bool use_delta_encoding_
;
54 std::string buffer_
; // Destination buffer
55 std::vector
<uint32_t> restarts_
; // Restart points
57 int counter_
; // Number of entries emitted since restart
58 bool finished_
; // Has Finish() been called?
59 std::string last_key_
;
62 } // namespace rocksdb