1 #ifndef MSP_CORE_HASH_H_
2 #define MSP_CORE_HASH_H_
10 Computes a 32-bit Fowler-Noll-Vo (FNV-1a) hash. The number of bits can be
11 limited to less than 32, in which case XOR-folding is used to reduce the hash
14 UInt32 hash32(const void *, unsigned, unsigned = 32);
17 Convenience function to compute a 32-bit hash of a string.
19 inline unsigned hash32(const std::string &s, unsigned b = 32)
20 { return hash32(s.data(), s.size(), b); }
23 Computes a 64-bit Fowler-Noll-Vo (FNV-1a) hash. Note that even if bits is
24 limited to 32 or less, this does not produce the same result as hash32.
26 UInt64 hash64(const void *, unsigned, unsigned = 64);
29 Convenience function to compute a 64-bit hash of a string.
31 inline UInt64 hash64(const std::string &s, unsigned b = 64)
32 { return hash64(s.data(), s.size(), b); }
34 inline UInt32 fold32(UInt64 hash)
35 { return hash^(hash>>32); }
37 inline UInt16 fold16(UInt64 hash)
38 { return hash^(hash>>16)^(hash>>32)^(hash>>48); }