![]() |
JaffarPlus
High-performance best-first search optimizer for tool-assisted speedruns
|
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>
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. | |
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.
| using jaffarPlus::InputHistoryTrie::nodeId_t = SequenceInputTrie::nodeId_t |
Trie node identifier type.
Definition at line 46 of file inputHistoryTrie.hpp.
|
inline |
Binds this instance to the shared trie and sizes the bit-packed snapshot (full) form.
| trie | The shared trie (created once per search; outlives all instances). |
| shardId | This runner's contention-free free-list shard (its worker thread id). |
| managerShard | A shard reserved for StateDb/driver-thread operations (captureColdToFull). |
| maxInputIndex | One past the highest input index (sets the snapshot's per-step bit width). |
| maxSize | Maximum steps held in the reconstructed snapshot (full) form. |
Definition at line 54 of file inputHistoryTrie.hpp.
|
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.
|
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.
|
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.
|
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.
|
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.
|
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.
|
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.
|
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.
|
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.
|
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.
|
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.
|
inlineoverridevirtual |
Resets the cursor to the empty path.
Implements jaffarPlus::InputHistory.
Definition at line 66 of file inputHistoryTrie.hpp.
|
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.
|
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.
|
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.
|
private |
Size of the bit-packed snapshot buffer.
Definition at line 188 of file inputHistoryTrie.hpp.
|
private |
Bits per input index in the snapshot.
Definition at line 187 of file inputHistoryTrie.hpp.
|
private |
Shard for off-thread manager ops.
Definition at line 185 of file inputHistoryTrie.hpp.
|
private |
Max steps in the snapshot (full) form.
Definition at line 186 of file inputHistoryTrie.hpp.
|
private |
Cursor's current trie node.
Definition at line 189 of file inputHistoryTrie.hpp.
|
private |
Whether this cursor holds a reference to _node.
Definition at line 190 of file inputHistoryTrie.hpp.
|
mutableprivate |
Bit-pack scratch for the full (snapshot) form.
Definition at line 191 of file inputHistoryTrie.hpp.
|
private |
This runner's free-list shard.
Definition at line 184 of file inputHistoryTrie.hpp.
|
private |
The shared trie backing this instance.
Definition at line 183 of file inputHistoryTrie.hpp.