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