ModErn Text Analysis
META Enumerates Textual Applications
Public Types | Public Member Functions | Private Attributes | List of all members
meta::util::disk_vector< T > Class Template Reference

disk_vector represents a large constant-size vector that does not necessarily fit in memory. More...

#include <disk_vector.h>

Public Types

using iterator = T *
 
using const_iterator = const T *
 

Public Member Functions

 disk_vector (const std::string &path, uint64_t size=0)
 
 disk_vector (disk_vector &&)
 Move constructor.
 
disk_vectoroperator= (disk_vector &&)
 Move assignment operator.
 
 ~disk_vector ()
 Destructor.
 
T & operator[] (uint64_t idx)
 
const T & operator[] (uint64_t idx) const
 
T & at (uint64_t idx)
 
const T & at (uint64_t idx) const
 
uint64_t size () const
 
iterator begin ()
 
const_iterator begin () const
 
iterator end ()
 
const_iterator end () const
 

Private Attributes

std::string path_
 the path to the file this disk_vector uses for storage
 
T * start_
 the beginning of where the storage file is memory mapped
 
uint64_t size_
 this size of the memory-mapped file (in regards to T objects)
 
int file_desc_
 the file descriptor used to open and close the mmap file
 

Detailed Description

template<class T>
class meta::util::disk_vector< T >

disk_vector represents a large constant-size vector that does not necessarily fit in memory.

Constructor & Destructor Documentation

§ disk_vector()

template<class T >
meta::util::disk_vector< T >::disk_vector ( const std::string &  path,
uint64_t  size = 0 
)
Parameters
pathThe path to save this vector as. If the file exists, it is treated as disk_vector. If the file doesn't exist, a new one is created.
sizeThe number of elements that will be in this vector. If not specified, the disk_vector assumes that the file already exists.

Member Function Documentation

§ operator[]() [1/2]

template<class T >
T & meta::util::disk_vector< T >::operator[] ( uint64_t  idx)
Parameters
idxThe index of the vector to retrieve
Returns
a reference to the element at position idx in the vector container

§ operator[]() [2/2]

template<class T >
const T & meta::util::disk_vector< T >::operator[] ( uint64_t  idx) const
Parameters
idxThe index of the vector to retrieve
Returns
a reference to the element at position idx in the vector container

§ at() [1/2]

template<class T >
T & meta::util::disk_vector< T >::at ( uint64_t  idx)
Parameters
idxThe index of the vector to retrieve
Returns
a reference to the element at position idx in the vector

The function automatically checks whether idx is within the bounds of valid elements in the vector, throwing an exception if it is not (i.e., if idx is greater or equal than its size). This is in contrast with member operator[], that does not check against bounds.

§ at() [2/2]

template<class T >
const T & meta::util::disk_vector< T >::at ( uint64_t  idx) const
Parameters
idxThe index of the vector to retrieve
Returns
a reference to the element at position idx in the vector

The function automatically checks whether idx is within the bounds of valid elements in the vector, throwing an exception if it is not (i.e., if idx is greater or equal than its size). This is in contrast with member operator[], that does not check against bounds.

§ size()

template<class T >
uint64_t meta::util::disk_vector< T >::size ( ) const
Returns
the number of elements this vector stores

§ begin() [1/2]

template<class T >
auto meta::util::disk_vector< T >::begin ( )
Returns
an iterator to the beginning of this container

§ begin() [2/2]

template<class T >
auto meta::util::disk_vector< T >::begin ( ) const
Returns
an iterator to the beginning of this container (const version)

§ end() [1/2]

template<class T >
auto meta::util::disk_vector< T >::end ( )
Returns
an iterator to the end of this container

§ end() [2/2]

template<class T >
auto meta::util::disk_vector< T >::end ( ) const
Returns
an iterator to the end of this container (const version)

The documentation for this class was generated from the following files: