• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright 2015 The TensorFlow Authors. All Rights Reserved.
2 
3 Licensed under the Apache License, Version 2.0 (the "License");
4 you may not use this file except in compliance with the License.
5 You may obtain a copy of the License at
6 
7     http://www.apache.org/licenses/LICENSE-2.0
8 
9 Unless required by applicable law or agreed to in writing, software
10 distributed under the License is distributed on an "AS IS" BASIS,
11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 See the License for the specific language governing permissions and
13 limitations under the License.
14 ==============================================================================*/
15 
16 #ifndef TENSORFLOW_CORE_LIB_IO_TABLE_H_
17 #define TENSORFLOW_CORE_LIB_IO_TABLE_H_
18 
19 #include <stdint.h>
20 #include "tensorflow/core/lib/io/iterator.h"
21 
22 namespace tensorflow {
23 class RandomAccessFile;
24 
25 namespace table {
26 
27 class Block;
28 class BlockHandle;
29 class Footer;
30 struct Options;
31 
32 // A Table is a sorted map from strings to strings.  Tables are
33 // immutable and persistent.  A Table may be safely accessed from
34 // multiple threads without external synchronization.
35 class Table {
36  public:
37   // Attempt to open the table that is stored in bytes [0..file_size)
38   // of "file", and read the metadata entries necessary to allow
39   // retrieving data from the table.
40   //
41   // If successful, returns ok and sets "*table" to the newly opened
42   // table.  The client should delete "*table" when no longer needed.
43   // If there was an error while initializing the table, sets "*table"
44   // to NULL and returns a non-ok status.  Does not take ownership of
45   // "*file", but the client must ensure that "file" remains live
46   // for the duration of the returned table's lifetime.
47   static Status Open(const Options& options, RandomAccessFile* file,
48                      uint64 file_size, Table** table);
49 
50   ~Table();
51 
52   // Returns a new iterator over the table contents.
53   // The result of NewIterator() is initially invalid (caller must
54   // call one of the Seek methods on the iterator before using it).
55   Iterator* NewIterator() const;
56 
57   // Given a key, return an approximate byte offset in the file where
58   // the data for that key begins (or would begin if the key were
59   // present in the file).  The returned value is in terms of file
60   // bytes, and so includes effects like compression of the underlying data.
61   // E.g., the approximate offset of the last key in the table will
62   // be close to the file length.
63   uint64 ApproximateOffsetOf(const StringPiece& key) const;
64 
65  private:
66   struct Rep;
67   Rep* rep_;
68 
Table(Rep * rep)69   explicit Table(Rep* rep) { rep_ = rep; }
70   static Iterator* BlockReader(void*, const StringPiece&);
71 
72   // Calls (*handle_result)(arg, ...) with the entry found after a call
73   // to Seek(key).  May not make such a call if filter policy says
74   // that key is not present.
75   Status InternalGet(const StringPiece& key, void* arg,
76                      void (*handle_result)(void* arg, const StringPiece& k,
77                                            const StringPiece& v));
78 
79   // No copying allowed
80   Table(const Table&);
81   void operator=(const Table&);
82 };
83 
84 }  // namespace table
85 }  // namespace tensorflow
86 
87 #endif  // TENSORFLOW_CORE_LIB_IO_TABLE_H_
88