1
// Copyright (c) 2011 The LevelDB Authors. All rights reserved.
2
// Use of this source code is governed by a BSD-style license that can be
3
// found in the LICENSE file. See the AUTHORS file for names of contributors.
5
#ifndef STORAGE_LEVELDB_TABLE_BLOCK_BUILDER_H_
6
#define STORAGE_LEVELDB_TABLE_BLOCK_BUILDER_H_
11
#include "leveldb/slice.h"
19
explicit BlockBuilder(const Options* options);
21
// Reset the contents as if the BlockBuilder was just constructed.
24
// REQUIRES: Finish() has not been callled since the last call to Reset().
25
// REQUIRES: key is larger than any previously added key
26
void Add(const Slice& key, const Slice& value);
28
// Finish building the block and return a slice that refers to the
29
// block contents. The returned slice will remain valid for the
30
// lifetime of this builder or until Reset() is called.
33
// Returns an estimate of the current (uncompressed) size of the block
35
size_t CurrentSizeEstimate() const;
37
// Return true iff no entries have been added since the last Reset()
39
return buffer_.empty();
43
const Options* options_;
44
std::string buffer_; // Destination buffer
45
std::vector<uint32_t> restarts_; // Restart points
46
int counter_; // Number of entries emitted since restart
47
bool finished_; // Has Finish() been called?
48
std::string last_key_;
51
BlockBuilder(const BlockBuilder&);
52
void operator=(const BlockBuilder&);
55
} // namespace leveldb
57
#endif // STORAGE_LEVELDB_TABLE_BLOCK_BUILDER_H_