26#include <jaffarCommon/bitwise.hpp>
27#include <jaffarCommon/exceptions.hpp>
28#include <jaffarCommon/sequenceTrie.hpp>
60 if (maxInputIndex > 0x10000u) JAFFAR_THROW_RUNTIME(
"Trie input-history supports at most 65536 distinct inputs (got %u); use Store Input History Type \"Raw\".", maxInputIndex);
61 _bits = jaffarCommon::bitwise::getEncodingBitsForElementCount(maxInputIndex);
69 _node = SequenceInputTrie::ROOT;
103 void deserializeFull(jaffarCommon::deserializer::Base& d,
const size_t stepCount)
override
109 std::string
toString(
const std::map<InputSet::inputIndex_t, std::string>& inputStringMap,
const size_t )
const override
111 std::vector<InputSet::inputIndex_t> seq;
114 for (
size_t i = 0; i < seq.size() && i <
_maxSize; i++)
116 if (inputStringMap.contains(seq[i]) ==
false) JAFFAR_THROW_RUNTIME(
"Move Index %lu not found in runner\n", (
unsigned long)seq[i]);
117 out += inputStringMap.at(seq[i]) + std::string(
"\n");
131 auto* node =
reinterpret_cast<nodeId_t*
>(cold);
132 if (*node != SequenceInputTrie::NONE)
134 _trie->release(*node, (uint32_t)shard);
135 *node = SequenceInputTrie::NONE;
145 std::memcpy(&node, cold,
sizeof(node));
156 if (node == SequenceInputTrie::NONE)
return;
157 if (pin)
_trie->acquire(node);
158 std::vector<InputSet::inputIndex_t> seq;
159 _trie->reconstruct(node, seq);
169 _node = SequenceInputTrie::ROOT;
172 for (
size_t i = 0; i < steps; i++)
Stores each state's path as one node id into a shared, reference-counted prefix trie; sibling states ...
void serializeFull(jaffarCommon::serializer::Base &s) const override
Writes the self-contained "full" path representation (for standalone snapshot buffers),...
const uint32_t _shardId
This runner's free-list shard.
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 deserializeFull(jaffarCommon::deserializer::Base &d, const size_t stepCount) override
Restores the cursor from a "full" representation.
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 _bits
Bits per input index in the snapshot.
SequenceInputTrie *const _trie
The shared trie backing this instance.
void deserializeCold(jaffarCommon::deserializer::Base &d) override
Restores the cursor from a "cold" representation (the count is restored by the runner).
size_t getApproxMemoryBytes() const override
Approximate resident memory of any shared structure (e.g. the trie), in bytes. Default: 0.
void reconstructIntoBuffer(nodeId_t node, uint8_t *buffer, bool pin=false) const
Reconstructs node's path into a bit-packed buffer.
SequenceInputTrie::nodeId_t nodeId_t
Trie node identifier type.
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 getFullSize() const override
Size, in bytes, of the full (self-contained) path representation in a snapshot buffer (EXCLUDING the ...
const uint32_t _managerShard
Shard for off-thread manager ops.
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-pac...
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).
const uint32_t _maxSize
Max steps in the snapshot (full) form.
size_t _bitpackBytes
Size of the bit-packed snapshot buffer.
bool _ownNode
Whether this cursor holds a reference to _node.
nodeId_t _node
Cursor's current trie node.
std::vector< uint8_t > _scratch
Bit-pack scratch for the full (snapshot) form.
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).
void serializeCold(jaffarCommon::serializer::Base &s) const override
Writes the compact "cold" path representation (stored in each StateDb slot), excluding the count.
size_t getColdSize() const override
Size, in bytes, of the cold path representation in a StateDb slot (EXCLUDING the runner's count).
void reset() override
Resets the cursor to the empty path.
Abstract strategy for remembering the input path that produced each search state.
jaffarCommon::sequenceTrie::SequenceTrie< uint16_t > SequenceInputTrie
The shared trie type backing every InputHistoryTrie instance of one search.
Abstract interface for how a search remembers the sequence of inputs ("path") that produced each stat...