小组成员:10215300402-朱维清 & 10222140408 谷杰
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

86 行
2.9 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/export.h"
  8. #include "leveldb/iterator.h"
  9. namespace leveldb {
  10. class Block;
  11. class BlockHandle;
  12. class Footer;
  13. struct Options;
  14. class RandomAccessFile;
  15. struct ReadOptions;
  16. class TableCache;
  17. // A Table is a sorted map from strings to strings. Tables are
  18. // immutable and persistent. A Table may be safely accessed from
  19. // multiple threads without external synchronization.
  20. class LEVELDB_EXPORT Table {
  21. public:
  22. // Attempt to open the table that is stored in bytes [0..file_size)
  23. // of "file", and read the metadata entries necessary to allow
  24. // retrieving data from the table.
  25. //
  26. // If successful, returns ok and sets "*table" to the newly opened
  27. // table. The client should delete "*table" when no longer needed.
  28. // If there was an error while initializing the table, sets "*table"
  29. // to NULL and returns a non-ok status. Does not take ownership of
  30. // "*source", but the client must ensure that "source" remains live
  31. // for the duration of the returned table's lifetime.
  32. //
  33. // *file must remain live while this Table is in use.
  34. static Status Open(const Options& options,
  35. RandomAccessFile* file,
  36. uint64_t file_size,
  37. Table** table);
  38. ~Table();
  39. // Returns a new iterator over the table contents.
  40. // The result of NewIterator() is initially invalid (caller must
  41. // call one of the Seek methods on the iterator before using it).
  42. Iterator* NewIterator(const ReadOptions&) const;
  43. // Given a key, return an approximate byte offset in the file where
  44. // the data for that key begins (or would begin if the key were
  45. // present in the file). The returned value is in terms of file
  46. // bytes, and so includes effects like compression of the underlying data.
  47. // E.g., the approximate offset of the last key in the table will
  48. // be close to the file length.
  49. uint64_t ApproximateOffsetOf(const Slice& key) const;
  50. private:
  51. struct Rep;
  52. Rep* rep_;
  53. explicit Table(Rep* rep) { rep_ = rep; }
  54. static Iterator* BlockReader(void*, const ReadOptions&, const Slice&);
  55. // Calls (*handle_result)(arg, ...) with the entry found after a call
  56. // to Seek(key). May not make such a call if filter policy says
  57. // that key is not present.
  58. friend class TableCache;
  59. Status InternalGet(
  60. const ReadOptions&, const Slice& key,
  61. void* arg,
  62. void (*handle_result)(void* arg, const Slice& k, const Slice& v));
  63. void ReadMeta(const Footer& footer);
  64. void ReadFilter(const Slice& filter_handle_value);
  65. // No copying allowed
  66. Table(const Table&);
  67. void operator=(const Table&);
  68. };
  69. } // namespace leveldb
  70. #endif // STORAGE_LEVELDB_INCLUDE_TABLE_H_