Files
boost_beast/beast/crypto/MurmurHash.h
T

85 lines
2.5 KiB
C++
Raw Normal View History

2013-06-17 09:28:43 -07:00
//------------------------------------------------------------------------------
2013-06-17 06:42:49 -07:00
/*
2013-06-17 09:28:43 -07:00
This file is part of Beast: https://github.com/vinniefalco/Beast
Copyright 2013, Vinnie Falco <vinnie.falco@gmail.com>
2013-06-17 06:42:49 -07:00
2013-06-17 09:28:43 -07:00
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
2013-06-17 06:42:49 -07:00
2013-06-17 09:28:43 -07:00
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
2013-06-17 06:42:49 -07:00
*/
2013-06-17 09:28:43 -07:00
//==============================================================================
2013-06-17 06:42:49 -07:00
2013-10-25 15:36:07 -07:00
#ifndef BEAST_CRYPTO_MURMURHASH_H_INCLUDED
#define BEAST_CRYPTO_MURMURHASH_H_INCLUDED
2014-03-22 09:43:11 -07:00
#include <cstdint>
#include <stdexcept>
2013-06-17 06:42:49 -07:00
// Original source code links in .cpp file
2013-10-25 15:36:07 -07:00
namespace beast {
namespace Murmur {
2013-06-17 06:42:49 -07:00
2014-03-22 09:43:11 -07:00
extern void MurmurHash3_x86_32 (const void* key, int len, std::uint32_t seed, void* out);
extern void MurmurHash3_x86_128 (const void* key, int len, std::uint32_t seed, void* out);
extern void MurmurHash3_x64_128 (const void* key, int len, std::uint32_t seed, void* out);
2013-06-17 06:42:49 -07:00
2013-06-29 13:02:41 -07:00
// Uses Beast to choose an appropriate routine
2013-06-17 06:42:49 -07:00
// This handy template deduces which size hash is desired
template <typename HashType>
2014-03-22 09:43:11 -07:00
inline void Hash (const void* key, int len, std::uint32_t seed, HashType* out)
2013-06-17 06:42:49 -07:00
{
switch (8 * sizeof (HashType))
{
case 32:
MurmurHash3_x86_32 (key, len, seed, out);
break;
#if BEAST_64BIT
2013-10-01 12:00:03 -07:00
case 64:
{
HashType tmp[2];
MurmurHash3_x64_128 (key, len, seed, &tmp[0]);
*out = tmp[0];
}
break;
2013-06-17 06:42:49 -07:00
case 128:
MurmurHash3_x64_128 (key, len, seed, out);
break;
2013-06-29 13:02:41 -07:00
#else
2013-10-01 12:00:03 -07:00
case 64:
{
HashType tmp[2];
MurmurHash3_x86_128 (key, len, seed, &tmp[0]);
*out = tmp[0];
}
break;
2013-06-17 06:42:49 -07:00
case 128:
MurmurHash3_x86_128 (key, len, seed, out);
break;
2013-06-29 13:02:41 -07:00
2013-06-17 06:42:49 -07:00
#endif
default:
2014-03-22 09:43:11 -07:00
throw std::runtime_error ("invalid key size in MurmurHash");
2013-06-17 06:42:49 -07:00
break;
};
}
2013-10-25 15:36:07 -07:00
}
2013-06-17 06:42:49 -07:00
}
#endif