jaffarCommon
Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | Static Public Attributes | List of all members
jaffarCommon::sequenceTrie::SequenceTrie< Element > Class Template Reference

A concurrent reference-counted prefix trie over sequences of Element. More...

#include <sequenceTrie.hpp>

Public Types

using nodeId_t = uint32_t
 Handle identifying a node (a stored sequence). Stable for the node's lifetime.
 

Public Member Functions

 SequenceTrie (uint32_t numShards=1, uint32_t chunkSizeLog2=20)
 Constructs an empty trie containing only ROOT.
 
 SequenceTrie (const SequenceTrie &)=delete
 
SequenceTrieoperator= (const SequenceTrie &)=delete
 
nodeId_t extend (nodeId_t parent, Element element, uint32_t shard=0)
 Appends element after parent, returning a handle to the new sequence.
 
void acquire (nodeId_t id)
 Adds one reference to id (when a new holder starts referencing it). Thread-safe.
 
void release (nodeId_t id, uint32_t shard=0)
 Drops one reference from id. Thread-safe.
 
template<typename OutElem = Element>
void reconstruct (nodeId_t id, std::vector< OutElem > &out) const
 Reconstructs the full sequence from ROOT to id, in root-first order.
 
size_t getDepth (nodeId_t id) const
 Number of elements from ROOT to id (its depth in the trie).
 
size_t getAllocatedNodeCount () const
 Total node slots ever bump-allocated (high-water of simultaneously-live nodes, since freed nodes are recycled before fresh ids are bumped). A good proxy for the trie's resident memory.
 
size_t getApproxMemoryBytes () const
 Approximate resident memory of the trie's node storage, in bytes.
 
size_t getMaxMemoryBytes () const
 Hard upper bound on the trie's node storage, in bytes: the most it can ever occupy before node allocation throws "exceeded maximum capacity". The live trie is otherwise unbounded (it grows ~ live-states x depth), so callers that must reserve RAM up front (e.g. the engine's memory guard) use this fixed ceiling. = MAX_CHUNKS * nodes-per-chunk * sizeof(Node).
 

Static Public Attributes

static constexpr nodeId_t ROOT = 0
 The empty sequence. Always valid, never recycled; the base of every path.
 
static constexpr nodeId_t NONE = 0xFFFFFFFFu
 Sentinel for "no node" (also the free-list terminator).
 

Detailed Description

template<typename Element>
class jaffarCommon::sequenceTrie::SequenceTrie< Element >

A concurrent reference-counted prefix trie over sequences of Element.

Template Parameters
ElementTrivially-copyable element type stored on each edge (e.g. an input index).

Constructor & Destructor Documentation

◆ SequenceTrie()

template<typename Element >
jaffarCommon::sequenceTrie::SequenceTrie< Element >::SequenceTrie ( uint32_t  numShards = 1,
uint32_t  chunkSizeLog2 = 20 
)
inlineexplicit

Constructs an empty trie containing only ROOT.

Parameters
numShardsNumber of independent free-list shards used to reduce contention (default 1).
chunkSizeLog2Log2 of the number of nodes per storage chunk (default 2^20 nodes/chunk).

Member Function Documentation

◆ acquire()

template<typename Element >
void jaffarCommon::sequenceTrie::SequenceTrie< Element >::acquire ( nodeId_t  id)
inline

Adds one reference to id (when a new holder starts referencing it). Thread-safe.

Parameters
idThe node to add a reference to.

◆ extend()

template<typename Element >
nodeId_t jaffarCommon::sequenceTrie::SequenceTrie< Element >::extend ( nodeId_t  parent,
Element  element,
uint32_t  shard = 0 
)
inline

Appends element after parent, returning a handle to the new sequence.

Parameters
parentA node the caller holds a reference to (e.g. ROOT, or a state's stored node).
elementThe element to append.
shardFree-list shard to allocate the new node from (default 0).
Returns
The new node, carrying one reference owned by the caller (balance with release).

Thread-safe. The new node adds a child link to parent, which keeps parent alive for at least as long as the new node.

◆ getAllocatedNodeCount()

template<typename Element >
size_t jaffarCommon::sequenceTrie::SequenceTrie< Element >::getAllocatedNodeCount ( ) const
inline

Total node slots ever bump-allocated (high-water of simultaneously-live nodes, since freed nodes are recycled before fresh ids are bumped). A good proxy for the trie's resident memory.

Returns
The number of node slots ever bump-allocated.

◆ getApproxMemoryBytes()

template<typename Element >
size_t jaffarCommon::sequenceTrie::SequenceTrie< Element >::getApproxMemoryBytes ( ) const
inline

Approximate resident memory of the trie's node storage, in bytes.

Returns
The approximate node-storage footprint in bytes.

◆ getDepth()

template<typename Element >
size_t jaffarCommon::sequenceTrie::SequenceTrie< Element >::getDepth ( nodeId_t  id) const
inline

Number of elements from ROOT to id (its depth in the trie).

Parameters
idThe node whose depth is measured.
Returns
The number of elements on the path from ROOT to id.

◆ getMaxMemoryBytes()

template<typename Element >
size_t jaffarCommon::sequenceTrie::SequenceTrie< Element >::getMaxMemoryBytes ( ) const
inline

Hard upper bound on the trie's node storage, in bytes: the most it can ever occupy before node allocation throws "exceeded maximum capacity". The live trie is otherwise unbounded (it grows ~ live-states x depth), so callers that must reserve RAM up front (e.g. the engine's memory guard) use this fixed ceiling. = MAX_CHUNKS * nodes-per-chunk * sizeof(Node).

Returns
The hard upper bound on the trie's node-storage footprint, in bytes.

◆ reconstruct()

template<typename Element >
template<typename OutElem = Element>
void jaffarCommon::sequenceTrie::SequenceTrie< Element >::reconstruct ( nodeId_t  id,
std::vector< OutElem > &  out 
) const
inline

Reconstructs the full sequence from ROOT to id, in root-first order.

Parameters
idA node the caller keeps alive for the duration of the call.
outCleared and filled with the sequence (ROOT contributes no element).

◆ release()

template<typename Element >
void jaffarCommon::sequenceTrie::SequenceTrie< Element >::release ( nodeId_t  id,
uint32_t  shard = 0 
)
inline

Drops one reference from id. Thread-safe.

Parameters
idThe node to drop a reference from.
shardFree-list shard that recycled node slots are returned to (default 0).

When a node's reference count reaches zero (no holders and no children) it is recycled and the drop cascades to its parent (whose child edge just disappeared). ROOT's permanent reference keeps the cascade from ever freeing it.


The documentation for this class was generated from the following file: