48# ifndef TRANSPOSITION_TABLE_H
49# define TRANSPOSITION_TABLE_H
95template <
typename Policy,
typename Entry>
98 { policy(
candidate, current) } -> std::convertible_to<bool>;
107template <
typename Table,
typename Key,
typename Entry>
109 { table.probe(key) } -> std::same_as<Entry *>;
110 { table.store(key, entry) } -> std::same_as<TranspositionStoreStatus>;
117template <
typename Entry>
133template <
typename Entry>
134 requires requires(
const Entry &entry) {
135 { entry.depth } -> std::convertible_to<size_t>;
163template <
typename Key,
277 return store_impl(std::move(key), std::move(entry));
281 template <
typename KeyLike>
286 auto *
pair =
table_.search(std::forward<KeyLike>(key));
294 return &
pair->second;
297 template <
typename KeyLike,
typename EntryLike>
300 if (
auto *current =
table_.search(key); current !=
nullptr)
308 current->second = std::forward<EntryLike>(entry);
314 (
void)
table_.insert(std::forward<KeyLike>(key), std::forward<EntryLike>(entry));
Generic linear hash table.
Transposition-table container built on top of Aleph hash maps.
Entry * probe(const Key &key)
Probe one key and return the stored entry if present.
TranspositionStats stats_
bool is_empty() const noexcept
Return true if the table contains no entries.
size_t size() const noexcept
Number of currently stored entries.
const TranspositionStats & stats() const noexcept
Read-only access to accumulated storage statistics.
ReplacePolicy Replace_Policy
TranspositionStoreStatus store(const Key &key, const Entry &entry)
Store a candidate entry for key.
Transposition_Table()=default
Build an empty table with the default replacement policy.
void reset_stats() noexcept
Reset only the accumulated storage statistics.
Entry * probe(Key &&key)
Probe one key using move semantics.
static constexpr bool enabled
Compile-time marker for search adapters.
Entry * probe_impl(KeyLike &&key)
TranspositionStoreStatus store_impl(KeyLike &&key, EntryLike &&entry)
void clear() noexcept
Remove all stored entries.
Transposition_Table(ReplacePolicy replace)
Build a table with a custom replacement policy instance.
TranspositionStoreStatus store(Key &&key, Entry entry)
Store a candidate entry for key using move semantics.
Minimal protocol for memo tables used by search engines.
Minimal protocol for replacement policies.
Main namespace for Aleph-w library functions.
TranspositionBound
Stored bound classification for memoized search entries.
@ Upper_Bound
Value is an upper bound (fail-low style).
@ Exact
Exact value for the stored search configuration.
@ Lower_Bound
Value is a lower bound (fail-high style).
Divide_Conquer_DP_Result< Cost > divide_and_conquer_partition_dp(const size_t groups, const size_t n, Transition_Cost_Fn transition_cost, const Cost inf=dp_optimization_detail::default_inf< Cost >())
Optimize partition DP using divide-and-conquer optimization.
std::pair< First, Second > pair
Alias to std::pair kept for backwards compatibility.
TranspositionStoreStatus
Outcome of one store/update attempt in a transposition table.
@ Inserted
A new key was inserted.
@ Replaced
An existing key was updated according to replacement policy.
@ Rejected
Existing entry was kept and candidate was discarded.
void replace(Itor beg, const Itor &end, const T &old_value, const T &new_value)
Replace elements equal to a value.
Common infrastructure for implicit state-space search.
bool is_empty() const noexcept
Checks if the container is empty.
Open addressing hash map using linear probing.
Replacement policy that prefers entries searched to greater depth.
bool operator()(const Entry &candidate, const Entry ¤t) const noexcept
Decide which entry to keep according to remaining depth.
Minimal replacement policy: always replace the current entry.
bool operator()(const Entry &, const Entry &) const noexcept
Decide whether to overwrite a stored entry.
Statistics collected by memo/transposition storage.
size_t replacements
Number of accepted overwrites of existing entries.
size_t probes
Number of probe attempts.
size_t misses
Number of failed probes.
size_t hits
Number of successful probes.
size_t cutoffs
Number of search cutoffs enabled by cached data.
size_t stores
Number of accepted stores (insertions or replacements).
size_t rejected_updates
Number of refused overwrites.