小组成员:谢瑞阳、徐翔宇
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

69 рядки
2.3 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_INCLUDE_TABLE_H_
  5. #define STORAGE_LEVELDB_INCLUDE_TABLE_H_
  6. #include <stdint.h>
  7. #include "leveldb/iterator.h"
  8. namespace leveldb {
  9. class Block;
  10. class BlockHandle;
  11. struct Options;
  12. class RandomAccessFile;
  13. struct ReadOptions;
  14. // A Table is a sorted map from strings to strings. Tables are
  15. // immutable and persistent.
  16. class Table {
  17. public:
  18. // Attempt to open the table that is stored in bytes [0..file_size)
  19. // of "file", and read the metadata entries necessary to allow
  20. // retrieving data from the table.
  21. //
  22. // If successful, returns ok and sets "*table" to the newly opened
  23. // table. The client should delete "*table" when no longer needed.
  24. // If there was an error while initializing the table, sets "*table"
  25. // to NULL and returns a non-ok status. Does not take ownership of
  26. // "*source", but the client must ensure that "source" remains live
  27. // for the duration of the returned table's lifetime.
  28. //
  29. // *file must remain live while this Table is in use.
  30. static Status Open(const Options& options,
  31. RandomAccessFile* file,
  32. uint64_t file_size,
  33. Table** table);
  34. ~Table();
  35. // Returns a new iterator over the table contents.
  36. // The result of NewIterator() is initially invalid (caller must
  37. // call one of the Seek methods on the iterator before using it).
  38. Iterator* NewIterator(const ReadOptions&) const;
  39. // Given a key, return an approximate byte offset in the file where
  40. // the data for that key begins (or would begin if the key were
  41. // present in the file). The returned value is in terms of file
  42. // bytes, and so includes effects like compression of the underlying data.
  43. // E.g., the approximate offset of the last key in the table will
  44. // be close to the file length.
  45. uint64_t ApproximateOffsetOf(const Slice& key) const;
  46. private:
  47. struct Rep;
  48. Rep* rep_;
  49. explicit Table(Rep* rep) { rep_ = rep; }
  50. static Iterator* BlockReader(void*, const ReadOptions&, const Slice&);
  51. // No copying allowed
  52. Table(const Table&);
  53. void operator=(const Table&);
  54. };
  55. }
  56. #endif // STORAGE_LEVELDB_INCLUDE_TABLE_H_