38 #ifndef OPENIMAGEIO_HASH_H
39 #define OPENIMAGEIO_HASH_H
43 #include <boost/version.hpp>
45 #define OIIO_HAVE_BOOST_UNORDERED_MAP
46 #include <boost/unordered_map.hpp>
47 #include <boost/unordered_set.hpp>
54 OIIO_NAMESPACE_ENTER {
63 unsigned int OIIO_API XXH_fast32 (
const void* input,
int len,
64 unsigned int seed=1771);
67 unsigned int OIIO_API XXH_strong32 (
const void* input,
int len,
68 unsigned int seed=1771);
79 inline uint32_t rotl32 (uint32_t x,
int k) {
return (x<<k) | (x>>(32-k)); }
80 inline uint64_t rotl64 (uint64_t x,
int k) {
return (x<<k) | (x>>(64-k)); }
83 inline void bjmix (uint32_t &a, uint32_t &b, uint32_t &c)
85 a -= c; a ^= rotl32(c, 4); c += b;
86 b -= a; b ^= rotl32(a, 6); a += c;
87 c -= b; c ^= rotl32(b, 8); b += a;
88 a -= c; a ^= rotl32(c,16); c += b;
89 b -= a; b ^= rotl32(a,19); a += c;
90 c -= b; c ^= rotl32(b, 4); b += a;
95 inline uint32_t bjfinal (uint32_t a, uint32_t b, uint32_t c=0xdeadbeef)
97 c ^= b; c -= rotl32(b,14);
98 a ^= c; a -= rotl32(c,11);
99 b ^= a; b -= rotl32(a,25);
100 c ^= b; c -= rotl32(b,16);
101 a ^= c; a -= rotl32(c,4);
102 b ^= a; b -= rotl32(a,14);
103 c ^= b; c -= rotl32(b,24);
109 inline uint64_t bjfinal64 (uint64_t h0, uint64_t h1, uint64_t h2, uint64_t h3)
111 h3 ^= h2; h2 = rotl64(h2,15); h3 += h2;
112 h0 ^= h3; h3 = rotl64(h3,52); h0 += h3;
113 h1 ^= h0; h0 = rotl64(h0,26); h1 += h0;
114 h2 ^= h1; h1 = rotl64(h1,51); h2 += h1;
115 h3 ^= h2; h2 = rotl64(h2,28); h3 += h2;
116 h0 ^= h3; h3 = rotl64(h3,9); h0 += h3;
117 h1 ^= h0; h0 = rotl64(h0,47); h1 += h0;
118 h2 ^= h1; h1 = rotl64(h1,54); h2 += h1;
119 h3 ^= h2; h2 = rotl64(h2,32); h3 += h2;
120 h0 ^= h3; h3 = rotl64(h3,25); h0 += h3;
121 h1 ^= h0; h0 = rotl64(h0,63); h1 += h0;
126 uint32_t OIIO_API hashlittle (
const void *key,
size_t length,
131 uint32_t OIIO_API hashword (
const uint32_t *key,
size_t nwords,
145 inline uint32_t fmix (uint32_t h)
155 inline uint64_t fmix (uint64_t k)
158 k *= 0xff51afd7ed558ccdULL;
160 k *= 0xc4ceb9fe1a85ec53ULL;
174 class OIIO_API SHA1 {
177 SHA1 (
const void *data=NULL,
size_t size=0);
181 void append (
const void *data,
size_t size);
183 template<
class T>
void appendvec (
const std::vector<T> &v) {
184 append (&v[0], v.size()*
sizeof(T));
189 unsigned char hash[20];
193 void gethash (Hash &h);
197 void gethash (
void *h) { gethash (*(Hash *)h); }
200 std::string digest ();
203 static std::string digest (
const void *data,
size_t size) {
204 SHA1 s (data, size);
return s.digest();
213 } OIIO_NAMESPACE_EXIT
215 #endif // OPENIMAGEIO_HASH_H