Vita
cache.h
Go to the documentation of this file.
1
13#if !defined(VITA_CACHE_H)
14#define VITA_CACHE_H
15
16#include <shared_mutex>
17
18#include "kernel/cache_hash.h"
19#include "kernel/environment.h"
20
21namespace vita
22{
31class cache
32{
33public:
34 DISALLOW_COPY_AND_ASSIGN(cache);
35
36 explicit cache(unsigned);
37
38 void clear();
39 void clear(const hash_t &);
40
41 void insert(const hash_t &, const fitness_t &);
42
43 const fitness_t &find(const hash_t &) const;
44
45 bool is_valid() const;
46
47 // Serialization.
48 bool load(std::istream &);
49 bool save(std::ostream &) const;
50
51private:
52 // Private support methods.
53 std::size_t index(const hash_t &) const;
54
55 // Private data members.
56 struct slot
57 {
61 fitness_t fitness;
63 unsigned seal;
64 };
65
66 mutable std::shared_mutex mutex_;
67
68 const std::uint64_t k_mask;
69 std::vector<slot> table_;
70 decltype(slot::seal) seal_;
71};
72
75} // namespace vita
76
77#endif // include guard
Implements a hash table that links individuals' signature to fitness (mainly used by the evaluator_pr...
Definition: cache.h:32
cache(unsigned)
Creates a new hash table.
Definition: cache.cc:24
void clear()
Clears the content and the statistical informations of the table.
Definition: cache.cc:45
const fitness_t & find(const hash_t &) const
Looks for the fitness of an individual in the transposition table.
Definition: cache.cc:81
bool is_valid() const
Definition: cache.cc:180
void insert(const hash_t &, const fitness_t &)
Stores fitness information in the transposition table.
Definition: cache.cc:102
bool save(std::ostream &) const
Definition: cache.cc:155
bool load(std::istream &)
Definition: cache.cc:121
MurmurHash3 (https://github.com/aappleby/smhasher) by Austin Appleby.
Definition: cache_hash.h:101
The main namespace for the project.
A 128bit unsigned integer used as individual's signature / hash table look-up key.
Definition: cache_hash.h:27