Static Value-Flow Analysis
Loading...
Searching...
No Matches
Hash.h
Go to the documentation of this file.
1#ifndef Hash_H
2#define Hash_H
3
4#include <vector>
5
6namespace SVF
7{
8
10template <class T> struct Hash;
11
12template <class S, class T> struct Hash<std::pair<S, T>>
13{
14 // Pairing function from: http://szudzik.com/ElegantPairing.pdf
15 static size_t szudzik(size_t a, size_t b)
16 {
17 return a > b ? b * b + a : a * a + a + b;
18 }
19
20 size_t operator()(const std::pair<S, T>& t) const
21 {
22 Hash<decltype(t.first)> first;
23 Hash<decltype(t.second)> second;
24 return szudzik(first(t.first), second(t.second));
25 }
26};
27
28template <class T> struct Hash
29{
30 size_t operator()(const T& t) const
31 {
32 std::hash<T> h;
33 return h(t);
34 }
35};
36
37} // namespace SVF
38
39template <typename T> struct std::hash<std::vector<T>>
40{
41 size_t operator()(const std::vector<T>& v) const
42 {
43 // TODO: repetition with CBV.
44 size_t h = v.size();
45
46 SVF::Hash<T> hf;
47 for (const T& t : v)
48 {
49 h ^= hf(t) + 0x9e3779b9 + (h << 6) + (h >> 2);
50 }
51
52 return h;
53 }
54};
55
56#endif // Hash_H
cJSON * a
Definition cJSON.cpp:2560
const cJSON *const b
Definition cJSON.h:255
for isBitcode
Definition BasicTypes.h:70
llvm::IRBuilder IRBuilder
Definition BasicTypes.h:76
size_t operator()(const std::pair< S, T > &t) const
Definition Hash.h:20
static size_t szudzik(size_t a, size_t b)
Definition Hash.h:15
provide extra hash function for std::pair handling
Definition Hash.h:29
size_t operator()(const T &t) const
Definition Hash.h:30
size_t operator()(const std::vector< T > &v) const
Definition Hash.h:41