作者: 谢瑞阳 10225101483 徐翔宇 10225101535
Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

69 linhas
2.0 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_MEMTABLE_H_
  5. #define STORAGE_LEVELDB_DB_MEMTABLE_H_
  6. #include <string>
  7. #include "include/db.h"
  8. #include "db/dbformat.h"
  9. #include "db/skiplist.h"
  10. #include "util/arena.h"
  11. namespace leveldb {
  12. class InternalKeyComparator;
  13. class Mutex;
  14. class MemTableIterator;
  15. class MemTable {
  16. public:
  17. explicit MemTable(const InternalKeyComparator& comparator);
  18. ~MemTable();
  19. // Returns an estimate of the number of bytes of data in use by this
  20. // data structure.
  21. //
  22. // REQUIRES: external synchronization to prevent simultaneous
  23. // operations on the same MemTable.
  24. size_t ApproximateMemoryUsage();
  25. // Return an iterator that yields the contents of the memtable.
  26. //
  27. // The caller must ensure that the underlying MemTable remains live
  28. // while the returned iterator is live. The keys returned by this
  29. // iterator are internal keys encoded by AppendInternalKey in the
  30. // db/format.{h,cc} module.
  31. Iterator* NewIterator();
  32. // Add an entry into memtable that maps key to value at the
  33. // specified sequence number and with the specified type.
  34. // Typically value will be empty if type==kTypeDeletion.
  35. void Add(SequenceNumber seq, ValueType type,
  36. const Slice& key,
  37. const Slice& value);
  38. private:
  39. struct KeyComparator {
  40. const InternalKeyComparator comparator;
  41. explicit KeyComparator(const InternalKeyComparator& c) : comparator(c) { }
  42. int operator()(const char* a, const char* b) const;
  43. };
  44. friend class MemTableIterator;
  45. friend class MemTableBackwardIterator;
  46. typedef SkipList<const char*, KeyComparator> Table;
  47. KeyComparator comparator_;
  48. Arena arena_;
  49. Table table_;
  50. // No copying allowed
  51. MemTable(const MemTable&);
  52. void operator=(const MemTable&);
  53. };
  54. }
  55. #endif // STORAGE_LEVELDB_DB_MEMTABLE_H_