aboutsummaryrefslogtreecommitdiff
path: root/src/main/game/global_cache.h
diff options
context:
space:
mode:
authorCharlie Blake2018-06-13 15:38:20 +0100
committerGitHub2018-06-13 15:38:20 +0100
commitccb1232a48deef855d0e0f3ea0f69382494975cc (patch)
treebcc8fe29ea84abbd6682c1a880064a90dd65f959 /src/main/game/global_cache.h
parentMerge pull request #59 from thecharlesblake/paper-tidy-up (diff)
parentAdd default cache capacity of 100,000,000 (diff)
downloadmetasol-ccb1232a48deef855d0e0f3ea0f69382494975cc.tar.gz
metasol-ccb1232a48deef855d0e0f3ea0f69382494975cc.zip

Merge pull request #60 from thecharlesblake/cache-mem-limit

Cache mem limit

Diffstat (limited to 'src/main/game/global_cache.h')
-rw-r--r--src/main/game/global_cache.h36
1 files changed, 29 insertions, 7 deletions
diff --git a/src/main/game/global_cache.h b/src/main/game/global_cache.h
index 9541100..dd4670e 100644
--- a/src/main/game/global_cache.h
+++ b/src/main/game/global_cache.h
@@ -9,6 +9,10 @@
#include <unordered_set>
#include <boost/pool/pool.hpp>
#include <boost/pool/pool_alloc.hpp>
+#include <boost/multi_index_container.hpp>
+#include <boost/multi_index/sequenced_index.hpp>
+#include <boost/multi_index/identity.hpp>
+#include <boost/multi_index/hashed_index.hpp>
#include "sol_rules.h"
#include "search-state/game_state.h"
@@ -23,7 +27,9 @@ struct cached_game_state {
void add_card_divider();
state_data data;
+ bool live; // Is a parent in the current search tree
};
+
bool operator==(const cached_game_state&, const cached_game_state&);
struct hasher {
@@ -36,18 +42,34 @@ struct hasher {
const game_state& init_gs;
};
-class global_cache {
+class lru_cache {
public:
- explicit global_cache(const game_state&);
- bool insert(const game_state&);
+ typedef boost::multi_index::multi_index_container<
+ cached_game_state,
+ boost::multi_index::indexed_by<
+ boost::multi_index::sequenced<>,
+ boost::multi_index::hashed_unique<
+ boost::multi_index::identity<cached_game_state>,
+ hasher
+ >
+ >
+ > item_list;
+
+ explicit lru_cache(const game_state&, uint64_t);
+ std::pair<item_list::iterator, bool> insert(const game_state&);
bool contains(const game_state&) const;
void clear();
+ item_list::size_type size() const;
+ item_list::size_type bucket_count() const;
+ void set_non_live(item_list::iterator);
+ uint64_t get_states_removed_from_cache() const;
private:
- std::unordered_set<
- cached_game_state,
- hasher
- > u_set;
+ static item_list::ctor_args_list get_init_tuple(const game_state&);
+
+ uint64_t max_num_items;
+ item_list cache;
+ uint64_t states_removed_from_cache;
};
#endif //SOLVITAIRE_GLOBAL_CACHE_H