rippled
Loading...
Searching...
No Matches
uhash.h
1//------------------------------------------------------------------------------
2/*
3 This file is part of Beast: https://github.com/vinniefalco/Beast
4 Copyright 2014, Howard Hinnant <howard.hinnant@gmail.com>,
5 Vinnie Falco <vinnie.falco@gmail.com
6
7 Permission to use, copy, modify, and/or distribute this software for any
8 purpose with or without fee is hereby granted, provided that the above
9 copyright notice and this permission notice appear in all copies.
10
11 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14 ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18*/
19//==============================================================================
20
21#ifndef BEAST_HASH_UHASH_H_INCLUDED
22#define BEAST_HASH_UHASH_H_INCLUDED
23
24#include <xrpl/beast/hash/hash_append.h>
25#include <xrpl/beast/hash/xxhasher.h>
26
27namespace beast {
28
29// Universal hash function
30template <class Hasher = xxhasher>
31struct uhash
32{
33 explicit uhash() = default;
34
35 using result_type = typename Hasher::result_type;
36
37 template <class T>
39 operator()(T const& t) const noexcept
40 {
41 Hasher h;
42 hash_append(h, t);
43 return static_cast<result_type>(h);
44 }
45};
46
47} // namespace beast
48
49#endif
std::enable_if_t< is_contiguously_hashable< T, Hasher >::value > hash_append(Hasher &h, T const &t) noexcept
Logically concatenate input data to a Hasher.
Definition: hash_append.h:237
uhash()=default
result_type operator()(T const &t) const noexcept
Definition: uhash.h:39
typename Hasher::result_type result_type
Definition: uhash.h:35