diff options
| author | thecharlesblake | 2018-01-25 15:20:54 +0000 |
|---|---|---|
| committer | thecharlesblake | 2018-01-25 15:20:54 +0000 |
| commit | 252c7398925b5267963c1a48251cd7ba2d4ec381 (patch) | |
| tree | 48edb3c44e1a7e8e6008dc764ae960273d466427 /src/main/game/global_cache.h | |
| parent | Merge pull request #31 from thecharlesblake/profiling-fix (diff) | |
| download | metasol-252c7398925b5267963c1a48251cd7ba2d4ec381.tar.gz metasol-252c7398925b5267963c1a48251cd7ba2d4ec381.zip | |
Refactor game_state & cache to remove static hack
Diffstat (limited to 'src/main/game/global_cache.h')
| -rw-r--r-- | src/main/game/global_cache.h | 41 |
1 files changed, 27 insertions, 14 deletions
diff --git a/src/main/game/global_cache.h b/src/main/game/global_cache.h index 486006c..0e8fe0c 100644 --- a/src/main/game/global_cache.h +++ b/src/main/game/global_cache.h @@ -8,27 +8,40 @@ #include <vector> #include <unordered_set> -#include <boost/functional/hash.hpp> - #include "sol_rules.h" #include "game_state.h" -struct game_state_pred { - static bool comp_pile(const pile& x, const pile& y); - bool operator() (const game_state& x, const game_state& y) - const; +class predicate { +public: + explicit predicate(const game_state&); + static bool comp_pile(const pile&, const pile&); + bool operator() (const std::vector<pile>&, const std::vector<pile>&) const; +private: + const game_state& init_gs; }; -class global_cache { -public: - bool insert(const game_state&); - bool contains(const game_state&) const; +struct hasher { + explicit hasher(const game_state&); + std::size_t operator() (const std::vector<pile>&) const; + + std::size_t hash_value(const card&) const; + std::size_t hash_value(const pile&) const; + std::size_t combine(std::size_t&, std::size_t) const; + std::size_t combine_commutative(std::size_t&, std::size_t) const; + + const game_state& init_gs; +}; + +struct global_cache { + explicit global_cache(const game_state&); + bool insert(const std::vector<pile>&); + bool contains(const std::vector<pile>&) const; void clear(); -private: + std::unordered_set< - game_state, - boost::hash<game_state>, - game_state_pred + std::vector<pile>, + hasher, + predicate > u_set; }; |
