rippled
ripple
beast
hash
xxhasher.h
1
//------------------------------------------------------------------------------
2
/*
3
This file is part of Beast: https://github.com/vinniefalco/Beast
4
Copyright 2014, Vinnie Falco <vinnie.falco@gmail.com>
5
6
Permission to use, copy, modify, and/or distribute this software for any
7
purpose with or without fee is hereby granted, provided that the above
8
copyright notice and this permission notice appear in all copies.
9
10
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17
*/
18
//==============================================================================
19
20
#ifndef BEAST_HASH_XXHASHER_H_INCLUDED
21
#define BEAST_HASH_XXHASHER_H_INCLUDED
22
23
#include <ripple/beast/hash/endian.h>
24
#include <ripple/beast/hash/impl/xxhash.h>
25
#include <
cstddef
>
26
#include <
type_traits
>
27
28
namespace
beast
{
29
30
class
xxhasher
31
{
32
private
:
33
// requires 64-bit std::size_t
34
static_assert(
sizeof
(
std::size_t
) == 8,
""
);
35
36
detail::XXH64_state_t
state_
;
37
38
public
:
39
using
result_type
=
std::size_t
;
40
41
static
beast::endian
const
endian
=
beast::endian::native
;
42
43
xxhasher
() noexcept
44
{
45
detail::XXH64_reset
(&
state_
, 1);
46
}
47
48
template
<
49
class
Seed,
50
std::enable_if_t<std::is_unsigned<Seed>::value
>* =
nullptr
>
51
explicit
xxhasher
(Seed seed)
52
{
53
detail::XXH64_reset
(&
state_
, seed);
54
}
55
56
template
<
57
class
Seed,
58
std::enable_if_t<std::is_unsigned<Seed>::value
>* =
nullptr
>
59
xxhasher
(Seed seed, Seed)
60
{
61
detail::XXH64_reset
(&
state_
, seed);
62
}
63
64
void
65
operator()
(
void
const
* key,
std::size_t
len) noexcept
66
{
67
detail::XXH64_update
(&
state_
, key, len);
68
}
69
70
explicit
operator
std::size_t
() noexcept
71
{
72
return
detail::XXH64_digest
(&
state_
);
73
}
74
};
75
76
}
// namespace beast
77
78
#endif
beast::detail::XXH64_update
XXH_errorcode XXH64_update(XXH64_state_t *state_in, const void *input, size_t len)
Definition:
xxhash.cpp:891
beast::xxhasher
Definition:
xxhasher.h:30
beast::xxhasher::xxhasher
xxhasher() noexcept
Definition:
xxhasher.h:43
beast::xxhasher::state_
detail::XXH64_state_t state_
Definition:
xxhasher.h:34
beast::detail::XXH64_reset
XXH_errorcode XXH64_reset(XXH64_state_t *state_in, unsigned long long seed)
Definition:
xxhash.cpp:622
std::enable_if_t
beast::detail::XXH64_digest
unsigned long long XXH64_digest(const XXH64_state_t *state_in)
Definition:
xxhash.cpp:985
cstddef
beast::xxhasher::xxhasher
xxhasher(Seed seed, Seed)
Definition:
xxhasher.h:59
beast::endian::native
@ native
beast::xxhasher::xxhasher
xxhasher(Seed seed)
Definition:
xxhasher.h:51
beast::xxhasher::operator()
void operator()(void const *key, std::size_t len) noexcept
Definition:
xxhasher.h:65
std::size_t
type_traits
beast::detail::XXH64_state_t
Definition:
xxhash.h:107
beast::endian
endian
Definition:
endian.h:30
beast
Definition:
base_uint.h:646
Generated by
1.8.17