-
Notifications
You must be signed in to change notification settings - Fork 13
/
fnv1a.h
49 lines (39 loc) · 1.18 KB
/
fnv1a.h
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
//-------------------------------- fnv1a.h -------------------------------------
//
// This software is in the public domain. The only restriction on its use is
// that no one can remove it from the public domain by claiming ownership of it,
// including the original authors.
//
// There is no warranty of correctness on the software contained herein. Use
// at your own risk.
//
//------------------------------------------------------------------------------
#ifndef FNV1A_H
#define FNV1A_H
#include "endian.h"
#include <cstddef>
// namespace acme is used to demonstrate example code. It is not proposed.
namespace acme
{
class fnv1a
{
std::size_t state_ = 14695981039346656037u;
public:
static constexpr xstd::endian endian = xstd::endian::native;
using result_type = std::size_t;
void
operator()(void const* key, std::size_t len) noexcept
{
unsigned char const* p = static_cast<unsigned char const*>(key);
unsigned char const* const e = p + len;
for (; p < e; ++p)
state_ = (state_ ^ *p) * 1099511628211u;
}
explicit
operator std::size_t() noexcept
{
return state_;
}
};
} // acme
#endif // FNV1A_H