blob: e881408b8a1e7bf1bdf85ca3127479e397ee040a (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
//
// Created by thecharlesblake on 1/10/18.
//
#include <boost/functional/hash.hpp>
#include "global_cache.h"
using namespace std;
using namespace boost;
typedef sol_rules::build_policy pol;
global_cache::global_cache(const sol_rules& rules) {
global_cache::rules = rules;
}
bool global_cache::insert(const std::vector<pile>& pile_vec) {
return u_set.insert(pile_vec).second;
}
bool global_cache::contains(const std::vector<pile>& pile_vec) {
return u_set.count(pile_vec) > 0;
}
size_t hash_value(card const& c) {
boost::hash<unsigned char> hasher;
auto suit_val;
switch (global_cache::rules.build_pol) {
case pol::SAME_SUIT:
suit_val = static_cast<std::underlying_type_t<card::suit_t>>(
c.get_suit());
break;
case pol::RED_BLACK:
suit_val = static_cast<std::underlying_type_t<card::colour_t >>(
c.get_colour());
break;
default:
suit_val = 0;
break;
}
auto raw_val = static_cast<unsigned char>(suit_val * 13 + c.get_rank());
return hasher(raw_val);
}
size_t hash_value(pile const& p) {
return hash_range(begin(p.pile_vec), end(p.pile_vec));
}
|