-
Notifications
You must be signed in to change notification settings - Fork 1
/
late_util.hpp
56 lines (43 loc) · 1.23 KB
/
late_util.hpp
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
51
52
53
54
55
56
#ifndef LATE_UTIL
#define LATE_UTIL
#include "grammar.hpp"
struct word {
symbol lhs;
int origin, loc;
word(symbol l, int o, int c) : lhs(l), origin(o), loc(c) {}
inline bool operator==(const struct word &other) const {
return (lhs == other.lhs
&& origin == other.origin
&& loc == other.loc);
}
inline size_t hash() const {
size_t res = 17;
res = res * 31 + std::hash<symbol>()(lhs);
res = res * 31 + std::hash<int>()(origin);
res = res * 31 + std::hash<int>()(loc);
return res;
}
};
struct msg {
symbol lhs;
int origin;
msg(symbol l, int o) : lhs(l), origin(o) {}
inline bool operator==(const struct msg &other) const {
return (lhs == other.lhs && origin == other.origin);
}
inline size_t hash() const {
size_t res = 17;
res = res * 31 + std::hash<symbol>()(lhs);
res = res * 31 + std::hash<int>()(origin);
return res;
}
};
template <> struct std::hash<struct word> {
size_t operator()(const struct word& w) const { return w.hash(); }
};
template <> struct std::hash<struct msg> {
size_t operator()(const struct msg& r) const { return r.hash(); }
};
size_t tbb_hasher(const struct word& x);
size_t tbb_hasher(const struct msg& x);
#endif // LATE_UTIL