ModErn Text Analysis
META Enumerates Textual Applications
string_list_writer.h
Go to the documentation of this file.
1 
10 #ifndef META_STRING_LIST_WRITER_H_
11 #define META_STRING_LIST_WRITER_H_
12 
13 #include <fstream>
14 #include <mutex>
15 #include <string>
16 
17 #if !META_HAS_STREAM_MOVE
18 #include <memory>
19 #include "util/shim.h"
20 #endif
21 
22 #include "util/disk_vector.h"
23 
24 namespace meta
25 {
26 namespace index
27 {
28 
35 {
36  public:
44  string_list_writer(const std::string& path, uint64_t size);
45 
50 
55 
61  void insert(uint64_t idx, const std::string& elem);
62 
63  private:
64 #if META_HAS_STREAM_MOVE
65  using ofstream = std::ofstream;
66  std::ofstream& file()
67  {
68  return string_file_;
69  }
70  ofstream make_file(const std::string& path)
71  {
72  return std::ofstream{path};
73  }
74 #else
75  using ofstream = std::unique_ptr<std::ofstream>;
80  std::ofstream& file()
81  {
82  return *string_file_;
83  }
88  ofstream make_file(const std::string& path)
89  {
90  return make_unique<std::ofstream>(path);
91  }
92 #endif
93 
95  std::mutex mutex_;
96 
99 
101  uint64_t write_pos_;
102 
105 };
106 }
107 }
108 
109 #endif
std::mutex mutex_
Writes are internally synchronized.
Definition: string_list_writer.h:95
string_list_writer & operator=(string_list_writer &&)
May be move assigned.
Definition: string_list_writer.cpp:33
ofstream make_file(const std::string &path)
Definition: string_list_writer.h:88
A class for writing large lists of strings to disk with an associated index file for fast random acce...
Definition: string_list_writer.h:34
uint64_t write_pos_
Keeps track of the write position.
Definition: string_list_writer.h:101
The ModErn Text Analysis toolkit is a suite of natural language processing, classification, information retreival, data mining, and other applications of text processing.
Definition: analyzer.h:24
string_list_writer(const std::string &path, uint64_t size)
Constructs the writer, writing the string file to the given path.
Definition: string_list_writer.cpp:17
ofstream string_file_
The file containing the strings.
Definition: string_list_writer.h:98
void insert(uint64_t idx, const std::string &elem)
Sets the string at idx to be elem.
Definition: string_list_writer.cpp:44
std::unique_ptr< std::ofstream > ofstream
workaround for lack of move operators for gcc 4.8
Definition: string_list_writer.h:76
util::disk_vector< uint64_t > index_
Index vector—stores byte positions.
Definition: string_list_writer.h:104
std::ofstream & file()
Definition: string_list_writer.h:80