X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fcore%2Fhash.h;h=d696cae5b63542e65d6718f1012d0606b9f55833;hb=20c897ece781e18ba54c41fd68e232ce566a938d;hp=bb3de0514859922447af63c00a431ec2b7f95d6b;hpb=651cfe05e867ffdef9028a831add3eca54d19d0d;p=libs%2Fcore.git diff --git a/source/core/hash.h b/source/core/hash.h index bb3de05..d696cae 100644 --- a/source/core/hash.h +++ b/source/core/hash.h @@ -2,21 +2,16 @@ #define MSP_CORE_HASH_H_ #include +#include "inttypes.h" namespace Msp { -#ifdef MSVC -typedef __uint64 HashValue64; -#else -typedef unsigned long long HashValue64; -#endif - /** Computes a 32-bit Fowler-Noll-Vo (FNV-1a) hash. The number of bits can be limited to less than 32, in which case XOR-folding is used to reduce the hash size. */ -unsigned hash32(const void *, unsigned, unsigned = 32); +UInt32 hash32(const void *, unsigned, unsigned = 32); /** Convenience function to compute a 32-bit hash of a string. @@ -28,14 +23,20 @@ inline unsigned hash32(const std::string &s, unsigned b = 32) Computes a 64-bit Fowler-Noll-Vo (FNV-1a) hash. Note that even if bits is limited to 32 or less, this does not produce the same result as hash32. */ -HashValue64 hash64(const void *, unsigned, unsigned = 64); +UInt64 hash64(const void *, unsigned, unsigned = 64); /** Convenience function to compute a 64-bit hash of a string. */ -inline HashValue64 hash64(const std::string &s, unsigned b = 64) +inline UInt64 hash64(const std::string &s, unsigned b = 64) { return hash64(s.data(), s.size(), b); } +inline UInt32 fold32(UInt64 hash) +{ return hash^(hash>>32); } + +inline UInt16 fold16(UInt64 hash) +{ return hash^(hash>>16)^(hash>>32)^(hash>>48); } + } // namespace Msp #endif