mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-21 11:35:53 +00:00
Refactoring of container usage:
* New ripple container aliases use hardened_hash * Use std::tuple instead of boost::tuple * Use std unordered containers instead of boost * Fix Destroyer for new containers * Fix warning for fnv1a on 32-bit arch * Validator fixes for new containers
This commit is contained in:
committed by
Vinnie Falco
parent
8f5b4a6c96
commit
fdfcebd1cb
@@ -22,14 +22,14 @@
|
|||||||
|
|
||||||
#include "hash_append.h"
|
#include "hash_append.h"
|
||||||
|
|
||||||
#include "impl/spookyv2.h"
|
|
||||||
|
|
||||||
#include "../utility/noexcept.h"
|
#include "../utility/noexcept.h"
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <random>
|
#include <random>
|
||||||
#include "../cxx14/type_traits.h" // <type_traits>
|
#include "../cxx14/type_traits.h" // <type_traits>
|
||||||
|
#include <unordered_map>
|
||||||
|
#include <unordered_set>
|
||||||
#include "../cxx14/utility.h" // <utility>
|
#include "../cxx14/utility.h" // <utility>
|
||||||
|
|
||||||
// When set to 1, makes the seed per-process instead
|
// When set to 1, makes the seed per-process instead
|
||||||
@@ -115,30 +115,6 @@ private:
|
|||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
class spooky_wrapper
|
|
||||||
{
|
|
||||||
SpookyHash state_;
|
|
||||||
public:
|
|
||||||
spooky_wrapper (std::size_t seed1 = 1, std::size_t seed2 = 2) noexcept
|
|
||||||
{
|
|
||||||
state_.Init (seed1, seed2);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
append (void const* key, std::size_t len) noexcept
|
|
||||||
{
|
|
||||||
state_.Update (key, len);
|
|
||||||
}
|
|
||||||
|
|
||||||
explicit
|
|
||||||
operator std::size_t() noexcept
|
|
||||||
{
|
|
||||||
std::uint64_t h1, h2;
|
|
||||||
state_.Final (&h1, &h2);
|
|
||||||
return static_cast <std::size_t> (h1);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
} // detail
|
} // detail
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -23,14 +23,17 @@
|
|||||||
|
|
||||||
#include "../utility/meta.h"
|
#include "../utility/meta.h"
|
||||||
|
|
||||||
|
#include "impl/spookyv2.h"
|
||||||
|
|
||||||
#if BEAST_USE_BOOST_FEATURES
|
#if BEAST_USE_BOOST_FEATURES
|
||||||
#include <boost/tuple/tuple.hpp>
|
#include <boost/shared_ptr.hpp>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "../utility/noexcept.h"
|
#include "../utility/noexcept.h"
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <tuple>
|
#include <tuple>
|
||||||
#include "../cxx14/type_traits.h" // <type_traits>
|
#include "../cxx14/type_traits.h" // <type_traits>
|
||||||
@@ -141,20 +144,6 @@ static_assert (is_contiguously_hashable <
|
|||||||
std::tuple <char, char, short>>::value, "");
|
std::tuple <char, char, short>>::value, "");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if BEAST_USE_BOOST_FEATURES
|
|
||||||
|
|
||||||
#if ! BEAST_NO_TUPLE_VARIADICS
|
|
||||||
// boost::tuple
|
|
||||||
template <class ...T>
|
|
||||||
struct is_contiguously_hashable <boost::tuple<T...>>
|
|
||||||
: public std::integral_constant <bool,
|
|
||||||
static_and <is_contiguously_hashable<T>::value...>::value &&
|
|
||||||
static_sum <sizeof(T)...>::value == sizeof(boost::tuple<T...>)>
|
|
||||||
{
|
|
||||||
};
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif // BEAST_USE_BOOST_FEATURES
|
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
@@ -379,97 +368,6 @@ hash_append (Hasher& h, std::tuple <
|
|||||||
T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> const& t) noexcept;
|
T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> const& t) noexcept;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// boost::tuple
|
|
||||||
|
|
||||||
#if BEAST_USE_BOOST_FEATURES
|
|
||||||
|
|
||||||
template <class Hasher>
|
|
||||||
inline
|
|
||||||
void
|
|
||||||
hash_append (Hasher& h, boost::tuple<> const& t) noexcept;
|
|
||||||
|
|
||||||
#if BEAST_VARIADIC_MAX >= 1
|
|
||||||
template <class Hasher, class T1>
|
|
||||||
inline
|
|
||||||
void
|
|
||||||
hash_append (Hasher& h, boost::tuple <T1> const& t) noexcept;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if BEAST_VARIADIC_MAX >= 2
|
|
||||||
template <class Hasher, class T1, class T2>
|
|
||||||
inline
|
|
||||||
void
|
|
||||||
hash_append (Hasher& h, boost::tuple <T1, T2> const& t) noexcept;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if BEAST_VARIADIC_MAX >= 3
|
|
||||||
template <class Hasher, class T1, class T2, class T3>
|
|
||||||
inline
|
|
||||||
void
|
|
||||||
hash_append (Hasher& h, boost::tuple <T1, T2, T3> const& t) noexcept;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if BEAST_VARIADIC_MAX >= 4
|
|
||||||
template <class Hasher, class T1, class T2, class T3, class T4>
|
|
||||||
inline
|
|
||||||
void
|
|
||||||
hash_append (Hasher& h, boost::tuple <T1, T2, T3, T4> const& t) noexcept;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if BEAST_VARIADIC_MAX >= 5
|
|
||||||
template <class Hasher, class T1, class T2, class T3, class T4, class T5>
|
|
||||||
inline
|
|
||||||
void
|
|
||||||
hash_append (Hasher& h, boost::tuple <T1, T2, T3, T4, T5> const& t) noexcept;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if BEAST_VARIADIC_MAX >= 6
|
|
||||||
template <class Hasher, class T1, class T2, class T3, class T4, class T5,
|
|
||||||
class T6>
|
|
||||||
inline
|
|
||||||
void
|
|
||||||
hash_append (Hasher& h, boost::tuple <
|
|
||||||
T1, T2, T3, T4, T5, T6> const& t) noexcept;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if BEAST_VARIADIC_MAX >= 7
|
|
||||||
template <class Hasher, class T1, class T2, class T3, class T4, class T5,
|
|
||||||
class T6, class T7>
|
|
||||||
inline
|
|
||||||
void
|
|
||||||
hash_append (Hasher& h, boost::tuple <
|
|
||||||
T1, T2, T3, T4, T5, T6, T7> const& t) noexcept;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if BEAST_VARIADIC_MAX >= 8
|
|
||||||
template <class Hasher, class T1, class T2, class T3, class T4, class T5,
|
|
||||||
class T6, class T7, class T8>
|
|
||||||
inline
|
|
||||||
void
|
|
||||||
hash_append (Hasher& h, boost::tuple <
|
|
||||||
T1, T2, T3, T4, T5, T6, T7, T8> const& t) noexcept;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if BEAST_VARIADIC_MAX >= 9
|
|
||||||
template <class Hasher, class T1, class T2, class T3, class T4, class T5,
|
|
||||||
class T6, class T7, class T8, class T9>
|
|
||||||
inline
|
|
||||||
void
|
|
||||||
hash_append (Hasher& h, boost::tuple <
|
|
||||||
T1, T2, T3, T4, T5, T6, T7, T8, T9> const& t) noexcept;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if BEAST_VARIADIC_MAX >= 10
|
|
||||||
template <class Hasher, class T1, class T2, class T3, class T4, class T5,
|
|
||||||
class T6, class T7, class T8, class T9, class T10>
|
|
||||||
inline
|
|
||||||
void
|
|
||||||
hash_append (Hasher& h, boost::tuple <
|
|
||||||
T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> const& t) noexcept;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif // BEAST_USE_BOOST_FEATURES
|
|
||||||
|
|
||||||
#endif // BEAST_NO_TUPLE_VARIADICS
|
#endif // BEAST_NO_TUPLE_VARIADICS
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
@@ -688,209 +586,6 @@ hash_append (Hasher& h, std::tuple<T...> const& t) noexcept
|
|||||||
|
|
||||||
#endif // BEAST_NO_TUPLE_VARIADICS
|
#endif // BEAST_NO_TUPLE_VARIADICS
|
||||||
|
|
||||||
// boost::tuple
|
|
||||||
|
|
||||||
#if BEAST_USE_BOOST_FEATURES
|
|
||||||
|
|
||||||
template <class Hasher>
|
|
||||||
inline
|
|
||||||
void
|
|
||||||
hash_append (Hasher& h, boost::tuple<> const& t) noexcept
|
|
||||||
{
|
|
||||||
hash_append (h, nullptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
#if BEAST_NO_TUPLE_VARIADICS
|
|
||||||
|
|
||||||
#if BEAST_VARIADIC_MAX >= 1
|
|
||||||
template <class Hasher, class T1>
|
|
||||||
inline
|
|
||||||
void
|
|
||||||
hash_append (Hasher& h, boost::tuple <T1> const& t) noexcept
|
|
||||||
{
|
|
||||||
hash_append (h, boost::get<0>(t));
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if BEAST_VARIADIC_MAX >= 2
|
|
||||||
template <class Hasher, class T1, class T2>
|
|
||||||
inline
|
|
||||||
void
|
|
||||||
hash_append (Hasher& h, boost::tuple <T1, T2> const& t) noexcept
|
|
||||||
{
|
|
||||||
hash_append (h, boost::get<0>(t));
|
|
||||||
hash_append (h, boost::get<1>(t));
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if BEAST_VARIADIC_MAX >= 3
|
|
||||||
template <class Hasher, class T1, class T2, class T3>
|
|
||||||
inline
|
|
||||||
void
|
|
||||||
hash_append (Hasher& h, boost::tuple <T1, T2, T3> const& t) noexcept
|
|
||||||
{
|
|
||||||
hash_append (h, boost::get<0>(t));
|
|
||||||
hash_append (h, boost::get<1>(t));
|
|
||||||
hash_append (h, boost::get<2>(t));
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if BEAST_VARIADIC_MAX >= 4
|
|
||||||
template <class Hasher, class T1, class T2, class T3, class T4>
|
|
||||||
inline
|
|
||||||
void
|
|
||||||
hash_append (Hasher& h, boost::tuple <T1, T2, T3, T4> const& t) noexcept
|
|
||||||
{
|
|
||||||
hash_append (h, boost::get<0>(t));
|
|
||||||
hash_append (h, boost::get<1>(t));
|
|
||||||
hash_append (h, boost::get<2>(t));
|
|
||||||
hash_append (h, boost::get<3>(t));
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if BEAST_VARIADIC_MAX >= 5
|
|
||||||
template <class Hasher, class T1, class T2, class T3, class T4, class T5>
|
|
||||||
inline
|
|
||||||
void
|
|
||||||
hash_append (Hasher& h, boost::tuple <
|
|
||||||
T1, T2, T3, T4, T5> const& t) noexcept
|
|
||||||
{
|
|
||||||
hash_append (h, boost::get<0>(t));
|
|
||||||
hash_append (h, boost::get<1>(t));
|
|
||||||
hash_append (h, boost::get<2>(t));
|
|
||||||
hash_append (h, boost::get<3>(t));
|
|
||||||
hash_append (h, boost::get<4>(t));
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if BEAST_VARIADIC_MAX >= 6
|
|
||||||
template <class Hasher, class T1, class T2, class T3, class T4, class T5,
|
|
||||||
class T6>
|
|
||||||
inline
|
|
||||||
void
|
|
||||||
hash_append (Hasher& h, boost::tuple <
|
|
||||||
T1, T2, T3, T4, T5, T6> const& t) noexcept
|
|
||||||
{
|
|
||||||
hash_append (h, boost::get<0>(t));
|
|
||||||
hash_append (h, boost::get<1>(t));
|
|
||||||
hash_append (h, boost::get<2>(t));
|
|
||||||
hash_append (h, boost::get<3>(t));
|
|
||||||
hash_append (h, boost::get<4>(t));
|
|
||||||
hash_append (h, boost::get<5>(t));
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if BEAST_VARIADIC_MAX >= 7
|
|
||||||
template <class Hasher, class T1, class T2, class T3, class T4, class T5,
|
|
||||||
class T6, class T7>
|
|
||||||
inline
|
|
||||||
void
|
|
||||||
hash_append (Hasher& h, boost::tuple <
|
|
||||||
T1, T2, T3, T4, T5, T6, T7> const& t) noexcept
|
|
||||||
{
|
|
||||||
hash_append (h, boost::get<0>(t));
|
|
||||||
hash_append (h, boost::get<1>(t));
|
|
||||||
hash_append (h, boost::get<2>(t));
|
|
||||||
hash_append (h, boost::get<3>(t));
|
|
||||||
hash_append (h, boost::get<4>(t));
|
|
||||||
hash_append (h, boost::get<5>(t));
|
|
||||||
hash_append (h, boost::get<6>(t));
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if BEAST_VARIADIC_MAX >= 8
|
|
||||||
template <class Hasher, class T1, class T2, class T3, class T4, class T5,
|
|
||||||
class T6, class T7, class T8>
|
|
||||||
inline
|
|
||||||
void
|
|
||||||
hash_append (Hasher& h, boost::tuple <
|
|
||||||
T1, T2, T3, T4, T5, T6, T7, T8> const& t) noexcept
|
|
||||||
{
|
|
||||||
hash_append (h, boost::get<0>(t));
|
|
||||||
hash_append (h, boost::get<1>(t));
|
|
||||||
hash_append (h, boost::get<2>(t));
|
|
||||||
hash_append (h, boost::get<3>(t));
|
|
||||||
hash_append (h, boost::get<4>(t));
|
|
||||||
hash_append (h, boost::get<5>(t));
|
|
||||||
hash_append (h, boost::get<6>(t));
|
|
||||||
hash_append (h, boost::get<7>(t));
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if BEAST_VARIADIC_MAX >= 9
|
|
||||||
template <class Hasher, class T1, class T2, class T3, class T4, class T5,
|
|
||||||
class T6, class T7, class T8, class T9>
|
|
||||||
inline
|
|
||||||
void
|
|
||||||
hash_append (Hasher& h, boost::tuple <
|
|
||||||
T1, T2, T3, T4, T5, T6, T7, T8, T9> const& t) noexcept
|
|
||||||
{
|
|
||||||
hash_append (h, boost::get<0>(t));
|
|
||||||
hash_append (h, boost::get<1>(t));
|
|
||||||
hash_append (h, boost::get<2>(t));
|
|
||||||
hash_append (h, boost::get<3>(t));
|
|
||||||
hash_append (h, boost::get<4>(t));
|
|
||||||
hash_append (h, boost::get<5>(t));
|
|
||||||
hash_append (h, boost::get<6>(t));
|
|
||||||
hash_append (h, boost::get<7>(t));
|
|
||||||
hash_append (h, boost::get<8>(t));
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if BEAST_VARIADIC_MAX >= 10
|
|
||||||
template <class Hasher, class T1, class T2, class T3, class T4, class T5,
|
|
||||||
class T6, class T7, class T8, class T9, class T10>
|
|
||||||
inline
|
|
||||||
void
|
|
||||||
hash_append (Hasher& h, boost::tuple <
|
|
||||||
T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> const& t) noexcept
|
|
||||||
{
|
|
||||||
hash_append (h, boost::get<0>(t));
|
|
||||||
hash_append (h, boost::get<1>(t));
|
|
||||||
hash_append (h, boost::get<2>(t));
|
|
||||||
hash_append (h, boost::get<3>(t));
|
|
||||||
hash_append (h, boost::get<4>(t));
|
|
||||||
hash_append (h, boost::get<5>(t));
|
|
||||||
hash_append (h, boost::get<6>(t));
|
|
||||||
hash_append (h, boost::get<7>(t));
|
|
||||||
hash_append (h, boost::get<8>(t));
|
|
||||||
hash_append (h, boost::get<9>(t));
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#else // BEAST_NO_TUPLE_VARIADICS
|
|
||||||
|
|
||||||
namespace detail {
|
|
||||||
|
|
||||||
template <class Hasher, class ...T, std::size_t ...I>
|
|
||||||
inline
|
|
||||||
void
|
|
||||||
tuple_hash (Hasher& h, boost::tuple<T...> const& t,
|
|
||||||
std::index_sequence<I...>) noexcept
|
|
||||||
{
|
|
||||||
struct for_each_item {
|
|
||||||
for_each_item (...) { }
|
|
||||||
};
|
|
||||||
for_each_item (hash_one(h, boost::get<I>(t))...);
|
|
||||||
}
|
|
||||||
|
|
||||||
} // detail
|
|
||||||
|
|
||||||
template <class Hasher, class ...T>
|
|
||||||
inline
|
|
||||||
typename std::enable_if
|
|
||||||
<
|
|
||||||
!is_contiguously_hashable<boost::tuple<T...>>::value
|
|
||||||
>::type
|
|
||||||
hash_append (Hasher& h, boost::tuple<T...> const& t) noexcept
|
|
||||||
{
|
|
||||||
detail::tuple_hash(h, t, std::index_sequence_for<T...>{});
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // BEAST_NO_TUPLE_VARIADICS
|
|
||||||
|
|
||||||
#endif // BEAST_USE_BOOST_FEATURES
|
|
||||||
|
|
||||||
// pair
|
// pair
|
||||||
|
|
||||||
template <class Hasher, class T, class U>
|
template <class Hasher, class T, class U>
|
||||||
@@ -930,6 +625,28 @@ hash_append (Hasher& h, std::vector<T, Alloc> const& v) noexcept
|
|||||||
h.append (v.data(), v.size()*sizeof(T));
|
h.append (v.data(), v.size()*sizeof(T));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// shared_ptr
|
||||||
|
|
||||||
|
template <class Hasher, class T>
|
||||||
|
inline
|
||||||
|
void
|
||||||
|
hash_append (Hasher& h, std::shared_ptr<T> const& p) noexcept
|
||||||
|
{
|
||||||
|
hash_append(h, p.get());
|
||||||
|
}
|
||||||
|
|
||||||
|
#if BEAST_USE_BOOST_FEATURES
|
||||||
|
template <class Hasher, class T>
|
||||||
|
inline
|
||||||
|
void
|
||||||
|
hash_append (Hasher& h, boost::shared_ptr<T> const& p) noexcept
|
||||||
|
{
|
||||||
|
hash_append(h, p.get());
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// variadic hash_append
|
||||||
|
|
||||||
template <class Hasher, class T0, class T1, class ...T>
|
template <class Hasher, class T0, class T1, class ...T>
|
||||||
inline
|
inline
|
||||||
void
|
void
|
||||||
@@ -939,6 +656,62 @@ hash_append (Hasher& h, T0 const& t0, T1 const& t1, T const& ...t) noexcept
|
|||||||
hash_append (h, t1, t...);
|
hash_append (h, t1, t...);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace detail
|
||||||
|
{
|
||||||
|
|
||||||
|
class spooky_wrapper
|
||||||
|
{
|
||||||
|
SpookyHash state_;
|
||||||
|
public:
|
||||||
|
using result_type = std::size_t;
|
||||||
|
|
||||||
|
spooky_wrapper (std::size_t seed1 = 1, std::size_t seed2 = 2) noexcept
|
||||||
|
{
|
||||||
|
state_.Init (seed1, seed2);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
append (void const* key, std::size_t len) noexcept
|
||||||
|
{
|
||||||
|
state_.Update (key, len);
|
||||||
|
}
|
||||||
|
|
||||||
|
explicit
|
||||||
|
operator std::size_t() noexcept
|
||||||
|
{
|
||||||
|
std::uint64_t h1, h2;
|
||||||
|
state_.Final (&h1, &h2);
|
||||||
|
return static_cast <std::size_t> (h1);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
} // detail
|
||||||
|
|
||||||
|
template <class Hasher = detail::spooky_wrapper>
|
||||||
|
struct uhash
|
||||||
|
{
|
||||||
|
using result_type = typename Hasher::result_type;
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
result_type
|
||||||
|
operator()(T const& t) const noexcept
|
||||||
|
{
|
||||||
|
Hasher h;
|
||||||
|
hash_append (h, t);
|
||||||
|
return static_cast<result_type>(h);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
struct call_hash_value
|
||||||
|
{
|
||||||
|
template <class T>
|
||||||
|
std::size_t
|
||||||
|
operator()(T const& t) const noexcept
|
||||||
|
{
|
||||||
|
return hash_value(t);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
} // beast
|
} // beast
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -119,10 +119,13 @@ public:
|
|||||||
|
|
||||||
namespace hash_append_tests {
|
namespace hash_append_tests {
|
||||||
|
|
||||||
class fnv1a
|
template <std::size_t> class fnv1a_imp;
|
||||||
|
|
||||||
|
template <>
|
||||||
|
class fnv1a_imp<64>
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
std::size_t state_ = 14695981039346656037u;
|
std::uint64_t state_ = 14695981039346656037u;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void
|
void
|
||||||
@@ -141,6 +144,35 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template <>
|
||||||
|
class fnv1a_imp<32>
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
std::uint32_t state_ = 2166136261;
|
||||||
|
|
||||||
|
public:
|
||||||
|
void
|
||||||
|
append (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) * 16777619;
|
||||||
|
}
|
||||||
|
|
||||||
|
explicit
|
||||||
|
operator std::size_t() noexcept
|
||||||
|
{
|
||||||
|
return state_;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
class fnv1a
|
||||||
|
: public fnv1a_imp<CHAR_BIT*sizeof(std::size_t)>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
};
|
||||||
|
|
||||||
class jenkins1
|
class jenkins1
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -122,6 +122,15 @@ inline bool operator>= (URL const& lhs, URL const& rhs) { return ! (lhs.toString
|
|||||||
std::ostream& operator<< (std::ostream& os, URL const& url);
|
std::ostream& operator<< (std::ostream& os, URL const& url);
|
||||||
|
|
||||||
/** boost::hash support */
|
/** boost::hash support */
|
||||||
|
template <class Hasher>
|
||||||
|
inline
|
||||||
|
void
|
||||||
|
hash_append (Hasher& h, URL const& url)
|
||||||
|
{
|
||||||
|
using beast::hash_append;
|
||||||
|
hash_append (h, url.toString());
|
||||||
|
}
|
||||||
|
|
||||||
extern std::size_t hash_value (beast::URL const& url);
|
extern std::size_t hash_value (beast::URL const& url);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ private:
|
|||||||
class GroupsImp : public Groups
|
class GroupsImp : public Groups
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
typedef std::unordered_map <std::string, std::shared_ptr <Group>> Items;
|
typedef std::unordered_map <std::string, std::shared_ptr <Group>, uhash <>> Items;
|
||||||
|
|
||||||
Collector::ptr m_collector;
|
Collector::ptr m_collector;
|
||||||
Items m_items;
|
Items m_items;
|
||||||
|
|||||||
@@ -22,6 +22,7 @@
|
|||||||
|
|
||||||
#include "IPAddressV4.h"
|
#include "IPAddressV4.h"
|
||||||
#include "IPAddressV6.h"
|
#include "IPAddressV6.h"
|
||||||
|
#include "../container/hash_append.h"
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <ios>
|
#include <ios>
|
||||||
@@ -136,6 +137,18 @@ public:
|
|||||||
return m_v6;
|
return m_v6;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <class Hasher>
|
||||||
|
friend
|
||||||
|
void
|
||||||
|
hash_append(Hasher& h, Address const& addr)
|
||||||
|
{
|
||||||
|
using beast::hash_append;
|
||||||
|
if (addr.is_v4 ())
|
||||||
|
hash_append(h, addr.to_v4 ());
|
||||||
|
else
|
||||||
|
hash_append(h, addr.to_v6 ());
|
||||||
|
}
|
||||||
|
|
||||||
/** Arithmetic comparison. */
|
/** Arithmetic comparison. */
|
||||||
/** @{ */
|
/** @{ */
|
||||||
friend
|
friend
|
||||||
|
|||||||
@@ -20,6 +20,8 @@
|
|||||||
#ifndef BEAST_NET_IPADDRESSV4_H_INCLUDED
|
#ifndef BEAST_NET_IPADDRESSV4_H_INCLUDED
|
||||||
#define BEAST_NET_IPADDRESSV4_H_INCLUDED
|
#define BEAST_NET_IPADDRESSV4_H_INCLUDED
|
||||||
|
|
||||||
|
#include "../container/hash_append.h"
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <ios>
|
#include <ios>
|
||||||
#include <string>
|
#include <string>
|
||||||
@@ -178,6 +180,13 @@ OutputStream& operator<< (OutputStream& os, AddressV4 const& addr)
|
|||||||
std::istream& operator>> (std::istream& is, AddressV4& addr);
|
std::istream& operator>> (std::istream& is, AddressV4& addr);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <>
|
||||||
|
struct is_contiguously_hashable<IP::AddressV4>
|
||||||
|
: public std::integral_constant<bool, sizeof(IP::AddressV4) == sizeof(std::uint32_t)>
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -71,6 +71,13 @@ bool is_public (AddressV6 const& addr);
|
|||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
template <class Hasher>
|
||||||
|
void
|
||||||
|
hash_append(Hasher&, AddressV6 const&)
|
||||||
|
{
|
||||||
|
assert(false);
|
||||||
|
}
|
||||||
|
|
||||||
/** boost::hash support. */
|
/** boost::hash support. */
|
||||||
inline std::size_t hash_value (AddressV6 const&)
|
inline std::size_t hash_value (AddressV6 const&)
|
||||||
{ assert(false); return 0; }
|
{ assert(false); return 0; }
|
||||||
|
|||||||
@@ -21,6 +21,7 @@
|
|||||||
#define BEAST_NET_IPENDPOINT_H_INCLUDED
|
#define BEAST_NET_IPENDPOINT_H_INCLUDED
|
||||||
|
|
||||||
#include "IPAddress.h"
|
#include "IPAddress.h"
|
||||||
|
#include "../container/hash_append.h"
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <ios>
|
#include <ios>
|
||||||
@@ -91,6 +92,15 @@ public:
|
|||||||
{ return ! (rhs > lhs); }
|
{ return ! (rhs > lhs); }
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
||||||
|
template <class Hasher>
|
||||||
|
friend
|
||||||
|
void
|
||||||
|
hash_append (Hasher& h, Endpoint const& endpoint)
|
||||||
|
{
|
||||||
|
using beast::hash_append;
|
||||||
|
hash_append(h, endpoint.m_addr, endpoint.m_port);
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Address m_addr;
|
Address m_addr;
|
||||||
Port m_port;
|
Port m_port;
|
||||||
|
|||||||
@@ -1215,6 +1215,14 @@ public:
|
|||||||
String convertToPrecomposedUnicode() const;
|
String convertToPrecomposedUnicode() const;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
template <class Hasher>
|
||||||
|
friend
|
||||||
|
void
|
||||||
|
hash_append (Hasher& h, String const& s)
|
||||||
|
{
|
||||||
|
h.append(s.text.getAddress(), s.text.sizeInBytes());
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
//==============================================================================
|
//==============================================================================
|
||||||
struct FromNumber { };
|
struct FromNumber { };
|
||||||
|
|||||||
Reference in New Issue
Block a user