ModErn Text Analysis
META Enumerates Textual Applications
Classes | 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>

Classes

class  disk_vector_exception
 Basic exception for disk_vector. More...
 
class  iterator
 Provides iterator functionality for the disk_vector class. More...
 

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 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

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

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
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
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.

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.

template<class T >
uint64_t meta::util::disk_vector< T >::size ( ) const
Returns
the number of elements this vector stores
template<class T >
disk_vector< T >::iterator meta::util::disk_vector< T >::begin ( ) const
Returns
an iterator to the beginning of this container
template<class T >
disk_vector< T >::iterator meta::util::disk_vector< T >::end ( ) const
Returns
an iterator to the end of this container

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