Warning, file /include/boost/intrusive/detail/hash_integral.hpp was not indexed
or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016 #ifndef BOOST_INTRUSIVE_DETAIL_HASH_INTEGRAL_HPP
0017 #define BOOST_INTRUSIVE_DETAIL_HASH_INTEGRAL_HPP
0018
0019 #include <boost/config.hpp>
0020 #include "hash_mix.hpp"
0021 #include <cstddef>
0022 #include <climits>
0023 #include <boost/intrusive/detail/mpl.hpp>
0024
0025 namespace boost {
0026 namespace intrusive {
0027 namespace detail {
0028
0029
0030 template<class T,
0031 bool bigger_than_size_t = (sizeof(T) > sizeof(std::size_t)),
0032 bool is_unsigned = is_unsigned<T>::value,
0033 std::size_t size_t_bits = sizeof(std::size_t) * CHAR_BIT,
0034 std::size_t type_bits = sizeof(T) * CHAR_BIT>
0035 struct hash_integral_impl;
0036
0037 template<class T, bool is_unsigned, std::size_t size_t_bits, std::size_t type_bits>
0038 struct hash_integral_impl<T, false, is_unsigned, size_t_bits, type_bits>
0039 {
0040 static std::size_t fn( T v )
0041 {
0042 return static_cast<std::size_t>( v );
0043 }
0044 };
0045
0046 template<class T, std::size_t size_t_bits, std::size_t type_bits>
0047 struct hash_integral_impl<T, true, false, size_t_bits, type_bits>
0048 {
0049 static std::size_t fn( T v )
0050 {
0051 typedef typename make_unsigned<T>::type U;
0052
0053 if( v >= 0 )
0054 {
0055 return hash_integral_impl<U>::fn( static_cast<U>( v ) );
0056 }
0057 else
0058 {
0059 return ~hash_integral_impl<U>::fn( static_cast<U>( ~static_cast<U>( v ) ) );
0060 }
0061 }
0062 };
0063
0064 template<class T>
0065 struct hash_integral_impl<T, true, true, 32, 64>
0066 {
0067 static std::size_t fn( T v )
0068 {
0069 std::size_t seed = 0;
0070
0071 seed = static_cast<std::size_t>( v >> 32 ) + (hash_mix)( seed );
0072 seed = static_cast<std::size_t>( v & 0xFFFFFFFF ) + (hash_mix)( seed );
0073
0074 return seed;
0075 }
0076 };
0077
0078 template<class T>
0079 struct hash_integral_impl<T, true, true, 32, 128>
0080 {
0081 static std::size_t fn( T v )
0082 {
0083 std::size_t seed = 0;
0084
0085 seed = static_cast<std::size_t>( v >> 96 ) + (hash_mix)( seed );
0086 seed = static_cast<std::size_t>( v >> 64 ) + (hash_mix)( seed );
0087 seed = static_cast<std::size_t>( v >> 32 ) + (hash_mix)( seed );
0088 seed = static_cast<std::size_t>( v ) + (hash_mix)( seed );
0089
0090 return seed;
0091 }
0092 };
0093
0094 template<class T>
0095 struct hash_integral_impl<T, true, true, 64, 128>
0096 {
0097 static std::size_t fn( T v )
0098 {
0099 std::size_t seed = 0;
0100
0101 seed = static_cast<std::size_t>( v >> 64 ) + (hash_mix)( seed );
0102 seed = static_cast<std::size_t>( v ) + (hash_mix)( seed );
0103
0104 return seed;
0105 }
0106 };
0107
0108 template <typename T>
0109 typename enable_if_c<is_integral<T>::value, std::size_t>::type
0110 hash_value( T v )
0111 {
0112 return hash_integral_impl<T>::fn( v );
0113 }
0114
0115 }
0116 }
0117 }
0118
0119 #endif