maph 1.0.0 High-Performance Memory-Mapped Key-Value Database with O(1) Lookups

Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | Static Public Attributes | List of all members
maph::Slot Struct Reference

Storage slot for key-value pairs. More...

`#include <maph.hpp>`

Collaboration diagram for maph::Slot:

## Public Member Functions
uint32_t | hash () const
| Get the hash value of the key stored in this slot.
uint32_t | version () const
| Get the version number for optimistic concurrency control.
bool | empty () const
| Check if slot is empty.
JsonView | view () const
| Get a string_view of the stored value.
void | set (uint32_t h, JsonView value)
| Store a value in this slot.
void | clear ()
| Clear this slot (remove the key-value pair)

## Public Attributes
std::atomic< uint64_t > | hash_version {0}
| Combined hash (high 32) and version (low 32)
uint32_t | size {0}
| Size of stored value in bytes.
uint32_t | reserved {0}
| Reserved for future use.
char | data [SLOT_DATA_SIZE] {}
| Value data storage.
std::atomic< uint32_t > | version {0}
uint32_t | hash {0}

## Static Public Attributes
static constexpr size_t | MAX_SIZE = SLOT_DATA_SIZE
| Maximum value size (496 bytes)
static constexpr size_t | MAX_JSON_SIZE = 496

## Detailed Description

Storage slot for key-value pairs.

Each slot is 512 bytes and cache-line aligned (64 bytes) for optimal performance. The slot contains metadata and the actual value data.

Memory Layout:

- 8 bytes: atomic hash_version (32-bit hash + 32-bit version)
- 4 bytes: data size
- 4 bytes: reserved for future use
- 496 bytes: value data

Definition at line 115 of file maph.hpp.

## Member Function Documentation

## ◆ clear()

void maph::Slot::clear | ( |  | ) |
| inline

Clear this slot (remove the key-value pair)

Increments version by 2 and sets hash to 0. Data is not cleared for performance (will be overwritten on next use).

Definition at line 180 of file maph.hpp.

References hash_version, size, and version.

Referenced by maph::Maph::remove().

Here is the caller graph for this function:

## ◆ empty()

bool maph::Slot::empty | ( |  | ) | const
| inline

Check if slot is empty.

Returns
  true if no key is stored (hash == 0)

Definition at line 143 of file maph.hpp.

References hash.

Referenced by maph::Maph::get(), maph::Maph::parallel_scan(), maph::Maph::remove(), maph::Maph::scan(), and maph::Maph::set().

Here is the caller graph for this function:

## ◆ hash()

uint32_t maph::Slot::hash | ( |  | ) | const
| inline

Get the hash value of the key stored in this slot.

Returns
  32-bit hash value, or 0 if slot is empty

Definition at line 127 of file maph.hpp.

References hash_version.

## ◆ set()

void maph::Slot::set | ( | uint32_t | h,
|  | JsonView | value
| ) |  |
| inline

Store a value in this slot.

Uses double-write pattern for atomicity:

1. Write hash with version+1 (marks as updating)
2. Copy value data
3. Write hash with version+2 (marks as complete)

Parameters

  h | Hash of the key
  value | Value to store (must be <= 496 bytes)

Definition at line 166 of file maph.hpp.

References data, hash_version, size, and version.

Referenced by maph::Maph::set().

Here is the caller graph for this function:

## ◆ version()

uint32_t maph::Slot::version | ( |  | ) | const
| inline

Get the version number for optimistic concurrency control.

Returns
  32-bit version number, incremented on each modification

Definition at line 135 of file maph.hpp.

References hash_version.

## ◆ view()

JsonView maph::Slot::view | ( |  | ) | const
| inline

Get a string_view of the stored value.

Returns
  Zero-copy view of the value data

Definition at line 151 of file maph.hpp.

References data, and size.

Referenced by maph::Maph::get(), and maph::Maph::scan().

Here is the caller graph for this function:

## Member Data Documentation

## ◆ data

char maph::Slot::data {}

Value data storage.

Definition at line 119 of file maph.hpp.

Referenced by set(), and view().

## ◆ hash

uint32_t maph::Slot::hash {0}

Definition at line 30 of file maph.hpp.

Referenced by empty(), maph::Maph::get(), maph::Maph::remove(), maph::Maph::scan(), and maph::Maph::set().

## ◆ hash_version

std::atomic<uint64_t> maph::Slot::hash_version {0}

Combined hash (high 32) and version (low 32)

Definition at line 116 of file maph.hpp.

Referenced by clear(), hash(), set(), and version().

## ◆ MAX_JSON_SIZE

constexpr size_t maph::Slot::MAX_JSON_SIZE = 496
| static constexpr

Definition at line 34 of file maph.hpp.

Referenced by maph::Maph::set().

## ◆ MAX_SIZE

constexpr size_t maph::Slot::MAX_SIZE = SLOT_DATA_SIZE
| static constexpr

Maximum value size (496 bytes)

Definition at line 121 of file maph.hpp.

Referenced by maph::Maph::set().

## ◆ reserved

uint32_t maph::Slot::reserved {0}

Reserved for future use.

Definition at line 118 of file maph.hpp.

## ◆ size

uint32_t maph::Slot::size {0}

Size of stored value in bytes.

Definition at line 117 of file maph.hpp.

Referenced by clear(), maph::Maph::exists(), set(), and view().

## ◆ version

std::atomic<uint32_t> maph::Slot::version {0}

Definition at line 28 of file maph.hpp.

Referenced by clear(), and set().

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

- include/maph.hpp
- include/maph/maph.hpp