ModErn Text Analysis
META Enumerates Textual Applications
postings_file_writer.h
Go to the documentation of this file.
1 
10 #ifndef META_INDEX_POSTINGS_FILE_WRITER_H_
11 #define META_INDEX_POSTINGS_FILE_WRITER_H_
12 
13 #include <fstream>
14 #include <numeric>
15 
16 #include "meta/config.h"
17 #include "meta/io/packed.h"
18 #include "meta/util/disk_vector.h"
19 
20 namespace meta
21 {
22 namespace index
23 {
24 
25 template <class PostingsData>
27 {
28  public:
33  postings_file_writer(const std::string& filename, uint64_t unique_keys)
34  : output_{filename, std::ios::binary},
35  byte_locations_{filename + "_index", unique_keys},
36  byte_pos_{0},
37  id_{0}
38  {
39  // nothing
40  }
41 
47  void write(const PostingsData& pdata)
48  {
49  byte_locations_[id_] = byte_pos_;
50  byte_pos_ += pdata.write_packed_counts(output_);
51  ++id_;
52  }
53 
54  private:
55  std::ofstream output_;
56  util::disk_vector<uint64_t> byte_locations_;
57  uint64_t byte_pos_;
58  uint64_t id_;
59 };
60 }
61 }
62 #endif
void write(const PostingsData &pdata)
Writes a postings data object to the file.
Definition: postings_file_writer.h:47
Definition: postings_file_writer.h:26
The ModErn Text Analysis toolkit is a suite of natural language processing, classification, information retrieval, data mining, and other applications of text processing.
Definition: analyzer.h:25
postings_file_writer(const std::string &filename, uint64_t unique_keys)
Opens a postings file for writing.
Definition: postings_file_writer.h:33