Persistent open-addressing hash table mapping UUIDs to integers.
More...
#include "MMappedUUIDHashTable.h"
|
| struct | table_t |
| | On-disk layout of the hash table stored in the mmap file. More...
|
| |
| struct | value_t |
| | One slot in the hash table: a UUID key and its associated integer value. More...
|
| |
|
| | MMappedUUIDHashTable (const char *filename, bool read_only) |
| | Open (or create) the mmap-backed hash table.
|
| |
| | ~MMappedUUIDHashTable () |
| | Sync and unmap the file.
|
| |
| unsigned long | operator[] (pg_uuid_t u) const |
| | Look up the integer index for UUID u.
|
| |
| std::pair< unsigned long, bool > | add (pg_uuid_t u) |
| | Insert UUID u, assigning it the next available integer.
|
| |
| unsigned long | nbElements () const |
| | Return the number of UUID→integer pairs currently stored.
|
| |
| void | sync () |
| | Flush dirty pages to the backing file with msync().
|
| |
|
| static constexpr unsigned long | NOTHING =static_cast<unsigned long>(-1) |
| | Sentinel returned by operator[]() when the UUID is not present.
|
| |
|
| unsigned long | hash (pg_uuid_t u) const |
| | Compute the starting slot index for UUID u.
|
| |
| unsigned long | find (pg_uuid_t u) const |
| | Find the slot index of u, or NOTHING if absent.
|
| |
| void | mmap (size_t length, bool read_only) |
| | Map length bytes from the backing file (read-write or read-only).
|
| |
| void | grow () |
| | Double the table capacity and rehash all existing entries.
|
| |
| void | set (pg_uuid_t u, unsigned long i) |
| | Store the mapping u → i in the table.
|
| |
|
| int | fd |
| | File descriptor of the backing mmap file.
|
| |
| table_t * | table |
| | Pointer to the memory-mapped table header.
|
| |
|
| static constexpr unsigned | STARTING_LOG_SIZE =16 |
| | Initial log2 capacity (65 536 slots).
|
| |
| static constexpr double | MAXIMUM_LOAD_FACTOR =.5 |
| | Rehash when this fraction of slots is occupied.
|
| |
Persistent open-addressing hash table mapping UUIDs to integers.
Definition at line 37 of file MMappedUUIDHashTable.h.
◆ MMappedUUIDHashTable()
| MMappedUUIDHashTable::MMappedUUIDHashTable |
( |
const char * |
filename, |
|
|
bool |
read_only |
|
) |
| |
Open (or create) the mmap-backed hash table.
- Parameters
-
| filename | Path to the backing file (created if absent). |
| read_only | If true, map the file read-only (no new entries can be inserted). |
Definition at line 33 of file MMappedUUIDHashTable.cpp.
◆ ~MMappedUUIDHashTable()
| MMappedUUIDHashTable::~MMappedUUIDHashTable |
( |
| ) |
|
◆ add()
| std::pair< unsigned long, bool > MMappedUUIDHashTable::add |
( |
pg_uuid_t |
u | ) |
|
Insert UUID u, assigning it the next available integer.
If u is already present the existing value is returned without modification.
- Parameters
-
- Returns
- A pair
{value, inserted} where inserted is true if a new entry was created.
Definition at line 126 of file MMappedUUIDHashTable.cpp.
◆ find()
| unsigned long MMappedUUIDHashTable::find |
( |
pg_uuid_t |
u | ) |
const |
|
private |
Find the slot index of u, or NOTHING if absent.
- Parameters
-
- Returns
- Slot index, or
NOTHING if u is not in the table.
Definition at line 108 of file MMappedUUIDHashTable.cpp.
◆ grow()
| void MMappedUUIDHashTable::grow |
( |
| ) |
|
|
private |
◆ hash()
| unsigned long MMappedUUIDHashTable::hash |
( |
pg_uuid_t |
u | ) |
const |
|
inlineprivate |
Compute the starting slot index for UUID u.
Reinterprets the first 8 bytes of u as a 64-bit integer and takes it modulo the current capacity.
- Parameters
-
- Returns
- Slot index in [0, capacity).
Definition at line 105 of file MMappedUUIDHashTable.h.
◆ mmap()
| void MMappedUUIDHashTable::mmap |
( |
size_t |
length, |
|
|
bool |
read_only |
|
) |
| |
|
private |
Map length bytes from the backing file (read-write or read-only).
- Parameters
-
| length | Number of bytes to map. |
| read_only | If true, map read-only. |
Definition at line 63 of file MMappedUUIDHashTable.cpp.
◆ nbElements()
| unsigned long MMappedUUIDHashTable::nbElements |
( |
| ) |
const |
|
inline |
Return the number of UUID→integer pairs currently stored.
- Returns
- Element count.
Definition at line 169 of file MMappedUUIDHashTable.h.
◆ operator[]()
| unsigned long MMappedUUIDHashTable::operator[] |
( |
pg_uuid_t |
u | ) |
const |
Look up the integer index for UUID u.
- Parameters
-
- Returns
- The associated integer, or
NOTHING if u is absent.
Definition at line 119 of file MMappedUUIDHashTable.cpp.
◆ set()
| void MMappedUUIDHashTable::set |
( |
pg_uuid_t |
u, |
|
|
unsigned long |
i |
|
) |
| |
|
private |
Store the mapping u → i in the table.
- Parameters
-
| u | UUID key to store. |
| i | Integer value to associate with u. |
Definition at line 143 of file MMappedUUIDHashTable.cpp.
◆ sync()
| void MMappedUUIDHashTable::sync |
( |
| ) |
|
◆ fd
| int MMappedUUIDHashTable::fd |
|
private |
◆ MAXIMUM_LOAD_FACTOR
| constexpr double MMappedUUIDHashTable::MAXIMUM_LOAD_FACTOR =.5 |
|
staticconstexprprivate |
◆ NOTHING
| constexpr unsigned long MMappedUUIDHashTable::NOTHING =static_cast<unsigned long>(-1) |
|
staticconstexpr |
◆ STARTING_LOG_SIZE
| constexpr unsigned MMappedUUIDHashTable::STARTING_LOG_SIZE =16 |
|
staticconstexprprivate |
◆ table
| table_t* MMappedUUIDHashTable::table |
|
private |
The documentation for this class was generated from the following files: