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
|
#pragma once
#include <contrib/libs/farmhash/farmhash.h>
#include <util/system/types.h>
#include <util/generic/strbuf.h>
namespace NYT {
////////////////////////////////////////////////////////////////////////////////
using TFingerprint = ui64;
static inline TFingerprint FarmHash(ui64 value)
{
return ::util::Fingerprint(value);
}
static inline TFingerprint FarmHash(const void* buf, size_t len)
{
return ::util::Hash64(static_cast<const char*>(buf), len);
}
static inline TFingerprint FarmHash(const void* buf, size_t len, ui64 seed)
{
return ::util::Hash64WithSeed(static_cast<const char*>(buf), len, seed);
}
static inline TFingerprint FarmFingerprint(ui64 value)
{
return ::util::Fingerprint(value);
}
static inline TFingerprint FarmFingerprint(const void* buf, size_t len)
{
return ::util::Fingerprint64(static_cast<const char*>(buf), len);
}
static inline TFingerprint FarmFingerprint(TStringBuf buf)
{
return FarmFingerprint(buf.Data(), buf.Size());
}
static inline TFingerprint FarmFingerprint(ui64 first, ui64 second)
{
return ::util::Fingerprint(::util::Uint128(first, second));
}
// Forever-fixed Google FarmHash fingerprint.
template <class T>
TFingerprint FarmFingerprint(const T* begin, const T* end)
{
ui64 result = 0xdeadc0de;
for (const auto* value = begin; value < end; ++value) {
result = FarmFingerprint(result, FarmFingerprint(*value));
}
return result ^ (end - begin);
}
////////////////////////////////////////////////////////////////////////////////
} // namespace NYT
|