JaffarPlus
High-performance best-first search optimizer for tool-assisted speedruns
Loading...
Searching...
No Matches
jaffarPlus::InputHistoryTrie Class Referencefinal

Stores each state's path as one node id into a shared, reference-counted prefix trie; sibling states share their common prefix, so per-state cold storage is just a node id + count. More...

#include <inputHistoryTrie.hpp>

Inheritance diagram for jaffarPlus::InputHistoryTrie:
[legend]

Public Types

using nodeId_t = SequenceInputTrie::nodeId_t
 Trie node identifier type.
 

Public Member Functions

 InputHistoryTrie (SequenceInputTrie *trie, const uint32_t shardId, const uint32_t managerShard, const uint32_t maxInputIndex, const uint32_t maxSize)
 Binds this instance to the shared trie and sizes the bit-packed snapshot (full) form.
 
void reset () override
 Resets the cursor to the empty path.
 
void pushInput (const size_t, const InputSet::inputIndex_t input) override
 Records one applied input at path position stepCount (the runner's current step counter).
 
void serializeCold (jaffarCommon::serializer::Base &s) const override
 Writes the compact "cold" path representation (stored in each StateDb slot), excluding the count.
 
void deserializeCold (jaffarCommon::deserializer::Base &d) override
 Restores the cursor from a "cold" representation (the count is restored by the runner).
 
void serializeFull (jaffarCommon::serializer::Base &s) const override
 Writes the self-contained "full" path representation (for standalone snapshot buffers), excluding the count.
 
void deserializeFull (jaffarCommon::deserializer::Base &d, const size_t stepCount) override
 Restores the cursor from a "full" representation.
 
std::string toString (const std::map< InputSet::inputIndex_t, std::string > &inputStringMap, const size_t) const override
 Reconstructs the path as a newline-separated string of input strings (the solution).
 
size_t getColdSize () const override
 Size, in bytes, of the cold path representation in a StateDb slot (EXCLUDING the runner's count).
 
size_t getFullSize () const override
 Size, in bytes, of the full (self-contained) path representation in a snapshot buffer (EXCLUDING the count).
 
void initColdSlot (void *cold) const override
 Prepares a fresh/recycled cold slot (e.g. marks it as holding no trie node). Default: no-op.
 
size_t getApproxMemoryBytes () const override
 Approximate resident memory of any shared structure (e.g. the trie), in bytes. Default: 0.
 
void releaseColdSlot (void *cold, const size_t shard) const override
 Releases any shared resource a freed cold slot was holding (trie GC).
 
void captureColdToFull (const void *cold, void *full) const override
 Converts a stored cold path into a self-contained full one (best/worst snapshot).
 

Private Member Functions

void reconstructIntoBuffer (nodeId_t node, uint8_t *buffer, bool pin=false) const
 Reconstructs node's path into a bit-packed buffer.
 
void rebuildNodeFromBuffer (const uint8_t *buffer, const size_t stepCount)
 Rebuilds the cursor's owned trie node by re-extending the stepCount path elements stored in a bit-packed buffer (so a restored runner, e.g.
 

Private Attributes

SequenceInputTrie *const _trie
 The shared trie backing this instance.
 
const uint32_t _shardId
 This runner's free-list shard.
 
const uint32_t _managerShard
 Shard for off-thread manager ops.
 
const uint32_t _maxSize
 Max steps in the snapshot (full) form.
 
size_t _bits = 0
 Bits per input index in the snapshot.
 
size_t _bitpackBytes = 0
 Size of the bit-packed snapshot buffer.
 
nodeId_t _node = SequenceInputTrie::ROOT
 Cursor's current trie node.
 
bool _ownNode = false
 Whether this cursor holds a reference to _node.
 
std::vector< uint8_t > _scratch
 Bit-pack scratch for the full (snapshot) form.
 

Detailed Description

Stores each state's path as one node id into a shared, reference-counted prefix trie; sibling states share their common prefix, so per-state cold storage is just a node id + count.

{"Type":"Trie"}.

Definition at line 43 of file inputHistoryTrie.hpp.

Member Typedef Documentation

◆ nodeId_t

using jaffarPlus::InputHistoryTrie::nodeId_t = SequenceInputTrie::nodeId_t

Trie node identifier type.

Definition at line 46 of file inputHistoryTrie.hpp.

Constructor & Destructor Documentation

◆ InputHistoryTrie()

jaffarPlus::InputHistoryTrie::InputHistoryTrie ( SequenceInputTrie trie,
const uint32_t  shardId,
const uint32_t  managerShard,
const uint32_t  maxInputIndex,
const uint32_t  maxSize 
)
inline

Binds this instance to the shared trie and sizes the bit-packed snapshot (full) form.

Parameters
trieThe shared trie (created once per search; outlives all instances).
shardIdThis runner's contention-free free-list shard (its worker thread id).
managerShardA shard reserved for StateDb/driver-thread operations (captureColdToFull).
maxInputIndexOne past the highest input index (sets the snapshot's per-step bit width).
maxSizeMaximum steps held in the reconstructed snapshot (full) form.

Definition at line 54 of file inputHistoryTrie.hpp.

Member Function Documentation

◆ captureColdToFull()

void jaffarPlus::InputHistoryTrie::captureColdToFull ( const void *  cold,
void *  full 
) const
inlineoverridevirtual

Converts a stored cold path into a self-contained full one (best/worst snapshot).

Operates on the path only; the runner's count prefix is copied separately by the StateDb.

Implements jaffarPlus::InputHistory.

Definition at line 139 of file inputHistoryTrie.hpp.

◆ deserializeCold()

void jaffarPlus::InputHistoryTrie::deserializeCold ( jaffarCommon::deserializer::Base &  d)
inlineoverridevirtual

Restores the cursor from a "cold" representation (the count is restored by the runner).

Implements jaffarPlus::InputHistory.

Definition at line 91 of file inputHistoryTrie.hpp.

◆ deserializeFull()

void jaffarPlus::InputHistoryTrie::deserializeFull ( jaffarCommon::deserializer::Base &  d,
const size_t  stepCount 
)
inlineoverridevirtual

Restores the cursor from a "full" representation.

stepCount is the runner's already-restored step counter, needed by strategies (the trie) that rebuild their cursor from the path length.

Implements jaffarPlus::InputHistory.

Definition at line 103 of file inputHistoryTrie.hpp.

◆ getApproxMemoryBytes()

size_t jaffarPlus::InputHistoryTrie::getApproxMemoryBytes ( ) const
inlineoverridevirtual

Approximate resident memory of any shared structure (e.g. the trie), in bytes. Default: 0.

Reimplemented from jaffarPlus::InputHistory.

Definition at line 127 of file inputHistoryTrie.hpp.

◆ getColdSize()

size_t jaffarPlus::InputHistoryTrie::getColdSize ( ) const
inlineoverridevirtual

Size, in bytes, of the cold path representation in a StateDb slot (EXCLUDING the runner's count).

Implements jaffarPlus::InputHistory.

Definition at line 122 of file inputHistoryTrie.hpp.

◆ getFullSize()

size_t jaffarPlus::InputHistoryTrie::getFullSize ( ) const
inlineoverridevirtual

Size, in bytes, of the full (self-contained) path representation in a snapshot buffer (EXCLUDING the count).

Implements jaffarPlus::InputHistory.

Definition at line 123 of file inputHistoryTrie.hpp.

◆ initColdSlot()

void jaffarPlus::InputHistoryTrie::initColdSlot ( void *  cold) const
inlineoverridevirtual

Prepares a fresh/recycled cold slot (e.g. marks it as holding no trie node). Default: no-op.

Reimplemented from jaffarPlus::InputHistory.

Definition at line 125 of file inputHistoryTrie.hpp.

◆ pushInput()

void jaffarPlus::InputHistoryTrie::pushInput ( const size_t  stepCount,
const InputSet::inputIndex_t  input 
)
inlineoverridevirtual

Records one applied input at path position stepCount (the runner's current step counter).

Implements jaffarPlus::InputHistory.

Definition at line 73 of file inputHistoryTrie.hpp.

◆ rebuildNodeFromBuffer()

void jaffarPlus::InputHistoryTrie::rebuildNodeFromBuffer ( const uint8_t *  buffer,
const size_t  stepCount 
)
inlineprivate

Rebuilds the cursor's owned trie node by re-extending the stepCount path elements stored in a bit-packed buffer (so a restored runner, e.g.

the player, can keep extending the path).

Definition at line 166 of file inputHistoryTrie.hpp.

◆ reconstructIntoBuffer()

void jaffarPlus::InputHistoryTrie::reconstructIntoBuffer ( nodeId_t  node,
uint8_t *  buffer,
bool  pin = false 
) const
inlineprivate

Reconstructs node's path into a bit-packed buffer.

When pin, briefly holds a reference so a worker freeing the source slot cannot free the node mid-walk (best/worst snapshots run off the search threads).

Definition at line 153 of file inputHistoryTrie.hpp.

◆ releaseColdSlot()

void jaffarPlus::InputHistoryTrie::releaseColdSlot ( void *  cold,
const size_t  shard 
) const
inlineoverridevirtual

Releases any shared resource a freed cold slot was holding (trie GC).

shard is the freeing thread's id, used to recycle into a contention-free per-thread pool. Default: no-op.

Reimplemented from jaffarPlus::InputHistory.

Definition at line 129 of file inputHistoryTrie.hpp.

◆ reset()

void jaffarPlus::InputHistoryTrie::reset ( )
inlineoverridevirtual

Resets the cursor to the empty path.

Implements jaffarPlus::InputHistory.

Definition at line 66 of file inputHistoryTrie.hpp.

◆ serializeCold()

void jaffarPlus::InputHistoryTrie::serializeCold ( jaffarCommon::serializer::Base &  s) const
inlineoverridevirtual

Writes the compact "cold" path representation (stored in each StateDb slot), excluding the count.

Implements jaffarPlus::InputHistory.

Definition at line 83 of file inputHistoryTrie.hpp.

◆ serializeFull()

void jaffarPlus::InputHistoryTrie::serializeFull ( jaffarCommon::serializer::Base &  s) const
inlineoverridevirtual

Writes the self-contained "full" path representation (for standalone snapshot buffers), excluding the count.

Implements jaffarPlus::InputHistory.

Definition at line 98 of file inputHistoryTrie.hpp.

◆ toString()

std::string jaffarPlus::InputHistoryTrie::toString ( const std::map< InputSet::inputIndex_t, std::string > &  inputStringMap,
const size_t  stepCount 
) const
inlineoverridevirtual

Reconstructs the path as a newline-separated string of input strings (the solution).

stepCount is the runner's step counter, bounding how many recorded steps are rendered.

Implements jaffarPlus::InputHistory.

Definition at line 109 of file inputHistoryTrie.hpp.

Member Data Documentation

◆ _bitpackBytes

size_t jaffarPlus::InputHistoryTrie::_bitpackBytes = 0
private

Size of the bit-packed snapshot buffer.

Definition at line 188 of file inputHistoryTrie.hpp.

◆ _bits

size_t jaffarPlus::InputHistoryTrie::_bits = 0
private

Bits per input index in the snapshot.

Definition at line 187 of file inputHistoryTrie.hpp.

◆ _managerShard

const uint32_t jaffarPlus::InputHistoryTrie::_managerShard
private

Shard for off-thread manager ops.

Definition at line 185 of file inputHistoryTrie.hpp.

◆ _maxSize

const uint32_t jaffarPlus::InputHistoryTrie::_maxSize
private

Max steps in the snapshot (full) form.

Definition at line 186 of file inputHistoryTrie.hpp.

◆ _node

nodeId_t jaffarPlus::InputHistoryTrie::_node = SequenceInputTrie::ROOT
private

Cursor's current trie node.

Definition at line 189 of file inputHistoryTrie.hpp.

◆ _ownNode

bool jaffarPlus::InputHistoryTrie::_ownNode = false
private

Whether this cursor holds a reference to _node.

Definition at line 190 of file inputHistoryTrie.hpp.

◆ _scratch

std::vector<uint8_t> jaffarPlus::InputHistoryTrie::_scratch
mutableprivate

Bit-pack scratch for the full (snapshot) form.

Definition at line 191 of file inputHistoryTrie.hpp.

◆ _shardId

const uint32_t jaffarPlus::InputHistoryTrie::_shardId
private

This runner's free-list shard.

Definition at line 184 of file inputHistoryTrie.hpp.

◆ _trie

SequenceInputTrie* const jaffarPlus::InputHistoryTrie::_trie
private

The shared trie backing this instance.

Definition at line 183 of file inputHistoryTrie.hpp.


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