作者: 谢瑞阳 10225101483 徐翔宇 10225101535
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

73 строки
2.1 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_DB_WRITE_BATCH_INTERNAL_H_
  5. #define STORAGE_LEVELDB_DB_WRITE_BATCH_INTERNAL_H_
  6. #include "include/write_batch.h"
  7. namespace leveldb {
  8. // WriteBatchInternal provides static methods for manipulating a
  9. // WriteBatch that we don't want in the public WriteBatch interface.
  10. class WriteBatchInternal {
  11. public:
  12. static void PutLargeValueRef(WriteBatch* batch,
  13. const Slice& key,
  14. const LargeValueRef& large_ref);
  15. // Return the number of entries in the batch.
  16. static int Count(const WriteBatch* batch);
  17. // Set the count for the number of entries in the batch.
  18. static void SetCount(WriteBatch* batch, int n);
  19. // Return the seqeunce number for the start of this batch.
  20. static SequenceNumber Sequence(const WriteBatch* batch);
  21. // Store the specified number as the seqeunce number for the start of
  22. // this batch.
  23. static void SetSequence(WriteBatch* batch, SequenceNumber seq);
  24. static Slice Contents(const WriteBatch* batch) {
  25. return Slice(batch->rep_);
  26. }
  27. static size_t ByteSize(const WriteBatch* batch) {
  28. return batch->rep_.size();
  29. }
  30. static void SetContents(WriteBatch* batch, const Slice& contents);
  31. static Status InsertInto(const WriteBatch* batch, MemTable* memtable);
  32. // Iterate over the contents of a write batch.
  33. class Iterator {
  34. public:
  35. explicit Iterator(const WriteBatch& batch);
  36. bool Done() const { return done_; }
  37. void Next();
  38. ValueType op() const { return op_; }
  39. const Slice& key() const { return key_; }
  40. const Slice& value() const { return value_; }
  41. SequenceNumber sequence_number() const { return seq_; }
  42. Status status() const { return status_; }
  43. private:
  44. void GetNextEntry();
  45. Slice input_;
  46. bool done_;
  47. ValueType op_;
  48. Slice key_;
  49. Slice value_;
  50. SequenceNumber seq_;
  51. Status status_;
  52. };
  53. };
  54. }
  55. #endif // STORAGE_LEVELDB_DB_WRITE_BATCH_INTERNAL_H_