20#ifndef MMAPPED_VECTOR_H
21#define MMAPPED_VECTOR_H
88MMappedVector(
const char *filename,
bool read_only, uint64_t magic,
114void add(
const T& value);
121 return data->nb_elements;
126 return data->version;
File-backed memory region with two interchangeable backends.
void set(pg_uuid_t u, unsigned long i)
Unused overload kept for interface compatibility.
uint16_t version() const
Return the format version stamped in the file's header.
~MMappedVector()
Sync and unmap the file.
bool unclean_
The previous run left the dirty bit set.
data_t * data
Typed view of region.base().
void flush()
Force the backing file to stable storage (MappedRegion::flush()).
unsigned long nbElements() const
Return the number of elements currently stored.
static constexpr unsigned STARTING_CAPACITY
Initial number of element slots allocated.
bool read_only_
Mapped read-only: the header must not be written.
void add(const T &value)
Append an element to the end of the vector.
static constexpr uint32_t FLAG_DIRTY
Bit of data_t::flags set while the file is open for writing.
MMappedVector(const char *filename, bool read_only, uint64_t magic, uint16_t version=1)
Open (or create) the mmap-backed vector.
void grow()
Double the backing region and refresh data.
MappedRegion region
Backing storage (shared mmap, or heap buffer).
const T & operator[](unsigned long k) const
Read-only element access by index.
void sync()
Flush the backing region to its file (MappedRegion::sync()).
void setVersion(uint16_t v)
Stamp v into the header, declaring the file upgraded.
bool uncleanShutdown() const
Whether this file still had FLAG_DIRTY set when it was opened, i.e.
Core types, constants, and utilities shared across ProvSQL.
On-disk layout stored at the start of the backing file.
unsigned long nb_elements
Number of elements currently stored.
uint32_t flags
Bit 0: opened for writing and not closed since.
T d[]
Flexible array of elements.
uint16_t elem_size
sizeof(T) at write time
uint16_t version
Format version of this file.
uint64_t magic
File-type identifier.
unsigned long capacity
Maximum elements before the next grow.