ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
Persistence.h

The persistence of the static structures of ADS, beyond the book. More...

Files

file  ADS/external/Persistence.h
 The persistence of the static structures of ADS, beyond the book: a structure built once (a succinct index, a filter, a minimal perfect hash function, a graph in CSR form) is written to a file, a stream or a buffer by store(), and read back by restore(), or opened in place by restoreMapped(), which maps the file [see MappedFile.h] and makes the large arrays of the structure views over its bytes, with no copy and no parsing, so that an index of any size is opened in \( O( 1 ) \) time and its pages are read from the disk at their first access.

Concepts

concept  ADS::Persistent
 a structure that store() writes and restore() reads: it names itself, lists its members in persist(), and is made empty by its default constructor or, if it has none, by its persistEmpty()

Classes

class  ADS::PersistWriter
 the archive that writes the members of a structure [see store()] More...
class  ADS::PersistReader
 the archive that reads the members of a structure [see restore()] More...

Enumerations

enum class  ADS::ByteOrder : std::uint8_t { ADS::ByteOrder::little = 1 , ADS::ByteOrder::big = 2 , ADS::ByteOrder::native = std::endian::native == std::endian::big ? 2 : 1 }
 the byte order of the payload of a file More...

Functions

template<Persistent T>
void ADS::store (const T &x, std::ostream &s, ByteOrder o=ByteOrder::native)
 the structure \( x \) written to the stream \( s \), its payload in the order \( o \)
template<Persistent T>
void ADS::store (const T &x, const std::filesystem::path &p, ByteOrder o=ByteOrder::native)
 the structure \( x \) written to the file \( p \), made or replaced, its payload in the order \( o \)
template<Persistent T>
std::vector< std::byte > ADS::store (const T &x, ByteOrder o=ByteOrder::native)
 the bytes of the structure \( x \), as in a file, its payload in the order \( o \)
template<Persistent T>
T ADS::restore (std::istream &s)
 the structure read from the stream \( s \), its checksum checked
template<Persistent T>
T ADS::restore (std::span< const std::byte > b)
 the structure read from the bytes \( b \), its checksum checked
template<Persistent T>
T ADS::restore (const std::filesystem::path &p)
 the structure read from the file \( p \), its checksum checked
template<Persistent T>
T ADS::restoreMapped (const std::filesystem::path &p, bool verify=false)
 the structure of the file \( p \) mapped in memory, its arrays views over the mapping (copies if the file is of the other byte order, or the array is not on the allocator of the views), its checksum checked if \( \mathit{verify} \); the mapping lives as long as a view of it

Detailed description

The persistence of the static structures of ADS, beyond the book.

The definitions, the invariants and the costs of the area are in Theory of external memory.

Enumeration type documentation

◆ ByteOrder

enum class ADS::ByteOrder : std::uint8_t
strong

the byte order of the payload of a file

Enumerator
little 

the least significant byte first

big 

the most significant byte first

native 

the order of the machine

Function documentation

◆ restore() [1/3]

template<Persistent T>
T ADS::restore ( const std::filesystem::path & p)
nodiscard

the structure read from the file \( p \), its checksum checked

Exceptions
PersistErrorif the file does not hold a valid \( T \)

◆ restore() [2/3]

template<Persistent T>
T ADS::restore ( std::istream & s)
nodiscard

the structure read from the stream \( s \), its checksum checked

Exceptions
PersistErrorif the stream does not hold a valid \( T \)

◆ restore() [3/3]

template<Persistent T>
T ADS::restore ( std::span< const std::byte > b)
nodiscard

the structure read from the bytes \( b \), its checksum checked

Exceptions
PersistErrorif the bytes are not a valid \( T \)

◆ restoreMapped()

template<Persistent T>
T ADS::restoreMapped ( const std::filesystem::path & p,
bool verify = false )
nodiscard

the structure of the file \( p \) mapped in memory, its arrays views over the mapping (copies if the file is of the other byte order, or the array is not on the allocator of the views), its checksum checked if \( \mathit{verify} \); the mapping lives as long as a view of it

Exceptions
PersistErrorif the file does not hold a valid \( T \)

◆ store() [1/3]

template<Persistent T>
std::vector< std::byte > ADS::store ( const T & x,
ByteOrder o = ByteOrder::native )
nodiscard

the bytes of the structure \( x \), as in a file, its payload in the order \( o \)

◆ store() [2/3]

template<Persistent T>
void ADS::store ( const T & x,
const std::filesystem::path & p,
ByteOrder o = ByteOrder::native )

the structure \( x \) written to the file \( p \), made or replaced, its payload in the order \( o \)

Exceptions
PersistErrorif the file cannot be written

◆ store() [3/3]

template<Persistent T>
void ADS::store ( const T & x,
std::ostream & s,
ByteOrder o = ByteOrder::native )

the structure \( x \) written to the stream \( s \), its payload in the order \( o \)

Exceptions
PersistErrorif the stream fails