JaffarPlus
High-performance best-first search optimizer for tool-assisted speedruns
Loading...
Searching...
No Matches
inputHistory.hpp
Go to the documentation of this file.
1#pragma once
2
22#include "../inputSet.hpp"
23#include <jaffarCommon/deserializers/base.hpp>
24#include <jaffarCommon/json.hpp>
25#include <jaffarCommon/serializers/base.hpp>
26#include <map>
27#include <memory>
28#include <string>
29
30namespace jaffarPlus
31{
32
40{
41public:
43 virtual ~InputHistory() = default;
44
45 // ---- per-runner cursor ---------------------------------------------------------------------------
46 //
47 // NOTE: the step counter is NOT owned here. The Runner owns the count (it is what implements Hash Step
48 // Tolerance) and is the sole party that serializes/deserializes it, prepending it to the cold/full blob.
49 // Strategies that need the current step (raw's write position, the trie's reconstruction length) receive
50 // it as a parameter; they never store or serialize it themselves.
51
53 virtual void reset() = 0;
54
56 virtual void pushInput(const size_t stepCount, const InputSet::inputIndex_t input) = 0;
57
59 virtual void serializeCold(jaffarCommon::serializer::Base& s) const = 0;
61 virtual void deserializeCold(jaffarCommon::deserializer::Base& d) = 0;
62
64 virtual void serializeFull(jaffarCommon::serializer::Base& s) const = 0;
67 virtual void deserializeFull(jaffarCommon::deserializer::Base& d, const size_t stepCount) = 0;
68
71 virtual std::string toString(const std::map<InputSet::inputIndex_t, std::string>& inputStringMap, const size_t stepCount) const = 0;
72
73 // ---- manager ops on stored bytes (use the shared backing only) -----------------------------------
74
76 virtual size_t getColdSize() const = 0;
78 virtual size_t getFullSize() const = 0;
79
81 virtual void initColdSlot(void* cold) const { (void)cold; }
84 virtual void releaseColdSlot(void* cold, const size_t shard) const
85 {
86 (void)cold;
87 (void)shard;
88 }
91 virtual void captureColdToFull(const void* cold, void* full) const = 0;
92
94 virtual size_t getApproxMemoryBytes() const { return 0; }
95};
96
97} // namespace jaffarPlus
Abstract strategy for remembering the input path that produced each search state.
virtual void serializeFull(jaffarCommon::serializer::Base &s) const =0
Writes the self-contained "full" path representation (for standalone snapshot buffers),...
virtual void releaseColdSlot(void *cold, const size_t shard) const
Releases any shared resource a freed cold slot was holding (trie GC).
virtual size_t getColdSize() const =0
Size, in bytes, of the cold path representation in a StateDb slot (EXCLUDING the runner's count).
virtual void reset()=0
Resets the cursor to the empty path.
virtual size_t getFullSize() const =0
Size, in bytes, of the full (self-contained) path representation in a snapshot buffer (EXCLUDING the ...
virtual void deserializeFull(jaffarCommon::deserializer::Base &d, const size_t stepCount)=0
Restores the cursor from a "full" representation.
virtual ~InputHistory()=default
Virtual destructor for the strategy interface.
virtual void serializeCold(jaffarCommon::serializer::Base &s) const =0
Writes the compact "cold" path representation (stored in each StateDb slot), excluding the count.
virtual std::string toString(const std::map< InputSet::inputIndex_t, std::string > &inputStringMap, const size_t stepCount) const =0
Reconstructs the path as a newline-separated string of input strings (the solution).
virtual size_t getApproxMemoryBytes() const
Approximate resident memory of any shared structure (e.g. the trie), in bytes. Default: 0.
virtual void initColdSlot(void *cold) const
Prepares a fresh/recycled cold slot (e.g. marks it as holding no trie node). Default: no-op.
virtual void deserializeCold(jaffarCommon::deserializer::Base &d)=0
Restores the cursor from a "cold" representation (the count is restored by the runner).
virtual void captureColdToFull(const void *cold, void *full) const =0
Converts a stored cold path into a self-contained full one (best/worst snapshot).
virtual void pushInput(const size_t stepCount, const InputSet::inputIndex_t input)=0
Records one applied input at path position stepCount (the runner's current step counter).
size_t inputIndex_t
Type used to index an input.
Definition inputSet.hpp:29