ProvSQL C/C++ API
Adding support for provenance and uncertainty management to PostgreSQL databases
Loading...
Searching...
No Matches
MMappedVector< T > Class Template Reference

Append-only, mmap-backed vector of elements of type T. More...

#include "MMappedVector.h"

Collaboration diagram for MMappedVector< T >:

Classes

struct  data_t
 On-disk layout stored at the start of the backing file. More...

Public Member Functions

 MMappedVector (const char *filename, bool read_only, uint64_t magic)
 Open (or create) the mmap-backed vector.
 ~MMappedVector ()
 Sync and unmap the file.
const T & operator[] (unsigned long k) const
 Read-only element access by index.
T & operator[] (unsigned long k)
 Read-write element access by index.
void add (const T &value)
 Append an element to the end of the vector.
unsigned long nbElements () const
 Return the number of elements currently stored.
void sync ()
 Flush the backing region to its file (MappedRegion::sync()).

Private Member Functions

void grow ()
 Double the backing region and refresh data.
void set (pg_uuid_t u, unsigned long i)
 Unused overload kept for interface compatibility.

Private Attributes

MappedRegion region
 Backing storage (shared mmap, or heap buffer).
data_tdata
 Typed view of region.base().

Static Private Attributes

static constexpr unsigned STARTING_CAPACITY =(1u << 16)
 Initial number of element slots allocated.

Detailed Description

template<typename T>
class MMappedVector< T >

Append-only, mmap-backed vector of elements of type T.

Template Parameters
TThe element type. Must be trivially copyable.

Definition at line 39 of file MMappedVector.h.

Constructor & Destructor Documentation

◆ MMappedVector()

template<typename T>
MMappedVector< T >::MMappedVector ( const char * filename,
bool read_only,
uint64_t magic )

Open (or create) the mmap-backed vector.

Parameters
filenamePath to the backing file (created with STARTING_CAPACITY slots if absent).
read_onlyIf true, map the file read-only.
magicExpected magic value for format validation.

Definition at line 41 of file MMappedVector.hpp.

◆ ~MMappedVector()

template<typename T>
MMappedVector< T >::~MMappedVector ( )

Sync and unmap the file.

Definition at line 82 of file MMappedVector.hpp.

Member Function Documentation

◆ add()

template<typename T>
void MMappedVector< T >::add ( const T & value)

Append an element to the end of the vector.

Grows the backing file if the current capacity is exhausted.

Parameters
valueElement to append.

Definition at line 100 of file MMappedVector.hpp.

Here is the call graph for this function:

◆ grow()

template<typename T>
void MMappedVector< T >::grow ( )
private

Double the backing region and refresh data.

Definition at line 73 of file MMappedVector.hpp.

Here is the caller graph for this function:

◆ nbElements()

template<typename T>
unsigned long MMappedVector< T >::nbElements ( ) const
inline

Return the number of elements currently stored.

Returns
Element count.

Definition at line 110 of file MMappedVector.h.

◆ operator[]() [1/2]

template<typename T>
T & MMappedVector< T >::operator[] ( unsigned long k)
inline

Read-write element access by index.

Parameters
kZero-based element index.
Returns
Reference to element k.

Definition at line 94 of file MMappedVector.hpp.

◆ operator[]() [2/2]

template<typename T>
const T & MMappedVector< T >::operator[] ( unsigned long k) const
inline

Read-only element access by index.

Parameters
kZero-based element index.
Returns
Const reference to element k.

Definition at line 88 of file MMappedVector.hpp.

◆ set()

template<typename T>
void MMappedVector< T >::set ( pg_uuid_t u,
unsigned long i )
private

Unused overload kept for interface compatibility.

Parameters
uIgnored UUID parameter.
iIgnored integer parameter.

◆ sync()

template<typename T>
void MMappedVector< T >::sync ( )

Flush the backing region to its file (MappedRegion::sync()).

Definition at line 109 of file MMappedVector.hpp.

Member Data Documentation

◆ data

template<typename T>
data_t* MMappedVector< T >::data
private

Typed view of region.base().

Definition at line 56 of file MMappedVector.h.

◆ region

template<typename T>
MappedRegion MMappedVector< T >::region
private

Backing storage (shared mmap, or heap buffer).

Definition at line 55 of file MMappedVector.h.

◆ STARTING_CAPACITY

template<typename T>
unsigned MMappedVector< T >::STARTING_CAPACITY =(1u << 16)
staticconstexprprivate

Initial number of element slots allocated.

Definition at line 59 of file MMappedVector.h.


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