mirror of
https://github.com/bolero-MURAKAMI/Sprout.git
synced 2024-12-23 21:25:49 +00:00
fix hash implementation
This commit is contained in:
parent
0a5f16ee81
commit
4332b26a0e
22 changed files with 412 additions and 216 deletions
|
@ -3,8 +3,8 @@
|
|||
|
||||
#include <cstddef>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/functional/hash/hash.hpp>
|
||||
#include <sprout/array/array.hpp>
|
||||
#include <sprout/functional/hash.hpp>
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#include <cstddef>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/complex/complex.hpp>
|
||||
#include <sprout/functional/hash/hash.hpp>
|
||||
#include <sprout/functional/hash.hpp>
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
|
|
|
@ -2,6 +2,13 @@
|
|||
#define SPROUT_FUNCTIONAL_HASH_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/functional/hash/hash_fwd.hpp>
|
||||
#include <sprout/functional/hash/hash_value.hpp>
|
||||
#include <sprout/functional/hash/to_hash.hpp>
|
||||
#include <sprout/functional/hash/hash.hpp>
|
||||
#include <sprout/functional/hash/hash_combine.hpp>
|
||||
#include <sprout/functional/hash/hash_range.hpp>
|
||||
#include <sprout/functional/hash/hash_values_combine.hpp>
|
||||
#include <sprout/functional/hash/hash_values.hpp>
|
||||
|
||||
#endif // #ifndef SPROUT_FUNCTIONAL_HASH_HPP
|
||||
|
|
|
@ -2,212 +2,11 @@
|
|||
#define SPROUT_FUNCTIONAL_HASH_HASH_HPP
|
||||
|
||||
#include <cstddef>
|
||||
#include <limits>
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/functional/hash/hash_fwd.hpp>
|
||||
#include <sprout/iterator/operation.hpp>
|
||||
#include <sprout/type_traits/enabler_if.hpp>
|
||||
#include <sprout/functional/hash/to_hash.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace hash_detail {
|
||||
template <typename T>
|
||||
struct is_basic_number
|
||||
: public std::integral_constant<
|
||||
bool,
|
||||
std::is_integral<T>::value
|
||||
&& (sizeof(T) <= sizeof(std::size_t))
|
||||
>
|
||||
{};
|
||||
template <typename T>
|
||||
struct is_long_number
|
||||
: public std::integral_constant<
|
||||
bool,
|
||||
std::is_integral<T>::value
|
||||
&& (sizeof(T) > sizeof(std::size_t))
|
||||
&& std::is_signed<T>::value
|
||||
>
|
||||
{};
|
||||
template <typename T>
|
||||
struct is_ulong_number
|
||||
: public std::integral_constant<
|
||||
bool,
|
||||
std::is_integral<T>::value
|
||||
&& (sizeof(T) > sizeof(std::size_t))
|
||||
&& std::is_unsigned<T>::value
|
||||
>
|
||||
{};
|
||||
|
||||
template<typename T>
|
||||
inline SPROUT_CONSTEXPR std::size_t
|
||||
hash_value_signed_2(T val, int length, std::size_t seed, T positive, std::size_t i) {
|
||||
return i > 0
|
||||
? hash_value_signed_2(
|
||||
val,
|
||||
length,
|
||||
seed ^ static_cast<std::size_t>((positive >> i) + (seed << 6) + (seed >> 2)),
|
||||
positive,
|
||||
i - std::numeric_limits<std::size_t>::digits
|
||||
)
|
||||
: seed ^ static_cast<std::size_t>(val + (seed << 6) + (seed >> 2))
|
||||
;
|
||||
}
|
||||
template<typename T>
|
||||
inline SPROUT_CONSTEXPR std::size_t
|
||||
hash_value_signed_1(T val, int length, std::size_t seed, T positive) {
|
||||
return hash_value_signed_2(val, length, seed, positive, length * std::numeric_limits<std::size_t>::digits);
|
||||
}
|
||||
template<typename T>
|
||||
inline SPROUT_CONSTEXPR std::size_t
|
||||
hash_value_signed(T val) {
|
||||
return sprout::hash_detail::hash_value_signed_1(
|
||||
val,
|
||||
(std::numeric_limits<T>::digits - 1) / std::numeric_limits<std::size_t>::digits,
|
||||
0,
|
||||
val < 0 ? -1 - val : val
|
||||
);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline SPROUT_CONSTEXPR std::size_t
|
||||
hash_value_unsigned_2(T val, int length, std::size_t seed, std::size_t i) {
|
||||
return i > 0
|
||||
? hash_value_unsigned_2(
|
||||
val,
|
||||
length,
|
||||
seed ^ static_cast<std::size_t>((val >> i) + (seed << 6) + (seed >> 2)),
|
||||
i - std::numeric_limits<std::size_t>::digits
|
||||
)
|
||||
: seed ^ static_cast<std::size_t>(val + (seed << 6) + (seed >> 2))
|
||||
;
|
||||
}
|
||||
template<typename T>
|
||||
inline SPROUT_CONSTEXPR std::size_t
|
||||
hash_value_unsigned_1(T val, int length, std::size_t seed) {
|
||||
return hash_value_unsigned_2(val, length, seed, length * std::numeric_limits<std::size_t>::digits);
|
||||
}
|
||||
template<typename T>
|
||||
inline SPROUT_CONSTEXPR std::size_t
|
||||
hash_value_unsigned(T val) {
|
||||
return sprout::hash_detail::hash_value_unsigned_1(
|
||||
val,
|
||||
(std::numeric_limits<T>::digits - 1) / std::numeric_limits<std::size_t>::digits,
|
||||
0
|
||||
);
|
||||
}
|
||||
|
||||
inline std::size_t
|
||||
hash_value_pointer_1(std::size_t x) {
|
||||
return x + (x >> 3);
|
||||
}
|
||||
template<typename T>
|
||||
std::size_t
|
||||
hash_value_pointer(T const* v) {
|
||||
return sprout::hash_detail::hash_value_pointer_1(static_cast<std::size_t>(reinterpret_cast<std::ptrdiff_t>(v)));
|
||||
}
|
||||
} // namespace hash_detail
|
||||
|
||||
//
|
||||
// hash_value
|
||||
//
|
||||
template<typename T>
|
||||
inline SPROUT_CONSTEXPR typename std::enable_if<sprout::hash_detail::is_basic_number<T>::value, std::size_t>::type
|
||||
hash_value(T v) {
|
||||
return static_cast<std::size_t>(v);
|
||||
}
|
||||
template<typename T>
|
||||
inline SPROUT_CONSTEXPR typename std::enable_if<sprout::hash_detail::is_long_number<T>::value, std::size_t>::type
|
||||
hash_value(T v) {
|
||||
return sprout::hash_detail::hash_value_signed(v);
|
||||
}
|
||||
template<typename T>
|
||||
inline SPROUT_CONSTEXPR typename std::enable_if<sprout::hash_detail::is_ulong_number<T>::value, std::size_t>::type
|
||||
hash_value(T v) {
|
||||
return sprout::hash_detail::hash_value_unsigned(v);
|
||||
}
|
||||
template<typename T>
|
||||
inline SPROUT_CONSTEXPR typename std::enable_if<std::is_enum<T>::value, std::size_t>::type
|
||||
hash_value(T v) {
|
||||
return sprout::hash_value(static_cast<typename std::underlying_type<T>::type>(v));
|
||||
}
|
||||
template<typename T>
|
||||
inline SPROUT_CONSTEXPR typename std::enable_if<std::is_pointer<typename std::remove_reference<T>::type>::value, std::size_t>::type
|
||||
hash_value(T&& v) {
|
||||
return sprout::hash_detail::hash_value_pointer(v);
|
||||
}
|
||||
template<typename T, std::size_t N>
|
||||
inline SPROUT_CONSTEXPR std::size_t
|
||||
hash_value(T const (&v)[N]) {
|
||||
return sprout::hash_range(&v[0], &v[0] + N);
|
||||
}
|
||||
|
||||
//
|
||||
// to_hash
|
||||
//
|
||||
template<typename T>
|
||||
inline SPROUT_CONSTEXPR std::size_t
|
||||
to_hash(T const& v) {
|
||||
using sprout::hash_value;
|
||||
return hash_value(v);
|
||||
}
|
||||
|
||||
//
|
||||
// hash_combine
|
||||
//
|
||||
template<typename T>
|
||||
inline SPROUT_CONSTEXPR std::size_t
|
||||
hash_combine(std::size_t seed, T const& v) {
|
||||
return seed ^ (sprout::to_hash(v) + 0x9e3779b9 + (seed << 6) + (seed >> 2));
|
||||
}
|
||||
|
||||
//
|
||||
// hash_range
|
||||
//
|
||||
template<typename Iterator>
|
||||
inline SPROUT_CONSTEXPR std::size_t
|
||||
hash_range(std::size_t seed, Iterator first, Iterator last) {
|
||||
return first != last
|
||||
? sprout::hash_range(sprout::hash_combine(seed, *first), sprout::next(first), last)
|
||||
: seed
|
||||
;
|
||||
}
|
||||
template<typename Iterator>
|
||||
inline SPROUT_CONSTEXPR std::size_t
|
||||
hash_range(Iterator first, Iterator last) {
|
||||
return sprout::hash_range(0, first, last);
|
||||
}
|
||||
|
||||
namespace detail {
|
||||
template<typename T>
|
||||
inline SPROUT_CONSTEXPR std::size_t
|
||||
hash_values_combine_impl(std::size_t seed, T const& v) {
|
||||
return sprout::hash_combine(seed, v);
|
||||
}
|
||||
template<typename Head, typename... Tail>
|
||||
inline SPROUT_CONSTEXPR std::size_t
|
||||
hash_values_combine_impl(std::size_t seed, Head const& head, Tail const&... tail) {
|
||||
return sprout::detail::hash_values_combine_impl(sprout::hash_combine(seed, head), tail...);
|
||||
}
|
||||
} // namespace detail
|
||||
|
||||
//
|
||||
// hash_values_combine
|
||||
//
|
||||
template<typename... Args>
|
||||
inline SPROUT_CONSTEXPR std::size_t
|
||||
hash_values_combine(std::size_t seed, Args const&... args) {
|
||||
return sprout::detail::hash_values_combine_impl(seed, args...);
|
||||
}
|
||||
|
||||
//
|
||||
// hash_values
|
||||
//
|
||||
template<typename... Args>
|
||||
inline SPROUT_CONSTEXPR std::size_t
|
||||
hash_values(Args const&... args) {
|
||||
return sprout::hash_values_combine(0, args...);
|
||||
}
|
||||
|
||||
//
|
||||
// hash
|
||||
//
|
||||
|
|
20
sprout/functional/hash/hash_combine.hpp
Normal file
20
sprout/functional/hash/hash_combine.hpp
Normal file
|
@ -0,0 +1,20 @@
|
|||
#ifndef SPROUT_FUNCTIONAL_HASH_HASH_COMBINE_HPP
|
||||
#define SPROUT_FUNCTIONAL_HASH_HASH_COMBINE_HPP
|
||||
|
||||
#include <cstddef>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/functional/hash/hash_fwd.hpp>
|
||||
#include <sprout/functional/hash/to_hash.hpp>
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
// hash_combine
|
||||
//
|
||||
template<typename T>
|
||||
inline SPROUT_CONSTEXPR std::size_t
|
||||
hash_combine(std::size_t seed, T const& v) {
|
||||
return seed ^ (sprout::to_hash(v) + 0x9e3779b9 + (seed << 6) + (seed >> 2));
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_FUNCTIONAL_HASH_HASH_COMBINE_HPP
|
29
sprout/functional/hash/hash_range.hpp
Normal file
29
sprout/functional/hash/hash_range.hpp
Normal file
|
@ -0,0 +1,29 @@
|
|||
#ifndef SPROUT_FUNCTIONAL_HASH_HASH_RANGE_HPP
|
||||
#define SPROUT_FUNCTIONAL_HASH_HASH_RANGE_HPP
|
||||
|
||||
#include <cstddef>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/functional/hash/hash_fwd.hpp>
|
||||
#include <sprout/functional/hash/hash_combine.hpp>
|
||||
#include <sprout/iterator/next.hpp>
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
// hash_range
|
||||
//
|
||||
template<typename InputIterator>
|
||||
inline SPROUT_CONSTEXPR std::size_t
|
||||
hash_range(std::size_t seed, InputIterator first, InputIterator last) {
|
||||
return first != last
|
||||
? sprout::hash_range(sprout::hash_combine(seed, *first), sprout::next(first), last)
|
||||
: seed
|
||||
;
|
||||
}
|
||||
template<typename InputIterator>
|
||||
inline SPROUT_CONSTEXPR std::size_t
|
||||
hash_range(InputIterator first, InputIterator last) {
|
||||
return sprout::hash_range(0, first, last);
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_FUNCTIONAL_HASH_HASH_RANGE_HPP
|
143
sprout/functional/hash/hash_value.hpp
Normal file
143
sprout/functional/hash/hash_value.hpp
Normal file
|
@ -0,0 +1,143 @@
|
|||
#ifndef SPROUT_FUNCTIONAL_HASH_HASH_VALUE_HPP
|
||||
#define SPROUT_FUNCTIONAL_HASH_HASH_VALUE_HPP
|
||||
|
||||
#include <cstddef>
|
||||
#include <limits>
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/functional/hash/hash_fwd.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace hash_detail {
|
||||
template <typename T>
|
||||
struct is_basic_number
|
||||
: public std::integral_constant<
|
||||
bool,
|
||||
std::is_integral<T>::value
|
||||
&& (sizeof(T) <= sizeof(std::size_t))
|
||||
>
|
||||
{};
|
||||
template <typename T>
|
||||
struct is_long_number
|
||||
: public std::integral_constant<
|
||||
bool,
|
||||
std::is_integral<T>::value
|
||||
&& (sizeof(T) > sizeof(std::size_t))
|
||||
&& std::is_signed<T>::value
|
||||
>
|
||||
{};
|
||||
template <typename T>
|
||||
struct is_ulong_number
|
||||
: public std::integral_constant<
|
||||
bool,
|
||||
std::is_integral<T>::value
|
||||
&& (sizeof(T) > sizeof(std::size_t))
|
||||
&& std::is_unsigned<T>::value
|
||||
>
|
||||
{};
|
||||
|
||||
template<typename T>
|
||||
inline SPROUT_CONSTEXPR std::size_t
|
||||
hash_value_signed_2(T val, int length, std::size_t seed, T positive, std::size_t i) {
|
||||
return i > 0
|
||||
? hash_value_signed_2(
|
||||
val,
|
||||
length,
|
||||
seed ^ static_cast<std::size_t>((positive >> i) + (seed << 6) + (seed >> 2)),
|
||||
positive,
|
||||
i - std::numeric_limits<std::size_t>::digits
|
||||
)
|
||||
: seed ^ static_cast<std::size_t>(val + (seed << 6) + (seed >> 2))
|
||||
;
|
||||
}
|
||||
template<typename T>
|
||||
inline SPROUT_CONSTEXPR std::size_t
|
||||
hash_value_signed_1(T val, int length, std::size_t seed, T positive) {
|
||||
return hash_value_signed_2(val, length, seed, positive, length * std::numeric_limits<std::size_t>::digits);
|
||||
}
|
||||
template<typename T>
|
||||
inline SPROUT_CONSTEXPR std::size_t
|
||||
hash_value_signed(T val) {
|
||||
return sprout::hash_detail::hash_value_signed_1(
|
||||
val,
|
||||
(std::numeric_limits<T>::digits - 1) / std::numeric_limits<std::size_t>::digits,
|
||||
0,
|
||||
val < 0 ? -1 - val : val
|
||||
);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline SPROUT_CONSTEXPR std::size_t
|
||||
hash_value_unsigned_2(T val, int length, std::size_t seed, std::size_t i) {
|
||||
return i > 0
|
||||
? hash_value_unsigned_2(
|
||||
val,
|
||||
length,
|
||||
seed ^ static_cast<std::size_t>((val >> i) + (seed << 6) + (seed >> 2)),
|
||||
i - std::numeric_limits<std::size_t>::digits
|
||||
)
|
||||
: seed ^ static_cast<std::size_t>(val + (seed << 6) + (seed >> 2))
|
||||
;
|
||||
}
|
||||
template<typename T>
|
||||
inline SPROUT_CONSTEXPR std::size_t
|
||||
hash_value_unsigned_1(T val, int length, std::size_t seed) {
|
||||
return hash_value_unsigned_2(val, length, seed, length * std::numeric_limits<std::size_t>::digits);
|
||||
}
|
||||
template<typename T>
|
||||
inline SPROUT_CONSTEXPR std::size_t
|
||||
hash_value_unsigned(T val) {
|
||||
return sprout::hash_detail::hash_value_unsigned_1(
|
||||
val,
|
||||
(std::numeric_limits<T>::digits - 1) / std::numeric_limits<std::size_t>::digits,
|
||||
0
|
||||
);
|
||||
}
|
||||
|
||||
inline std::size_t
|
||||
hash_value_pointer_1(std::size_t x) {
|
||||
return x + (x >> 3);
|
||||
}
|
||||
template<typename T>
|
||||
std::size_t
|
||||
hash_value_pointer(T const* v) {
|
||||
return sprout::hash_detail::hash_value_pointer_1(static_cast<std::size_t>(reinterpret_cast<std::ptrdiff_t>(v)));
|
||||
}
|
||||
} // namespace hash_detail
|
||||
|
||||
//
|
||||
// hash_value
|
||||
//
|
||||
template<typename T>
|
||||
inline SPROUT_CONSTEXPR typename std::enable_if<sprout::hash_detail::is_basic_number<T>::value, std::size_t>::type
|
||||
hash_value(T v) {
|
||||
return static_cast<std::size_t>(v);
|
||||
}
|
||||
template<typename T>
|
||||
inline SPROUT_CONSTEXPR typename std::enable_if<sprout::hash_detail::is_long_number<T>::value, std::size_t>::type
|
||||
hash_value(T v) {
|
||||
return sprout::hash_detail::hash_value_signed(v);
|
||||
}
|
||||
template<typename T>
|
||||
inline SPROUT_CONSTEXPR typename std::enable_if<sprout::hash_detail::is_ulong_number<T>::value, std::size_t>::type
|
||||
hash_value(T v) {
|
||||
return sprout::hash_detail::hash_value_unsigned(v);
|
||||
}
|
||||
template<typename T>
|
||||
inline SPROUT_CONSTEXPR typename std::enable_if<std::is_enum<T>::value, std::size_t>::type
|
||||
hash_value(T v) {
|
||||
return sprout::hash_value(static_cast<typename std::underlying_type<T>::type>(v));
|
||||
}
|
||||
template<typename T>
|
||||
inline SPROUT_CONSTEXPR typename std::enable_if<std::is_pointer<typename std::remove_reference<T>::type>::value, std::size_t>::type
|
||||
hash_value(T&& v) {
|
||||
return sprout::hash_detail::hash_value_pointer(v);
|
||||
}
|
||||
template<typename T, std::size_t N>
|
||||
inline SPROUT_CONSTEXPR std::size_t
|
||||
hash_value(T const (&v)[N]) {
|
||||
return sprout::hash_range(&v[0], &v[0] + N);
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_FUNCTIONAL_HASH_HASH_VALUE_HPP
|
20
sprout/functional/hash/hash_values.hpp
Normal file
20
sprout/functional/hash/hash_values.hpp
Normal file
|
@ -0,0 +1,20 @@
|
|||
#ifndef SPROUT_FUNCTIONAL_HASH_HASH_VALUES_HPP
|
||||
#define SPROUT_FUNCTIONAL_HASH_HASH_VALUES_HPP
|
||||
|
||||
#include <cstddef>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/functional/hash/hash_fwd.hpp>
|
||||
#include <sprout/functional/hash/hash_values_combine.hpp>
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
// hash_values
|
||||
//
|
||||
template<typename... Args>
|
||||
inline SPROUT_CONSTEXPR std::size_t
|
||||
hash_values(Args const&... args) {
|
||||
return sprout::hash_values_combine(0, args...);
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_FUNCTIONAL_HASH_HASH_VALUES_HPP
|
33
sprout/functional/hash/hash_values_combine.hpp
Normal file
33
sprout/functional/hash/hash_values_combine.hpp
Normal file
|
@ -0,0 +1,33 @@
|
|||
#ifndef SPROUT_FUNCTIONAL_HASH_HASH_VALUES_COMBINE_HPP
|
||||
#define SPROUT_FUNCTIONAL_HASH_HASH_VALUES_COMBINE_HPP
|
||||
|
||||
#include <cstddef>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/functional/hash/hash_fwd.hpp>
|
||||
#include <sprout/functional/hash/hash_combine.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace detail {
|
||||
template<typename T>
|
||||
inline SPROUT_CONSTEXPR std::size_t
|
||||
hash_values_combine_impl(std::size_t seed, T const& v) {
|
||||
return sprout::hash_combine(seed, v);
|
||||
}
|
||||
template<typename Head, typename... Tail>
|
||||
inline SPROUT_CONSTEXPR std::size_t
|
||||
hash_values_combine_impl(std::size_t seed, Head const& head, Tail const&... tail) {
|
||||
return sprout::detail::hash_values_combine_impl(sprout::hash_combine(seed, head), tail...);
|
||||
}
|
||||
} // namespace detail
|
||||
|
||||
//
|
||||
// hash_values_combine
|
||||
//
|
||||
template<typename... Args>
|
||||
inline SPROUT_CONSTEXPR std::size_t
|
||||
hash_values_combine(std::size_t seed, Args const&... args) {
|
||||
return sprout::detail::hash_values_combine_impl(seed, args...);
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_FUNCTIONAL_HASH_HASH_VALUES_COMBINE_HPP
|
|
@ -13,7 +13,7 @@ namespace sprout {
|
|||
template<typename T1, typename T2>
|
||||
inline SPROUT_CONSTEXPR std::size_t
|
||||
hash_value(sscrisk::cel::pair<T1, T2> const& v) {
|
||||
return sprout::hash_combine(sprout::hash_combine(0, v.first), v.second);
|
||||
return sprout::hash_values(v.first, v.second);
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
|
|
145
sprout/functional/hash/to_hash.hpp
Normal file
145
sprout/functional/hash/to_hash.hpp
Normal file
|
@ -0,0 +1,145 @@
|
|||
#ifndef SPROUT_FUNCTIONAL_HASH_TO_HASH_HPP
|
||||
#define SPROUT_FUNCTIONAL_HASH_TO_HASH_HPP
|
||||
|
||||
#include <cstddef>
|
||||
#include <utility>
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/functional/hash/hash_fwd.hpp>
|
||||
#include <sprout/functional/hash/hash_value.hpp>
|
||||
#include <sprout/utility/forward.hpp>
|
||||
#include <sprout/type_traits/enabler_if.hpp>
|
||||
#include <sprout/adl/not_found.hpp>
|
||||
|
||||
namespace sprout_adl {
|
||||
sprout::not_found_via_adl hash_value(...);
|
||||
} // namespace sprout_adl
|
||||
|
||||
namespace sprout_hash_detail {
|
||||
using sprout::hash_value;
|
||||
using sprout_adl::hash_value;
|
||||
|
||||
template<typename T>
|
||||
struct has_adl_hash_value_test {
|
||||
public:
|
||||
template<
|
||||
typename U = T,
|
||||
typename sprout::enabler_if<
|
||||
sprout::is_found_via_adl<decltype(hash_value(std::declval<U>()))>::value
|
||||
>::type = sprout::enabler
|
||||
>
|
||||
static std::true_type test(int);
|
||||
static std::false_type test(...);
|
||||
};
|
||||
#if defined(_MSC_VER)
|
||||
template<typename T, typename Base_ = decltype(sprout_hash_detail::has_adl_hash_value_test<T>::test(0))>
|
||||
struct has_adl_hash_value
|
||||
: public Base_
|
||||
{};
|
||||
#else
|
||||
template<typename T>
|
||||
struct has_adl_hash_value
|
||||
: public decltype(sprout_hash_detail::has_adl_hash_value_test<T>::test(0))
|
||||
{};
|
||||
#endif
|
||||
|
||||
template<typename T, typename Enable = void>
|
||||
struct select_adl_hash_value;
|
||||
template<typename T>
|
||||
struct select_adl_hash_value<
|
||||
T,
|
||||
typename std::enable_if<
|
||||
sprout_hash_detail::has_adl_hash_value<T>::value
|
||||
>::type
|
||||
>
|
||||
: public std::true_type
|
||||
{};
|
||||
template<typename T>
|
||||
struct select_adl_hash_value<
|
||||
T,
|
||||
typename std::enable_if<!(
|
||||
sprout_hash_detail::has_adl_hash_value<T>::value
|
||||
)>::type
|
||||
>
|
||||
: public std::false_type
|
||||
{};
|
||||
|
||||
template<typename T, typename Enable = void>
|
||||
struct select_std_hash;
|
||||
template<typename T>
|
||||
struct select_std_hash<
|
||||
T,
|
||||
typename std::enable_if<
|
||||
!sprout_hash_detail::has_adl_hash_value<T>::value
|
||||
>::type
|
||||
>
|
||||
: public std::true_type
|
||||
{};
|
||||
template<typename T>
|
||||
struct select_std_hash<
|
||||
T,
|
||||
typename std::enable_if<!(
|
||||
!sprout_hash_detail::has_adl_hash_value<T>::value
|
||||
)>::type
|
||||
>
|
||||
: public std::false_type
|
||||
{};
|
||||
|
||||
template<typename T, typename = void>
|
||||
struct noexcept_to_hash;
|
||||
template<typename T>
|
||||
struct noexcept_to_hash<T, typename std::enable_if<sprout_hash_detail::select_adl_hash_value<T>::value>::type>
|
||||
: public std::integral_constant<bool, SPROUT_NOEXCEPT_EXPR_OR_DEFAULT(hash_value(std::declval<T>()), false)>
|
||||
{};
|
||||
template<typename T>
|
||||
struct noexcept_to_hash<T, typename std::enable_if<sprout_hash_detail::select_std_hash<T>::value>::type>
|
||||
: public std::integral_constant<bool, SPROUT_NOEXCEPT_EXPR_OR_DEFAULT(std::hash<typename std::decay<T>::type>()(std::declval<T>()), false)>
|
||||
{};
|
||||
|
||||
template<typename T, typename = void>
|
||||
struct to_hash_result;
|
||||
template<typename T>
|
||||
struct to_hash_result<T, typename std::enable_if<sprout_hash_detail::select_adl_hash_value<T>::value>::type> {
|
||||
public:
|
||||
typedef decltype(hash_value(std::declval<T>())) type;
|
||||
};
|
||||
template<typename T>
|
||||
struct to_hash_result<T, typename std::enable_if<sprout_hash_detail::select_std_hash<T>::value>::type> {
|
||||
public:
|
||||
typedef decltype(std::hash<typename std::decay<T>::type>()(std::declval<T>())) type;
|
||||
};
|
||||
|
||||
template<
|
||||
typename T,
|
||||
typename sprout::enabler_if<sprout_hash_detail::select_adl_hash_value<T>::value>::type = sprout::enabler
|
||||
>
|
||||
inline SPROUT_CONSTEXPR typename sprout_hash_detail::to_hash_result<T>::type
|
||||
to_hash_impl(T&& t)
|
||||
SPROUT_NOEXCEPT_EXPR((sprout_hash_detail::noexcept_to_hash<T>::value))
|
||||
{
|
||||
return hash_value(sprout::forward<T>(t));
|
||||
}
|
||||
template<
|
||||
typename T,
|
||||
typename sprout::enabler_if<sprout_hash_detail::select_std_hash<T>::value>::type = sprout::enabler
|
||||
>
|
||||
inline SPROUT_CONSTEXPR typename sprout_hash_detail::to_hash_result<T>::type
|
||||
to_hash_impl(T&& t)
|
||||
SPROUT_NOEXCEPT_EXPR((sprout_hash_detail::noexcept_to_hash<T>::value))
|
||||
{
|
||||
return std::hash<typename std::decay<T>::type>()(sprout::forward<T>(t));
|
||||
}
|
||||
} // namespace sprout_hash_detail
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
// to_hash
|
||||
//
|
||||
template<typename T>
|
||||
inline SPROUT_CONSTEXPR std::size_t
|
||||
to_hash(T const& v) {
|
||||
return sprout_hash_detail::to_hash_impl(v);
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_FUNCTIONAL_HASH_TO_HASH_HPP
|
|
@ -3,8 +3,8 @@
|
|||
|
||||
#include <cstddef>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/functional/hash/hash.hpp>
|
||||
#include <sprout/logic/tribool/tribool.hpp>
|
||||
#include <sprout/functional/hash.hpp>
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
|
|
|
@ -3,8 +3,8 @@
|
|||
|
||||
#include <cstddef>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/functional/hash/hash.hpp>
|
||||
#include <sprout/optional/optional.hpp>
|
||||
#include <sprout/functional/hash.hpp>
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
|
|
|
@ -3,8 +3,8 @@
|
|||
|
||||
#include <cstddef>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/functional/hash/hash.hpp>
|
||||
#include <sprout/pit/pit.hpp>
|
||||
#include <sprout/functional/hash.hpp>
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#include <cstddef>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/rational/rational.hpp>
|
||||
#include <sprout/functional/hash/hash.hpp>
|
||||
#include <sprout/functional/hash.hpp>
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#include <cstddef>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/string/string.hpp>
|
||||
#include <sprout/functional/hash/hash.hpp>
|
||||
#include <sprout/functional/hash.hpp>
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
#define SPROUT_SUB_ARRAY_HASH_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/functional/hash/hash.hpp>
|
||||
#include <sprout/sub_array/sub_array.hpp>
|
||||
#include <sprout/functional/hash.hpp>
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#include <cstddef>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/index_tuple.hpp>
|
||||
#include <sprout/functional/hash/hash.hpp>
|
||||
#include <sprout/functional/hash.hpp>
|
||||
#include <sprout/tuple/tuple/tuple.hpp>
|
||||
#include <sprout/tuple/tuple/get.hpp>
|
||||
|
||||
|
|
|
@ -3,8 +3,8 @@
|
|||
|
||||
#include <cstddef>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/functional/hash/hash.hpp>
|
||||
#include <sprout/utility/pair/pair.hpp>
|
||||
#include <sprout/functional/hash.hpp>
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
|
|
|
@ -3,8 +3,8 @@
|
|||
|
||||
#include <cstddef>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/functional/hash/hash.hpp>
|
||||
#include <sprout/utility/value_holder/value_holder.hpp>
|
||||
#include <sprout/functional/hash.hpp>
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
|
|
|
@ -3,8 +3,8 @@
|
|||
|
||||
#include <cstddef>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/functional/hash/hash.hpp>
|
||||
#include <sprout/uuid/uuid.hpp>
|
||||
#include <sprout/functional/hash.hpp>
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
#include <cstddef>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/functional/hash/hash.hpp>
|
||||
#include <sprout/functional/hash.hpp>
|
||||
#include <sprout/variant/variant.hpp>
|
||||
#include <sprout/variant/static_visitor.hpp>
|
||||
#include <sprout/variant/apply_visitor.hpp>
|
||||
|
|
Loading…
Reference in a new issue