Move MurmurHash to beast

This commit is contained in:
Vinnie Falco
2013-10-25 15:36:07 -07:00
parent 31089931d3
commit dc591f8943
11 changed files with 63 additions and 38 deletions

View File

@@ -111,6 +111,7 @@
<ClInclude Include="..\..\beast\config\StandardConfig.h" /> <ClInclude Include="..\..\beast\config\StandardConfig.h" />
<ClInclude Include="..\..\beast\Crypto.h" /> <ClInclude Include="..\..\beast\Crypto.h" />
<ClInclude Include="..\..\beast\crypto\impl\sha2\sha2.h" /> <ClInclude Include="..\..\beast\crypto\impl\sha2\sha2.h" />
<ClInclude Include="..\..\beast\crypto\MurmurHash.h" />
<ClInclude Include="..\..\beast\crypto\Sha256.h" /> <ClInclude Include="..\..\beast\crypto\Sha256.h" />
<ClInclude Include="..\..\beast\CStdInt.h" /> <ClInclude Include="..\..\beast\CStdInt.h" />
<ClInclude Include="..\..\beast\FixedArray.h" /> <ClInclude Include="..\..\beast\FixedArray.h" />
@@ -280,7 +281,6 @@
<ClInclude Include="..\..\modules\beast_core\maths\Expression.h" /> <ClInclude Include="..\..\modules\beast_core\maths\Expression.h" />
<ClInclude Include="..\..\modules\beast_core\maths\Interval.h" /> <ClInclude Include="..\..\modules\beast_core\maths\Interval.h" />
<ClInclude Include="..\..\modules\beast_core\maths\Math.h" /> <ClInclude Include="..\..\modules\beast_core\maths\Math.h" />
<ClInclude Include="..\..\modules\beast_core\maths\MurmurHash.h" />
<ClInclude Include="..\..\modules\beast_core\maths\Random.h" /> <ClInclude Include="..\..\modules\beast_core\maths\Random.h" />
<ClInclude Include="..\..\modules\beast_core\maths\Range.h" /> <ClInclude Include="..\..\modules\beast_core\maths\Range.h" />
<ClInclude Include="..\..\modules\beast_core\maths\uint24.h" /> <ClInclude Include="..\..\modules\beast_core\maths\uint24.h" />
@@ -425,6 +425,12 @@
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClCompile> </ClCompile>
<ClCompile Include="..\..\beast\crypto\Crypto.cpp" /> <ClCompile Include="..\..\beast\crypto\Crypto.cpp" />
<ClCompile Include="..\..\beast\crypto\impl\MurmurHash.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\..\beast\crypto\impl\Sha256.cpp"> <ClCompile Include="..\..\beast\crypto\impl\Sha256.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
@@ -879,12 +885,6 @@
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClCompile> </ClCompile>
<ClCompile Include="..\..\modules\beast_core\maths\MurmurHash.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\..\modules\beast_core\maths\Random.cpp"> <ClCompile Include="..\..\modules\beast_core\maths\Random.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>

View File

@@ -683,9 +683,6 @@
<ClInclude Include="..\..\modules\beast_sqdb\detail\use_type.h"> <ClInclude Include="..\..\modules\beast_sqdb\detail\use_type.h">
<Filter>beast_sqdb\detail</Filter> <Filter>beast_sqdb\detail</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\..\modules\beast_core\maths\MurmurHash.h">
<Filter>beast_core\maths</Filter>
</ClInclude>
<ClInclude Include="..\..\modules\beast_core\text\LexicalCast.h"> <ClInclude Include="..\..\modules\beast_core\text\LexicalCast.h">
<Filter>beast_core\text</Filter> <Filter>beast_core\text</Filter>
</ClInclude> </ClInclude>
@@ -1263,6 +1260,9 @@
<ClInclude Include="..\..\beast\asio\IPAddressConversion.h"> <ClInclude Include="..\..\beast\asio\IPAddressConversion.h">
<Filter>beast\asio</Filter> <Filter>beast\asio</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\..\beast\crypto\MurmurHash.h">
<Filter>beast\crypto</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="..\..\modules\beast_core\containers\AbstractFifo.cpp"> <ClCompile Include="..\..\modules\beast_core\containers\AbstractFifo.cpp">
@@ -1565,9 +1565,6 @@
<ClCompile Include="..\..\modules\beast_sqdb\source\use_type.cpp"> <ClCompile Include="..\..\modules\beast_sqdb\source\use_type.cpp">
<Filter>beast_sqdb\source</Filter> <Filter>beast_sqdb\source</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\..\modules\beast_core\maths\MurmurHash.cpp">
<Filter>beast_core\maths</Filter>
</ClCompile>
<ClCompile Include="..\..\modules\beast_core\text\LexicalCast.cpp"> <ClCompile Include="..\..\modules\beast_core\text\LexicalCast.cpp">
<Filter>beast_core\text</Filter> <Filter>beast_core\text</Filter>
</ClCompile> </ClCompile>
@@ -1817,6 +1814,9 @@
<ClCompile Include="..\..\beast\asio\impl\IPAddressConversion.cpp"> <ClCompile Include="..\..\beast\asio\impl\IPAddressConversion.cpp">
<Filter>beast\asio\impl</Filter> <Filter>beast\asio\impl</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\..\beast\crypto\impl\MurmurHash.cpp">
<Filter>beast\crypto\impl</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Text Include="..\..\TODO.txt"> <Text Include="..\..\TODO.txt">

View File

@@ -20,6 +20,7 @@
#ifndef BEAST_CRYPTO_H_INCLUDED #ifndef BEAST_CRYPTO_H_INCLUDED
#define BEAST_CRYPTO_H_INCLUDED #define BEAST_CRYPTO_H_INCLUDED
#include "crypto/MurmurHash.h"
#include "crypto/Sha256.h" #include "crypto/Sha256.h"
#endif #endif

View File

@@ -19,4 +19,5 @@
#include "BeastConfig.h" #include "BeastConfig.h"
#include "impl/MurmurHash.cpp"
#include "impl/Sha256.cpp" #include "impl/Sha256.cpp"

View File

@@ -17,15 +17,15 @@
*/ */
//============================================================================== //==============================================================================
#ifndef BEAST_MURMURHASH_H_INCLUDED #ifndef BEAST_CRYPTO_MURMURHASH_H_INCLUDED
#define BEAST_MURMURHASH_H_INCLUDED #define BEAST_CRYPTO_MURMURHASH_H_INCLUDED
#include "../CStdInt.h"
// Original source code links in .cpp file // Original source code links in .cpp file
// This file depends on some Beast declarations and defines namespace beast {
namespace Murmur {
namespace Murmur
{
extern void MurmurHash3_x86_32 (const void* key, int len, uint32 seed, void* out); extern void MurmurHash3_x86_32 (const void* key, int len, uint32 seed, void* out);
extern void MurmurHash3_x86_128 (const void* key, int len, uint32 seed, void* out); extern void MurmurHash3_x86_128 (const void* key, int len, uint32 seed, void* out);
@@ -77,6 +77,7 @@ inline void Hash (const void* key, int len, uint32 seed, HashType* out)
}; };
} }
}
} }
#endif #endif

View File

@@ -19,8 +19,12 @@
// http://code.google.com/p/smhasher/ // http://code.google.com/p/smhasher/
namespace Murmur #include "../MurmurHash.h"
{
#include <cstdint>
namespace beast {
namespace Murmur {
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// Platform-specific functions and macros // Platform-specific functions and macros
@@ -485,3 +489,4 @@ void MurmurHash3_x64_128 ( const void* key, const int len,
} }
} }
}

View File

@@ -195,6 +195,9 @@ public:
/** Generates a probably-unique 64-bit hashcode from this string. */ /** Generates a probably-unique 64-bit hashcode from this string. */
int64 hashCode64() const noexcept; int64 hashCode64() const noexcept;
/** Returns a hash value suitable for use with std::hash. */
std::size_t hash() const noexcept;
/** Returns the number of characters in the string. */ /** Returns the number of characters in the string. */
int length() const noexcept; int length() const noexcept;

View File

@@ -404,26 +404,42 @@ beast_wchar String::operator[] (int index) const noexcept
return text [index]; return text [index];
} }
//------------------------------------------------------------------------------
namespace detail {
template <typename Type>
struct HashGenerator
{
template <typename CharPointer>
static Type calculate (CharPointer t) noexcept
{
Type result = Type();
while (! t.isEmpty())
result = multiplier * result + t.getAndAdvance();
return result;
}
enum { multiplier = sizeof (Type) > 4 ? 101 : 31 };
};
}
int String::hashCode() const noexcept int String::hashCode() const noexcept
{ {
CharPointerType t (text); return detail::HashGenerator<int> ::calculate (text);
int result = 0;
while (! t.isEmpty())
result = 31 * result + (int) t.getAndAdvance();
return result;
} }
int64 String::hashCode64() const noexcept int64 String::hashCode64() const noexcept
{ {
CharPointerType t (text); return detail::HashGenerator<int64> ::calculate (text);
int64 result = 0; }
while (! t.isEmpty()) std::size_t String::hash() const noexcept
result = 101 * result + t.getAndAdvance(); {
return detail::HashGenerator<std::size_t>::calculate (text);
return result;
} }
//============================================================================== //==============================================================================

View File

@@ -156,7 +156,6 @@ namespace beast
#include "maths/BigInteger.cpp" #include "maths/BigInteger.cpp"
#include "maths/Expression.cpp" #include "maths/Expression.cpp"
#include "maths/MurmurHash.cpp"
#include "maths/Random.cpp" #include "maths/Random.cpp"
#include "memory/MemoryBlock.cpp" #include "memory/MemoryBlock.cpp"

View File

@@ -187,7 +187,6 @@ class FileOutputStream;
#include "logging/Logger.h" #include "logging/Logger.h"
#include "maths/Expression.h" #include "maths/Expression.h"
#include "maths/Interval.h" #include "maths/Interval.h"
#include "maths/MurmurHash.h"
#include "memory/OptionalScopedPointer.h" #include "memory/OptionalScopedPointer.h"
#include "memory/SharedSingleton.h" #include "memory/SharedSingleton.h"
#include "memory/WeakReference.h" #include "memory/WeakReference.h"

View File

@@ -38,11 +38,11 @@
#endif #endif
#include "../beast_core/beast_core.h" #include "../beast_core/beast_core.h"
#include "../../beast/crypto/MurmurHash.h"
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
namespace beast namespace beast {
{
# include "math/UnsignedIntegerCalc.h" # include "math/UnsignedIntegerCalc.h"
#include "math/UnsignedInteger.h" #include "math/UnsignedInteger.h"