![]() |
ProvSQL C/C++ API
Adding support for provenance and uncertainty management to PostgreSQL databases
|
Append-only, mmap-backed vector of elements of type T.
More...
#include "MMappedVector.h"

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, uint16_t version=1) | |
| 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. | |
| uint16_t | version () const |
| Return the format version stamped in the file's header. | |
| void | setVersion (uint16_t v) |
Stamp v into the header, declaring the file upgraded. | |
| void | sync () |
Flush the backing region to its file (MappedRegion::sync()). | |
| void | flush () |
Force the backing file to stable storage (MappedRegion::flush()). | |
| bool | uncleanShutdown () const |
Whether this file still had FLAG_DIRTY set when it was opened, i.e. | |
Static Public Attributes | |
| static constexpr uint32_t | FLAG_DIRTY = 1u |
Bit of data_t::flags set while the file is open for writing. | |
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_t * | data |
Typed view of region.base(). | |
| bool | read_only_ = false |
| Mapped read-only: the header must not be written. | |
| bool | unclean_ = false |
| The previous run left the dirty bit set. | |
Static Private Attributes | |
| static constexpr unsigned | STARTING_CAPACITY =(1u << 16) |
| Initial number of element slots allocated. | |
Append-only, mmap-backed vector of elements of type T.
| T | The element type. Must be trivially copyable. |
Definition at line 39 of file MMappedVector.h.
| MMappedVector< T >::MMappedVector | ( | const char * | filename, |
| bool | read_only, | ||
| uint64_t | magic, | ||
| uint16_t | version = 1 ) |
Open (or create) the mmap-backed vector.
A file created here is stamped with version; an existing file is accepted when its stamp is at most version, so a build that understands version n keeps reading the files an older one wrote. The caller reads the stamp back with version() to decide how to interpret fields whose meaning changed.
| filename | Path to the backing file (created with STARTING_CAPACITY slots if absent). |
| read_only | If true, map the file read-only. |
| magic | Expected magic value for format validation. |
| version | Highest format version this build writes and reads. |
Definition at line 41 of file MMappedVector.hpp.

| MMappedVector< T >::~MMappedVector | ( | ) |
Sync and unmap the file.
Definition at line 91 of file MMappedVector.hpp.
| 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.
| value | Element to append. |
Definition at line 111 of file MMappedVector.hpp.

| void MMappedVector< T >::flush | ( | ) |
Force the backing file to stable storage (MappedRegion::flush()).
Definition at line 126 of file MMappedVector.hpp.

|
private |
Double the backing region and refresh data.
Definition at line 82 of file MMappedVector.hpp.
|
inline |
Return the number of elements currently stored.
Definition at line 120 of file MMappedVector.h.

|
inline |
Read-write element access by index.
| k | Zero-based element index. |
k. Definition at line 105 of file MMappedVector.hpp.
|
inline |
Read-only element access by index.
| k | Zero-based element index. |
k. Definition at line 99 of file MMappedVector.hpp.
|
private |
Unused overload kept for interface compatibility.
| u | Ignored UUID parameter. |
| i | Ignored integer parameter. |

|
inline |
Stamp v into the header, declaring the file upgraded.
Only a pass that has rewritten every record to the new version's conventions may call this.
Definition at line 133 of file MMappedVector.h.
| void MMappedVector< T >::sync | ( | ) |
Flush the backing region to its file (MappedRegion::sync()).
Definition at line 120 of file MMappedVector.hpp.
|
inline |
Whether this file still had FLAG_DIRTY set when it was opened, i.e.
whoever wrote it last did not close it.
Definition at line 156 of file MMappedVector.h.
|
inline |
Return the format version stamped in the file's header.
Definition at line 125 of file MMappedVector.h.

|
private |
Typed view of region.base().
Definition at line 56 of file MMappedVector.h.
|
staticconstexpr |
Bit of data_t::flags set while the file is open for writing.
Cleared on a clean close, so a file found with it still set was left behind by a process that died (or by an immediate shutdown). The header layout is unchanged: the bit lives in what used to be reserved padding, which older builds neither read nor write.
Definition at line 152 of file MMappedVector.h.
|
private |
Mapped read-only: the header must not be written.
Definition at line 57 of file MMappedVector.h.
|
private |
Backing storage (shared mmap, or heap buffer).
Definition at line 55 of file MMappedVector.h.
|
staticconstexprprivate |
Initial number of element slots allocated.
Definition at line 61 of file MMappedVector.h.
|
private |
The previous run left the dirty bit set.
Definition at line 58 of file MMappedVector.h.