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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
#pragma once
#include <unordered_set>
#include <unordered_map>
#include <util/generic/hash.h>
#include <util/generic/hash_multi_map.h>
#include <util/generic/hash_set.h>
namespace NYql {
#ifndef NDEBUG
size_t VaryingHash(size_t src);
#else
inline size_t VaryingHash(size_t src) {
return src;
}
#endif
template <typename T, typename THasher = ::THash<T>>
struct TVaryingHash {
THasher Underlying;
TVaryingHash() = default;
TVaryingHash(const TVaryingHash&) = default;
TVaryingHash(const THasher& underlying)
: Underlying(underlying)
{}
TVaryingHash& operator=(const TVaryingHash& other) = default;
size_t operator()(const T& elem) const {
return VaryingHash(Underlying(elem));
}
};
template <class TKey,
class TValue,
class THasher = std::hash<TKey>,
class TEqual = std::equal_to<TKey>,
class TAlloc = std::allocator<std::pair<const TKey, TValue>>>
using TVaryingUnorderedMap = std::unordered_map<TKey, TValue, TVaryingHash<TKey, THasher>, TEqual, TAlloc>;
template <class TKey,
class TValue,
class THasher = std::hash<TKey>,
class TEqual = std::equal_to<TKey>,
class TAlloc = std::allocator<std::pair<const TKey, TValue>>>
using TVaryingUnorderedMultiMap = std::unordered_multimap<TKey, TValue, TVaryingHash<TKey, THasher>, TEqual, TAlloc>;
template <class TKey,
class THasher = std::hash<TKey>,
class TEqual = std::equal_to<TKey>,
class TAlloc = std::allocator<TKey>>
using TVaryingUnorderedSet = std::unordered_set<TKey, TVaryingHash<TKey, THasher>, TEqual, TAlloc>;
template <class TKey,
class THasher = std::hash<TKey>,
class TEqual = std::equal_to<TKey>,
class TAlloc = std::allocator<TKey>>
using TVaryingUnorderedMultiSet = std::unordered_multiset<TKey, TVaryingHash<TKey, THasher>, TEqual, TAlloc>;
template <class TKey,
class TValue,
class THasher = THash<TKey>,
class TEqual = TEqualTo<TKey>,
class TAlloc = std::allocator<std::pair<const TKey, TValue>>>
using TVaryingHashMap = THashMap<TKey, TValue, TVaryingHash<TKey, THasher>, TEqual, TAlloc>;
template <class TKey,
class TValue,
class THasher = THash<TKey>,
class TEqual = TEqualTo<TKey>,
class TAlloc = std::allocator<std::pair<const TKey, TValue>>>
using TVaryingHashMultiMap = THashMultiMap<TKey, TValue, TVaryingHash<TKey, THasher>, TEqual, TAlloc>;
template <class TKey,
class THasher = THash<TKey>,
class TEqual = TEqualTo<TKey>,
class TAlloc = std::allocator<TKey>>
using TVaryingHashSet = THashSet<TKey, TVaryingHash<TKey, THasher>, TEqual, TAlloc>;
template <class TKey,
class THasher = THash<TKey>,
class TEqual = TEqualTo<TKey>,
class TAlloc = std::allocator<TKey>>
using TVaryingHashMultiSet = THashMultiSet<TKey, TVaryingHash<TKey, THasher>, TEqual, TAlloc>;
} // namespace NYql
|