]> git.tdb.fi Git - libs/core.git/blob - source/core/hash.h
Use a self-assignment to copy all members
[libs/core.git] / source / core / hash.h
1 #ifndef MSP_CORE_HASH_H_
2 #define MSP_CORE_HASH_H_
3
4 #include <string>
5
6 namespace Msp {
7
8 #ifdef WIN32
9 typedef __uint64 HashValue64;
10 #else
11 typedef unsigned long long HashValue64;
12 #endif
13
14 /**
15 Computes a 32-bit Fowler-Noll-Vo (FNV-1a) hash.  The number of bits can be
16 limited to less than 32, in which case XOR-folding is used to reduce the hash
17 size.
18 */
19 unsigned hash32(const void *, unsigned, unsigned = 32);
20
21 /**
22 Convenience function to compute a 32-bit hash of a string.
23 */
24 inline unsigned hash32(const std::string &s, unsigned b = 32)
25 { return hash32(s.data(), s.size(), b); }
26
27 /**
28 Computes a 64-bit Fowler-Noll-Vo (FNV-1a) hash.  Note that even if bits is
29 limited to 32 or less, this does not produce the same result as hash32.
30 */
31 HashValue64 hash64(const void *, unsigned, unsigned = 64);
32
33 /**
34 Convenience function to compute a 64-bit hash of a string.
35 */
36 inline HashValue64 hash64(const std::string &s, unsigned b = 64)
37 { return hash64(s.data(), s.size(), b); }
38
39 } // namespace Msp
40
41 #endif