-
Notifications
You must be signed in to change notification settings - Fork 13
/
jenkins1.h
56 lines (46 loc) · 1.33 KB
/
jenkins1.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
50
51
52
53
54
55
56
//------------------------------- jenkins1.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 JENKINS1_H
#define JENKINS1_H
#include "endian.h"
#include <cstddef>
// namespace acme is used to demonstrate example code. It is not proposed.
namespace acme
{
class jenkins1
{
std::size_t state_ = 0;
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_ += *p;
state_ += state_ << 10;
state_ ^= state_ >> 6;
}
}
explicit
operator std::size_t() noexcept
{
state_ += state_ << 3;
state_ ^= state_ >> 11;
state_ += state_ << 15;
return state_;
}
};
} // acme
#endif // JENKINS1_H