Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

54 řádky
1.7 KiB

před 1 měsícem
  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.
  4. #ifndef STORAGE_LEVELDB_TABLE_BLOCK_BUILDER_H_
  5. #define STORAGE_LEVELDB_TABLE_BLOCK_BUILDER_H_
  6. #include <cstdint>
  7. #include <vector>
  8. #include "leveldb/slice.h"
  9. namespace leveldb {
  10. struct Options;
  11. class BlockBuilder {
  12. public:
  13. explicit BlockBuilder(const Options* options);
  14. BlockBuilder(const BlockBuilder&) = delete;
  15. BlockBuilder& operator=(const BlockBuilder&) = delete;
  16. // Reset the contents as if the BlockBuilder was just constructed.
  17. void Reset();
  18. // REQUIRES: Finish() has not been called since the last call to Reset().
  19. // REQUIRES: key is larger than any previously added key
  20. void Add(const Slice& key, const Slice& value);
  21. // Finish building the block and return a slice that refers to the
  22. // block contents. The returned slice will remain valid for the
  23. // lifetime of this builder or until Reset() is called.
  24. Slice Finish();
  25. // Returns an estimate of the current (uncompressed) size of the block
  26. // we are building.
  27. size_t CurrentSizeEstimate() const;
  28. // Return true iff no entries have been added since the last Reset()
  29. bool empty() const { return buffer_.empty(); }
  30. private:
  31. const Options* options_;
  32. std::string buffer_; // Destination buffer
  33. std::vector<uint32_t> restarts_; // Restart points
  34. int counter_; // Number of entries emitted since restart
  35. bool finished_; // Has Finish() been called?
  36. std::string last_key_;
  37. };
  38. } // namespace leveldb
  39. #endif // STORAGE_LEVELDB_TABLE_BLOCK_BUILDER_H_