ModErn Text Analysis
META Enumerates Textual Applications
disk_vector.h
Go to the documentation of this file.
1 
10 #ifndef META_DISK_VECTOR_H_
11 #define META_DISK_VECTOR_H_
12 
13 #include <fcntl.h>
14 #include <stdio.h>
15 #include <string>
16 #include <type_traits>
17 #ifndef _WIN32
18 #include <sys/mman.h>
19 #else
20 #include "meta/io/mman-win32/mman.h"
21 #endif
22 #include <unistd.h>
23 
24 #include "meta/config.h"
25 #include "meta/meta.h"
26 
27 namespace meta
28 {
29 namespace util
30 {
31 
36 template <class T>
37 class disk_vector
38 {
39  static_assert(std::is_integral<T>::value || std::is_floating_point<T>::value
40  || std::is_base_of<util::numeric, T>::value,
41  "disk_vector templated types must be integral types");
42 
43  public:
51  disk_vector(const std::string& path, uint64_t size = 0);
52 
57 
62 
66  ~disk_vector();
67 
73  T& operator[](uint64_t idx);
74 
80  const T& operator[](uint64_t idx) const;
81 
91  T& at(uint64_t idx);
92 
102  const T& at(uint64_t idx) const;
103 
107  uint64_t size() const;
108 
109  using iterator = T*;
110  using const_iterator = const T*;
111 
115  iterator begin();
116 
121  const_iterator begin() const;
122 
126  iterator end();
127 
131  const_iterator end() const;
132 
133  private:
135  std::string path_;
136 
138  T* start_;
139 
141  uint64_t size_;
142 
145 };
146 
150 class disk_vector_exception : public std::runtime_error
151 {
152  public:
153  using std::runtime_error::runtime_error;
154 };
155 }
156 }
157 
158 #include "meta/util/disk_vector.tcc"
159 #endif
Contains top-level namespace documentation for the META toolkit.
iterator begin()
Definition: disk_vector.tcc:132
disk_vector(const std::string &path, uint64_t size=0)
Definition: disk_vector.tcc:16
int file_desc_
the file descriptor used to open and close the mmap file
Definition: disk_vector.h:144
Basic exception for disk_vector.
Definition: disk_vector.h:150
T & at(uint64_t idx)
Definition: disk_vector.tcc:106
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
iterator end()
Definition: disk_vector.tcc:150
~disk_vector()
Destructor.
Definition: disk_vector.tcc:85
T & operator[](uint64_t idx)
Definition: disk_vector.tcc:94
disk_vector & operator=(disk_vector &&)
Move assignment operator.
Definition: disk_vector.tcc:66
uint64_t size_
this size of the memory-mapped file (in regards to T objects)
Definition: disk_vector.h:141
uint64_t size() const
Definition: disk_vector.tcc:126
std::string path_
the path to the file this disk_vector uses for storage
Definition: disk_vector.h:135
T * start_
the beginning of where the storage file is memory mapped
Definition: disk_vector.h:138