![]() |
Ultra 0.9.4
|
#include <cache.h>
Public Member Functions | |
| cache (bitwidth) | |
| bitwidth | bits () const |
| void | resize (bitwidth) |
| void | clear () noexcept |
| void | clear (const hash_t &) |
| void | insert (const hash_t &, const F &) |
| std::optional< F > | find (const hash_t &) const |
| bool | is_valid () const |
| bool | load (std::istream &) |
| bool | save (std::ostream &) const |
| LOCK_GROUP_SIZE | set to 1 for maximum granularity (one lock per slot) or to the size of the table for a single mutex covering all slots. The default value balances performance and thread safety for most use cases. |
This class implements a hash table that maps individuals' signatures to their fitness. It's primarily used by the evaluator_proxy class to optimise performance.
During evolution, semantically equivalent but syntactically distinct individuals are often generated. By using this cache, the system avoids redundant computations of shared information, resulting in significant speed improvements.
|
explicit |
Creates a new, not empty, hash table.
| [in] | n | 2^n is the number of elements of the table. A value of zero creates a valid disabled cache object. Operations requiring table indexing are still guarded and are expected to be bypassed by callers |
|
nodiscard |
|
noexcept |
Invalidates all cached entries without changing the allocated size.
| void cache::clear | ( | const hash_t & | h | ) |
Clears the cached information for a specific individual.
| [in] | h | individual's signature whose information we have to clear |
|
nodiscard |
Looks for the fitness of an individual in the transposition table.
| [in] | h | individual's signature to look for |
| void cache::insert | ( | const hash_t & | h, |
| const F & | fitness ) |
Stores fitness information in the transposition table.
| [in] | h | a (possibly) new individual's signature to be stored in the table |
| [in] | fitness | the fitness of the individual |
|
nodiscard |
| bool cache::load | ( | std::istream & | in | ) |
| [in] | in | input stream |
| void cache::resize | ( | bitwidth | n | ) |
Resize the cache.
| [in] | n | 2^n is the new number of elements of the table |
| bool cache::save | ( | std::ostream & | out | ) | const |
| [out] | out | output stream |