aboutsummaryrefslogtreecommitdiff
path: root/src/main/game/global_cache.h
diff options
context:
space:
mode:
authorCharlie Blake2018-06-12 16:57:32 +0100
committerCharlie Blake2018-06-12 16:57:32 +0100
commit43a11ee2ee7827290d631698ea25b6724c8a1c29 (patch)
tree360cf97812a75459d10ced96849d9cf4e7eee338 /src/main/game/global_cache.h
parentSpeedup build and add lru cache (diff)
downloadmetasol-43a11ee2ee7827290d631698ea25b6724c8a1c29.tar.gz
metasol-43a11ee2ee7827290d631698ea25b6724c8a1c29.zip

Add lru cache with elems limit

Diffstat (limited to 'src/main/game/global_cache.h')
-rw-r--r--src/main/game/global_cache.h35
1 files changed, 9 insertions, 26 deletions
diff --git a/src/main/game/global_cache.h b/src/main/game/global_cache.h
index e420b57..7798f78 100644
--- a/src/main/game/global_cache.h
+++ b/src/main/game/global_cache.h
@@ -27,6 +27,7 @@ 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&);
@@ -41,29 +42,8 @@ struct hasher {
const game_state& init_gs;
};
-class global_cache {
+class lru_cache {
public:
- virtual ~global_cache() = default;
- virtual bool insert(const game_state&) = 0;
- virtual bool contains(const game_state&) const = 0;
- virtual void clear() = 0;
-};
-
-class unlimited_cache : public global_cache {
-public:
- explicit unlimited_cache(const game_state&);
- bool insert(const game_state&) override;
- bool contains(const game_state&) const override;
- void clear() override;
-
-private:
- std::unordered_set<
- cached_game_state,
- hasher
- > cache;
-};
-
-class lru_cache : public global_cache {
typedef boost::multi_index::multi_index_container<
cached_game_state,
boost::multi_index::indexed_by<
@@ -74,17 +54,20 @@ class lru_cache : public global_cache {
>
>
> item_list;
-public:
+
explicit lru_cache(const game_state&, std::size_t);
- bool insert(const game_state&) override;
- bool contains(const game_state&) const override;
- void clear() override;
+ std::pair<item_list::iterator, bool> insert(const game_state&);
+ bool contains(const game_state&) const;
+ void clear();
+ void set_non_live(item_list::iterator);
+ int get_states_removed_from_cache() const;
private:
static item_list::ctor_args_list get_init_tuple(const game_state&);
std::size_t max_num_items;
item_list cache;
+ int states_removed_from_cache;
};
#endif //SOLVITAIRE_GLOBAL_CACHE_H