diff --git a/Builds/VisualStudio2012/beast.vcxproj b/Builds/VisualStudio2012/beast.vcxproj index cdf07854e..9319d642a 100644 --- a/Builds/VisualStudio2012/beast.vcxproj +++ b/Builds/VisualStudio2012/beast.vcxproj @@ -111,6 +111,7 @@ + @@ -280,7 +281,6 @@ - @@ -425,6 +425,12 @@ true + + true + true + true + true + true true @@ -879,12 +885,6 @@ true true - - true - true - true - true - true true diff --git a/Builds/VisualStudio2012/beast.vcxproj.filters b/Builds/VisualStudio2012/beast.vcxproj.filters index 21a8498eb..dffaf6ebb 100644 --- a/Builds/VisualStudio2012/beast.vcxproj.filters +++ b/Builds/VisualStudio2012/beast.vcxproj.filters @@ -683,9 +683,6 @@ beast_sqdb\detail - - beast_core\maths - beast_core\text @@ -1263,6 +1260,9 @@ beast\asio + + beast\crypto + @@ -1565,9 +1565,6 @@ beast_sqdb\source - - beast_core\maths - beast_core\text @@ -1817,6 +1814,9 @@ beast\asio\impl + + beast\crypto\impl + diff --git a/beast/Crypto.h b/beast/Crypto.h index 50d820466..379e172e3 100644 --- a/beast/Crypto.h +++ b/beast/Crypto.h @@ -20,6 +20,7 @@ #ifndef BEAST_CRYPTO_H_INCLUDED #define BEAST_CRYPTO_H_INCLUDED +#include "crypto/MurmurHash.h" #include "crypto/Sha256.h" #endif diff --git a/beast/crypto/Crypto.cpp b/beast/crypto/Crypto.cpp index e2b5228a7..77a73390f 100644 --- a/beast/crypto/Crypto.cpp +++ b/beast/crypto/Crypto.cpp @@ -19,4 +19,5 @@ #include "BeastConfig.h" +#include "impl/MurmurHash.cpp" #include "impl/Sha256.cpp" diff --git a/modules/beast_core/maths/MurmurHash.h b/beast/crypto/MurmurHash.h similarity index 93% rename from modules/beast_core/maths/MurmurHash.h rename to beast/crypto/MurmurHash.h index 7cdf570f7..724d62d2f 100644 --- a/modules/beast_core/maths/MurmurHash.h +++ b/beast/crypto/MurmurHash.h @@ -17,15 +17,15 @@ */ //============================================================================== -#ifndef BEAST_MURMURHASH_H_INCLUDED -#define BEAST_MURMURHASH_H_INCLUDED +#ifndef BEAST_CRYPTO_MURMURHASH_H_INCLUDED +#define BEAST_CRYPTO_MURMURHASH_H_INCLUDED + +#include "../CStdInt.h" // Original source code links in .cpp file -// This file depends on some Beast declarations and defines - -namespace Murmur -{ +namespace beast { +namespace Murmur { 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); @@ -77,6 +77,7 @@ inline void Hash (const void* key, int len, uint32 seed, HashType* out) }; } +} } #endif diff --git a/modules/beast_core/maths/MurmurHash.cpp b/beast/crypto/impl/MurmurHash.cpp similarity index 99% rename from modules/beast_core/maths/MurmurHash.cpp rename to beast/crypto/impl/MurmurHash.cpp index 8f7d7be2d..1674c3b43 100644 --- a/modules/beast_core/maths/MurmurHash.cpp +++ b/beast/crypto/impl/MurmurHash.cpp @@ -19,8 +19,12 @@ // http://code.google.com/p/smhasher/ -namespace Murmur -{ +#include "../MurmurHash.h" + +#include + +namespace beast { +namespace Murmur { //----------------------------------------------------------------------------- // Platform-specific functions and macros @@ -485,3 +489,4 @@ void MurmurHash3_x64_128 ( const void* key, const int len, } } +} diff --git a/beast/strings/String.h b/beast/strings/String.h index 03d26ca77..198408ac5 100644 --- a/beast/strings/String.h +++ b/beast/strings/String.h @@ -195,6 +195,9 @@ public: /** Generates a probably-unique 64-bit hashcode from this string. */ 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. */ int length() const noexcept; diff --git a/beast/strings/impl/String.cpp b/beast/strings/impl/String.cpp index 5f281dcaa..b12f397a9 100644 --- a/beast/strings/impl/String.cpp +++ b/beast/strings/impl/String.cpp @@ -404,26 +404,42 @@ beast_wchar String::operator[] (int index) const noexcept return text [index]; } +//------------------------------------------------------------------------------ + +namespace detail { + +template +struct HashGenerator +{ + template + 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 { - CharPointerType t (text); - int result = 0; - - while (! t.isEmpty()) - result = 31 * result + (int) t.getAndAdvance(); - - return result; + return detail::HashGenerator ::calculate (text); } int64 String::hashCode64() const noexcept { - CharPointerType t (text); - int64 result = 0; + return detail::HashGenerator ::calculate (text); +} - while (! t.isEmpty()) - result = 101 * result + t.getAndAdvance(); - - return result; +std::size_t String::hash() const noexcept +{ + return detail::HashGenerator::calculate (text); } //============================================================================== diff --git a/modules/beast_core/beast_core.cpp b/modules/beast_core/beast_core.cpp index 92abf6fb4..1b6761e3d 100644 --- a/modules/beast_core/beast_core.cpp +++ b/modules/beast_core/beast_core.cpp @@ -156,7 +156,6 @@ namespace beast #include "maths/BigInteger.cpp" #include "maths/Expression.cpp" -#include "maths/MurmurHash.cpp" #include "maths/Random.cpp" #include "memory/MemoryBlock.cpp" diff --git a/modules/beast_core/beast_core.h b/modules/beast_core/beast_core.h index e095d1d27..74aeb1601 100644 --- a/modules/beast_core/beast_core.h +++ b/modules/beast_core/beast_core.h @@ -187,7 +187,6 @@ class FileOutputStream; #include "logging/Logger.h" #include "maths/Expression.h" #include "maths/Interval.h" -#include "maths/MurmurHash.h" #include "memory/OptionalScopedPointer.h" #include "memory/SharedSingleton.h" #include "memory/WeakReference.h" diff --git a/modules/beast_crypto/beast_crypto.h b/modules/beast_crypto/beast_crypto.h index 4e9039bbc..04404475d 100644 --- a/modules/beast_crypto/beast_crypto.h +++ b/modules/beast_crypto/beast_crypto.h @@ -38,11 +38,11 @@ #endif #include "../beast_core/beast_core.h" +#include "../../beast/crypto/MurmurHash.h" //------------------------------------------------------------------------------ -namespace beast -{ +namespace beast { # include "math/UnsignedIntegerCalc.h" #include "math/UnsignedInteger.h"