fork of https://github.com/oxigraph/rocksdb and https://github.com/facebook/rocksdb for nextgraph and oxigraph
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
76 lines
2.9 KiB
76 lines
2.9 KiB
9 years ago
|
// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
|
||
8 years ago
|
// This source code is licensed under both the GPLv2 (found in the
|
||
|
// COPYING file in the root directory) and Apache 2.0 License
|
||
|
// (found in the LICENSE.Apache file in the root directory).
|
||
11 years ago
|
//
|
||
14 years ago
|
// Copyright (c) 2011 The LevelDB Authors. All rights reserved.
|
||
|
// Use of this source code is governed by a BSD-style license that can be
|
||
|
// found in the LICENSE file. See the AUTHORS file for names of contributors.
|
||
|
|
||
11 years ago
|
#pragma once
|
||
14 years ago
|
#include <vector>
|
||
|
|
||
|
#include <stdint.h>
|
||
12 years ago
|
#include "rocksdb/slice.h"
|
||
6 years ago
|
#include "rocksdb/table.h"
|
||
6 years ago
|
#include "table/block_based/data_block_hash_index.h"
|
||
14 years ago
|
|
||
11 years ago
|
namespace rocksdb {
|
||
14 years ago
|
|
||
|
class BlockBuilder {
|
||
|
public:
|
||
10 years ago
|
BlockBuilder(const BlockBuilder&) = delete;
|
||
|
void operator=(const BlockBuilder&) = delete;
|
||
10 years ago
|
|
||
9 years ago
|
explicit BlockBuilder(int block_restart_interval,
|
||
6 years ago
|
bool use_delta_encoding = true,
|
||
6 years ago
|
bool use_value_delta_encoding = false,
|
||
|
BlockBasedTableOptions::DataBlockIndexType index_type =
|
||
|
BlockBasedTableOptions::kDataBlockBinarySearch,
|
||
|
double data_block_hash_table_util_ratio = 0.75);
|
||
10 years ago
|
|
||
14 years ago
|
// Reset the contents as if the BlockBuilder was just constructed.
|
||
|
void Reset();
|
||
|
|
||
8 years ago
|
// REQUIRES: Finish() has not been called since the last call to Reset().
|
||
14 years ago
|
// REQUIRES: key is larger than any previously added key
|
||
6 years ago
|
void Add(const Slice& key, const Slice& value,
|
||
|
const Slice* const delta_value = nullptr);
|
||
14 years ago
|
|
||
|
// Finish building the block and return a slice that refers to the
|
||
|
// block contents. The returned slice will remain valid for the
|
||
|
// lifetime of this builder or until Reset() is called.
|
||
|
Slice Finish();
|
||
|
|
||
|
// Returns an estimate of the current (uncompressed) size of the block
|
||
|
// we are building.
|
||
6 years ago
|
inline size_t CurrentSizeEstimate() const {
|
||
|
return estimate_ + (data_block_hash_index_builder_.Valid()
|
||
|
? data_block_hash_index_builder_.EstimateSize()
|
||
|
: 0);
|
||
|
}
|
||
14 years ago
|
|
||
12 years ago
|
// Returns an estimated block size after appending key and value.
|
||
|
size_t EstimateSizeAfterKV(const Slice& key, const Slice& value) const;
|
||
|
|
||
14 years ago
|
// Return true iff no entries have been added since the last Reset()
|
||
6 years ago
|
bool empty() const { return buffer_.empty(); }
|
||
14 years ago
|
|
||
|
private:
|
||
6 years ago
|
const int block_restart_interval_;
|
||
6 years ago
|
// TODO(myabandeh): put it into a separate IndexBlockBuilder
|
||
6 years ago
|
const bool use_delta_encoding_;
|
||
6 years ago
|
// Refer to BlockIter::DecodeCurrentValue for format of delta encoded values
|
||
|
const bool use_value_delta_encoding_;
|
||
11 years ago
|
|
||
6 years ago
|
std::string buffer_; // Destination buffer
|
||
11 years ago
|
std::vector<uint32_t> restarts_; // Restart points
|
||
6 years ago
|
size_t estimate_;
|
||
|
int counter_; // Number of entries emitted since restart
|
||
|
bool finished_; // Has Finish() been called?
|
||
|
std::string last_key_;
|
||
6 years ago
|
DataBlockHashIndexBuilder data_block_hash_index_builder_;
|
||
14 years ago
|
};
|
||
|
|
||
11 years ago
|
} // namespace rocksdb
|