Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

57 строки
1.7 KiB

  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 <vector>
  7. #include <stdint.h>
  8. #include "leveldb/slice.h"
  9. namespace leveldb {
  10. struct Options;
  11. class BlockBuilder {
  12. public:
  13. explicit BlockBuilder(const Options* options);
  14. // Reset the contents as if the BlockBuilder was just constructed.
  15. void Reset();
  16. // REQUIRES: Finish() has not been callled since the last call to Reset().
  17. // REQUIRES: key is larger than any previously added key
  18. void Add(const Slice& key, const Slice& value);
  19. // Finish building the block and return a slice that refers to the
  20. // block contents. The returned slice will remain valid for the
  21. // lifetime of this builder or until Reset() is called.
  22. Slice Finish();
  23. // Returns an estimate of the current (uncompressed) size of the block
  24. // we are building.
  25. size_t CurrentSizeEstimate() const;
  26. // Return true iff no entries have been added since the last Reset()
  27. bool empty() const {
  28. return buffer_.empty();
  29. }
  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. // No copying allowed
  38. BlockBuilder(const BlockBuilder&);
  39. void operator=(const BlockBuilder&);
  40. };
  41. } // namespace leveldb
  42. #endif // STORAGE_LEVELDB_TABLE_BLOCK_BUILDER_H_