21 #include <boost/cstdint.hpp>
22 #include <boost/static_assert.hpp>
47 static constexpr int m = 0x5bd1e995;
48 static constexpr int r = 24;
61 BOOST_STATIC_ASSERT(
sizeof(
int) == 4);
66 unsigned char const *data=
reinterpret_cast<
unsigned char const *>(&*d.begin());
67 for (;len >= 4; len -= 4) {
68 unsigned int k=*
reinterpret_cast<
unsigned int const *>(data);
79 #pragma GCC diagnostic push
80 #pragma GCC diagnostic ignored "-Wimplicit-fallthrough"
93 #pragma GCC diagnostic pop
117 typedef int16_t hashed_unit_t;
119 static constexpr hashed_unit_t
__fastcall FORCE_INLINE get16bits(
typename argument_type::const_iterator d)
noexcept(
true) {
120 return *
reinterpret_cast<hashed_unit_t
const *>(&*d);
132 const unsigned short rem=
static_cast<
unsigned short>(len & 3);
133 unsigned long hash=
static_cast<
unsigned long>(len);
138 for (;len > 0; --len) {
139 hash += get16bits(data);
140 typename argument_type::const_iterator it(
std::next(data,
sizeof(hashed_unit_t)));
141 const unsigned long tmp = (get16bits(it) << 11) ^ hash;
142 hash = (hash << 16) ^ tmp;
143 std::advance(data, 2*
sizeof(hashed_unit_t));
150 hash += get16bits(data);
152 hash ^= data[
sizeof(hashed_unit_t)] << 18;
156 hash += get16bits(data);
192 template<
unsigned long len,
class C>
195 struct core_hash<0,C> {
196 static constexpr unsigned long FORCE_INLINE result(
typename C::const_iterator&,
unsigned long hash)
noexcept(
true) {
201 template<
unsigned long len,
class C>
203 static unsigned long FORCE_INLINE result(
typename C::const_iterator &data,
unsigned long hash)
noexcept(
true) {
204 hash += get16bits(data);
206 const unsigned long tmp = (get16bits(it) << 11) ^ hash;
207 hash = (hash << 16) ^ tmp;
209 return core_hash<len-1,C>::result(data, hash + (hash >> 11));
213 template<
unsigned long rem,
class C>
216 struct end_cases<3,C> {
217 static constexpr unsigned long FORCE_INLINE result(
const typename C::const_iterator data,
unsigned long hash)
noexcept(
true) {
218 hash += get16bits(data);
221 return hash + (hash >> 11);
225 struct end_cases<2,C> {
226 static constexpr unsigned long result(
const typename C::const_iterator data,
unsigned long hash)
noexcept(
true) {
227 hash += get16bits(data);
229 return hash + (hash >> 17);
233 struct end_cases<1,C> {
234 static constexpr unsigned long FORCE_INLINE result(
const typename C::const_iterator data,
unsigned long hash)
noexcept(
true) {
237 return hash + (hash >> 1);
241 struct end_cases<0,C> {
242 static constexpr unsigned long FORCE_INLINE result(
const typename C::const_iterator,
unsigned long hash)
noexcept(
true) {
266 static constexpr unsigned long rem=
length&3;
276 assert(d.size()>=length);
286 return static_cast<
result_type>(hash + (hash >> 6));