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 std::uint32_t 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 std::uint64_t hash64(const void *, unsigned, unsigned = 64);
29 Convenience function to compute a 64-bit hash of a string.
31 inline std::uint64_t hash64(const std::string &s, unsigned b = 64)
32 { return hash64(s.data(), s.size(), b); }
34 inline std::uint32_t fold32(std::uint64_t hash)
35 { return hash^(hash>>32); }
37 inline std::uint16_t fold16(std::uint64_t hash)
38 { return hash^(hash>>16)^(hash>>32)^(hash>>48); }