• 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_LIB_IO_BLOCK_BUILDER_H_
17 #define TENSORFLOW_LIB_IO_BLOCK_BUILDER_H_
18 
19 #include <vector>
20 
21 #include <stdint.h>
22 #include "tensorflow/core/lib/core/stringpiece.h"
23 #include "tensorflow/core/platform/types.h"
24 
25 namespace tensorflow {
26 namespace table {
27 
28 struct Options;
29 
30 class BlockBuilder {
31  public:
32   explicit BlockBuilder(const Options* options);
33 
34   // Reset the contents as if the BlockBuilder was just constructed.
35   void Reset();
36 
37   // REQUIRES: Finish() has not been called since the last call to Reset().
38   // REQUIRES: key is larger than any previously added key
39   void Add(const StringPiece& key, const StringPiece& value);
40 
41   // Finish building the block and return a slice that refers to the
42   // block contents.  The returned slice will remain valid for the
43   // lifetime of this builder or until Reset() is called.
44   StringPiece Finish();
45 
46   // Returns an estimate of the current (uncompressed) size of the block
47   // we are building.
48   size_t CurrentSizeEstimate() const;
49 
50   // Return true iff no entries have been added since the last Reset()
empty()51   bool empty() const { return buffer_.empty(); }
52 
53  private:
54   const Options* options_;
55   string buffer_;                 // Destination buffer
56   std::vector<uint32> restarts_;  // Restart points
57   int counter_;                   // Number of entries emitted since restart
58   bool finished_;                 // Has Finish() been called?
59   string last_key_;
60 
61   // No copying allowed
62   BlockBuilder(const BlockBuilder&);
63   void operator=(const BlockBuilder&);
64 };
65 
66 }  // namespace table
67 }  // namespace tensorflow
68 
69 #endif  // TENSORFLOW_LIB_IO_BLOCK_BUILDER_H_
70