forked from greg7mdp/parallel-hashmap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhash.cc
48 lines (42 loc) · 1.07 KB
/
hash.cc
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
#include <parallel_hashmap/phmap_utils.h> // minimal header providing phmap::HashState()
#include <string>
#include <utility>
#include <tuple>
#include <vector>
#include <array>
#if PHMAP_HAVE_STD_STRING_VIEW
#include <string_view>
#endif
#include <iostream>
using std::string;
using std::tuple;
using std::pair;
using groupid_t = std::array<uint16_t, 4>;
namespace std
{
template<> struct hash<groupid_t>
{
#if PHMAP_HAVE_STD_STRING_VIEW
std::size_t operator()(groupid_t const &g) const
{
const std::string_view bv{reinterpret_cast<const char*>(g.data()), sizeof(g)};
return std::hash<std::string_view>()(bv);
}
#else
std::size_t operator()(groupid_t const &g) const
{
return phmap::Hash<decltype(std::tuple_cat(g))>()(std::tuple_cat(g));
}
#endif
};
}
int main()
{
std::vector<groupid_t> groups = {
{17, 75, 82, 66},
{22, 88, 54, 42},
{11, 55, 77, 99} };
for (const auto &g : groups)
std::cout << std::hash<groupid_t>()(g) << '\n';
return 0;
}