作者: 韩晨旭 10225101440 李畅 10225102463
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

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