rippled
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/impl/xxhash.h>
24 #include <boost/endian/conversion.hpp>
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 
37 
38 public:
40 
41  static constexpr auto const endian = boost::endian::order::native;
42 
43  xxhasher() noexcept
44  {
46  }
47 
48  template <
49  class Seed,
51  explicit xxhasher(Seed seed)
52  {
54  }
55 
56  template <
57  class Seed,
59  xxhasher(Seed seed, Seed)
60  {
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  {
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:899
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:630
std::enable_if_t
beast::detail::XXH64_digest
unsigned long long XXH64_digest(const XXH64_state_t *state_in)
Definition: xxhash.cpp:993
cstddef
beast::xxhasher::xxhasher
xxhasher(Seed seed, Seed)
Definition: xxhasher.h:59
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
beast::xxhasher::endian
static constexpr const auto endian
Definition: xxhasher.h:41
type_traits
beast::detail::XXH64_state_t
Definition: xxhash.h:107
beast
Definition: base_uint.h:641