the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
1#pragma once
2
3#include <cstdint>
4
5// Java doesn't have a default hash value for ints, however, the hashmap itself does some "supplemental" hashing, so
6// our ints actually get hashed by code as implemented below. std templates *do* have a standard hash for ints, but it
7// would appear to be a bit expensive so matching the java one for now anyway. This code implements the supplemental
8// hashing that happens in java so we can match what their maps are doing with ints.
9
10struct IntKeyHash
11{
12 inline int operator()(const int &k) const
13 {
14 int h = k;
15 h += ~(h << 9);
16 h ^= (((unsigned int)h) >> 14);
17 h += (h << 4);
18 h ^= (((unsigned int)h) >> 10);
19 return h;
20 }
21};
22
23struct IntKeyEq
24{
25 inline bool operator()(const int &x, const int &y) const
26 { return x==y; }
27};
28
29// This hash functor is taken from the IntHashMap java class used by the game, so that we can use a standard std hashmap with this hash rather
30// than implement the class itself
31struct IntKeyHash2
32{
33 inline int operator()(const int &k) const
34 {
35 unsigned int h = static_cast<unsigned int>(k);
36 h ^= (h >> 20) ^ (h >> 12);
37 return static_cast<int>(h ^ (h >> 7) ^ (h >> 4));
38 }
39};
40
41
42// This hash functor is taken from the LongHashMap java class used by the game, so that we can use a standard std hashmap with this hash rather
43// than implement the class itself
44struct LongKeyHash
45{
46 inline int hash(const int &k) const
47 {
48 unsigned int h = static_cast<unsigned int>(k);
49 h ^= (h >> 20) ^ (h >> 12);
50 return static_cast<int>(h ^ (h >> 7) ^ (h >> 4));
51 }
52
53 inline int operator()(const int64_t &k) const
54 {
55 return hash(static_cast<int>(k ^ ((static_cast<uint64_t>(k)) >> 32)));
56 }
57};
58
59struct LongKeyEq
60{
61 inline bool operator() (const int64_t &x, const int64_t &y) const
62 { return x == y; }
63};
64
65enum eINSTANCEOF;
66struct eINSTANCEOFKeyHash
67{
68 int operator()(const eINSTANCEOF &k) const
69 {
70 unsigned int h = static_cast<unsigned int>(k);
71 h ^= (h >> 20) ^ (h >> 12);
72 return static_cast<int>(h ^ (h >> 7) ^ (h >> 4));
73 }
74};
75
76struct eINSTANCEOFKeyEq
77{
78 inline bool operator()(const eINSTANCEOF &x, const eINSTANCEOF &y) const
79 { return x == y; }
80};
81