aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/yt/misc/hash.h
blob: fe4087c331566836a91866e8bd9c6332da9e311d (plain) (blame)
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
#pragma once

#include <util/generic/hash.h>

#include <util/random/random.h>

namespace NYT {

////////////////////////////////////////////////////////////////////////////////

//! Updates #h with #k.
//! Cf. |boost::hash_combine|.
void HashCombine(size_t& h, size_t k);

//! Updates #h with the hash of #k.
//! Cf. |boost::hash_combine|.
template <class T>
void HashCombine(size_t& h, const T& k);

//! Computes the hash of #value handling NaN values gracefully
//! (returning the same constant for all NaNs).
//! If |T| is not a floating-point type, #NaNSafeHash is equivalent to #THash.
template <class T>
size_t NaNSafeHash(const T& value);

////////////////////////////////////////////////////////////////////////////////

//! Provides a hasher that randomizes the results of another one.
template <class TElement, class TUnderlying = ::THash<TElement>>
class TRandomizedHash
{
public:
    TRandomizedHash();
    size_t operator()(const TElement& element) const;

private:
    size_t Seed_;
    TUnderlying Underlying_;
};

////////////////////////////////////////////////////////////////////////////////

} // namespace NYT

#define HASH_INL_H_
#include "hash-inl.h"
#undef HASH_INL_H_