HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
hash.h
Go to the documentation of this file.
1 // Copyright 2008-present Contributors to the OpenImageIO project.
2 // SPDX-License-Identifier: BSD-3-Clause
3 // https://github.com/OpenImageIO/oiio
4 
5 // clang-format off
6 
7 /// \file
8 ///
9 /// Wrapper so that hash_map and hash_set mean what we want regardless
10 /// of the compiler.
11 ///
12 
13 #pragma once
14 
15 #include <cassert>
16 #include <cstdint>
17 #include <cstdlib>
18 #include <cstring>
19 #include <unordered_map>
20 #include <utility>
21 #include <vector>
22 
23 #include <OpenImageIO/span.h>
24 #include <OpenImageIO/export.h>
27 
28 // We should never have included fmath.h here. But we did, oops. Once we're
29 // allowed to break back compatibility, remove it.
30 #if OIIO_VERSION < OIIO_MAKE_VERSION(3,0,0)
31 # include <OpenImageIO/fmath.h>
32 #endif
33 
34 
35 
37 
38 using std::hash;
39 using std::unordered_map;
40 
41 namespace fasthash {
42 
43 /* The MIT License
44  Copyright (C) 2012 Zilong Tan (eric.zltan@gmail.com)
45  Permission is hereby granted, free of charge, to any person
46  obtaining a copy of this software and associated documentation
47  files (the "Software"), to deal in the Software without
48  restriction, including without limitation the rights to use, copy,
49  modify, merge, publish, distribute, sublicense, and/or sell copies
50  of the Software, and to permit persons to whom the Software is
51  furnished to do so, subject to the following conditions:
52  The above copyright notice and this permission notice shall be
53  included in all copies or substantial portions of the Software.
54  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
55  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
56  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
57  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
58  BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
59  ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
60  CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
61  SOFTWARE.
62 */
63 
64 // Compression function for Merkle-Damgard construction.
65 // This function is generated using the framework provided.
66 static inline uint64_t mix(uint64_t h) {
67  h ^= h >> 23;
68  h *= 0x2127599bf4325c37ULL;
69  h ^= h >> 47;
70  return h;
71 }
72 
73 inline uint64_t fasthash64(const void *buf, size_t len, uint64_t seed=1771)
74 {
75  const uint64_t m = 0x880355f21e6d1965ULL;
76  const uint64_t *pos = (const uint64_t *)buf;
77  const uint64_t *end = pos + (len / 8);
78  const unsigned char *pos2;
79  uint64_t h = seed ^ (len * m);
80  uint64_t v;
81 
82  while (pos != end) {
83  v = *pos++;
84  h ^= mix(v);
85  h *= m;
86  }
87 
88  pos2 = (const unsigned char*)pos;
89  v = 0;
90 
91  switch (len & 7) {
92  case 7: v ^= (uint64_t)pos2[6] << 48;
93  case 6: v ^= (uint64_t)pos2[5] << 40;
94  case 5: v ^= (uint64_t)pos2[4] << 32;
95  case 4: v ^= (uint64_t)pos2[3] << 24;
96  case 3: v ^= (uint64_t)pos2[2] << 16;
97  case 2: v ^= (uint64_t)pos2[1] << 8;
98  case 1: v ^= (uint64_t)pos2[0];
99  h ^= mix(v);
100  h *= m;
101  }
102 
103  return mix(h);
104 }
105 
106 // simplified version for hashing just a few ints
107 inline uint64_t fasthash64(const std::initializer_list<uint64_t> buf) {
108  const uint64_t m = 0x880355f21e6d1965ULL;
109  uint64_t h = (buf.size() * sizeof(uint64_t)) * m;
110  for (const uint64_t v : buf) {
111  h ^= mix(v);
112  h *= m;
113  }
114  return mix(h);
115 }
116 
117 } // namespace fasthash
118 
119 
120 namespace xxhash {
121 
122 // xxhash: https://github.com/Cyan4973/xxHash
123 // BSD 2-clause license
124 
125 unsigned int OIIO_API XXH32 (const void* input, size_t length,
126  unsigned seed=1771);
127 unsigned long long OIIO_API XXH64 (const void* input, size_t length,
128  unsigned long long seed=1771);
129 
130 inline size_t xxhash (const void* input, size_t length, size_t seed=1771)
131 {
132  return size_t (XXH64 (input, length, (unsigned long long)seed));
133 }
134 
135 template <typename Str>
136 inline size_t xxhash (const Str& s, size_t seed=1771) {
137  assert(sizeof(s[0]) == 1);
138  return xxhash (s.data(), s.length(), seed);
139 }
140 
141 } // end namespace xxhash
142 
143 
144 
145 
146 namespace bjhash {
147 
148 // Bob Jenkins "lookup3" hashes: http://burtleburtle.net/bob/c/lookup3.c
149 // It's in the public domain.
150 
152 rotl32(uint32_t x, int k)
153 {
154 #if defined(__CUDA_ARCH__) && __CUDA_ARCH__ >= 320
155  return __funnelshift_lc(x, x, k);
156 #else
157  return (x << k) | (x >> (32 - k));
158 #endif
159 }
160 
162 rotl64(uint64_t x, int k)
163 {
164  return (x << k) | (x >> (64 - k));
165 }
166 
167 // Mix up the bits of a, b, and c (changing their values in place).
168 inline OIIO_HOSTDEVICE void bjmix (uint32_t &a, uint32_t &b, uint32_t &c)
169 {
170  a -= c; a ^= rotl32(c, 4); c += b;
171  b -= a; b ^= rotl32(a, 6); a += c;
172  c -= b; c ^= rotl32(b, 8); b += a;
173  a -= c; a ^= rotl32(c,16); c += b;
174  b -= a; b ^= rotl32(a,19); a += c;
175  c -= b; c ^= rotl32(b, 4); b += a;
176 }
177 
178 // Mix up and combine the bits of a, b, and c (doesn't change them, but
179 // returns a hash of those three original values). 21 ops
180 inline OIIO_HOSTDEVICE uint32_t bjfinal (uint32_t a, uint32_t b, uint32_t c=0xdeadbeef)
181 {
182  c ^= b; c -= rotl32(b,14);
183  a ^= c; a -= rotl32(c,11);
184  b ^= a; b -= rotl32(a,25);
185  c ^= b; c -= rotl32(b,16);
186  a ^= c; a -= rotl32(c,4);
187  b ^= a; b -= rotl32(a,14);
188  c ^= b; c -= rotl32(b,24);
189  return c;
190 }
191 
192 // Mix up 4 64-bit inputs (non-destructively), and return a 64 bit hash.
193 // Adapted from http://burtleburtle.net/bob/c/SpookyV2.h 33 ops
194 inline uint64_t bjfinal64 (uint64_t h0, uint64_t h1, uint64_t h2, uint64_t h3)
195 {
196  h3 ^= h2; h2 = rotl64(h2,15); h3 += h2;
197  h0 ^= h3; h3 = rotl64(h3,52); h0 += h3;
198  h1 ^= h0; h0 = rotl64(h0,26); h1 += h0;
199  h2 ^= h1; h1 = rotl64(h1,51); h2 += h1;
200  h3 ^= h2; h2 = rotl64(h2,28); h3 += h2;
201  h0 ^= h3; h3 = rotl64(h3,9); h0 += h3;
202  h1 ^= h0; h0 = rotl64(h0,47); h1 += h0;
203  h2 ^= h1; h1 = rotl64(h1,54); h2 += h1;
204  h3 ^= h2; h2 = rotl64(h2,32); h3 += h2;
205  h0 ^= h3; h3 = rotl64(h3,25); h0 += h3;
206  h1 ^= h0; h0 = rotl64(h0,63); h1 += h0;
207  return h1;
208 }
209 
210 // Standard "lookup3" hash, arbitrary length in bytes.
211 uint32_t OIIO_API hashlittle (const void *key, size_t length,
212  uint32_t seed=1771);
213 
214 // Hash an array of 32 bit words -- faster than hashlittle if you know
215 // it's a whole number of 4-byte words.
216 uint32_t OIIO_API hashword (const uint32_t *key, size_t nwords,
217  uint32_t seed=1771);
218 
219 // Hash a string without pre-known length. We use the Jenkins
220 // one-at-a-time hash (http://en.wikipedia.org/wiki/Jenkins_hash_function),
221 // which seems to be a good speed/quality/requirements compromise.
222 // Note that this is only returning a 32 bit hash space.
223 inline size_t
224 strhash (const char *s)
225 {
226  if (! s) return 0;
227  unsigned int h = 0;
228  while (*s) {
229  h += (unsigned char)(*s);
230  h += h << 10;
231  h ^= h >> 6;
232  ++s;
233  }
234  h += h << 3;
235  h ^= h >> 11;
236  h += h << 15;
237  return h;
238 }
239 
240 
241 // Hash a string_view. We use the Jenkins
242 // one-at-a-time hash (http://en.wikipedia.org/wiki/Jenkins_hash_function),
243 // which seems to be a good speed/quality/requirements compromise.
244 // Note that this is only returning a 32 bit hash space.
245 inline size_t
247 {
248  size_t len = s.length();
249  if (! len) return 0;
250  unsigned int h = 0;
251  for (size_t i = 0; i < len; ++i) {
252  h += (unsigned char)(s[i]);
253  h += h << 10;
254  h ^= h >> 6;
255  }
256  h += h << 3;
257  h ^= h >> 11;
258  h += h << 15;
259  return h;
260 }
261 
262 } // end namespace bjhash
263 
264 
265 namespace murmur {
266 
267 // These functions were lifted from the public domain Murmurhash3. We
268 // don't bother using Murmurhash -- in my tests, it was slower than
269 // xxhash in all cases, and comparable to bjhash. But these two fmix
270 // functions are useful for scrambling the bits of a single 32 or 64 bit
271 // value.
272 
273 inline uint32_t fmix (uint32_t h)
274 {
275  h ^= h >> 16;
276  h *= 0x85ebca6b;
277  h ^= h >> 13;
278  h *= 0xc2b2ae35;
279  h ^= h >> 16;
280  return h;
281 }
282 
283 inline uint64_t fmix (uint64_t k)
284 {
285  k ^= k >> 33;
286  k *= 0xff51afd7ed558ccdULL;
287  k ^= k >> 33;
288  k *= 0xc4ceb9fe1a85ec53ULL;
289  k ^= k >> 33;
290  return k;
291 }
292 
293 } // end namespace murmur
294 
295 
296 
297 namespace farmhash {
298 
299 // Copyright (c) 2014 Google, Inc.
300 // https://github.com/google/farmhash
301 // See OpenImageIO's hashes.cpp for the MIT license for this code.
302 
303 
304 #if defined(FARMHASH_UINT128_T_DEFINED)
305 
306 OIIO_HOSTDEVICE inline constexpr uint64_t Uint128Low64(const uint128_t x) {
307  return static_cast<uint64_t>(x);
308 }
309 
310 OIIO_HOSTDEVICE inline constexpr uint64_t Uint128High64(const uint128_t x) {
311  return static_cast<uint64_t>(x >> 64);
312 }
313 
314 OIIO_HOSTDEVICE inline constexpr uint128_t Uint128(uint64_t lo, uint64_t hi) {
315  return lo + (((uint128_t)hi) << 64);
316 }
317 
320  dst = src;
321 }
322 
323 #else
324 
325 typedef std::pair<uint64_t, uint64_t> uint128_t;
326 OIIO_HOSTDEVICE inline constexpr uint64_t Uint128Low64(const uint128_t x) {
327  return x.first;
328 }
329 
330 OIIO_HOSTDEVICE inline constexpr uint64_t Uint128High64(const uint128_t x) {
331  return x.second;
332 }
333 
334 OIIO_HOSTDEVICE inline OIIO_CONSTEXPR14 uint128_t Uint128(uint64_t lo, uint64_t hi) {
335  return uint128_t(lo, hi);
336 }
337 
340  dst.first = src.first;
341  dst.second = src.second;
342 
343 }
344 #endif
345 
346 
347 // BASIC STRING HASHING
348 
349 // Hash function for a byte array.
350 // May change from time to time, may differ on different platforms, may differ
351 // depending on NDEBUG.
352 size_t OIIO_API Hash(const char* s, size_t len);
353 
354 // Hash function for a byte array. Most useful in 32-bit binaries.
355 // May change from time to time, may differ on different platforms, may differ
356 // depending on NDEBUG.
357 uint32_t OIIO_API Hash32(const char* s, size_t len);
358 
359 // Hash function for a byte array. For convenience, a 32-bit seed is also
360 // hashed into the result.
361 // May change from time to time, may differ on different platforms, may differ
362 // depending on NDEBUG.
363 uint32_t OIIO_API Hash32WithSeed(const char* s, size_t len, uint32_t seed);
364 
365 // Hash 128 input bits down to 64 bits of output.
366 // Hash function for a byte array.
367 // May change from time to time, may differ on different platforms, may differ
368 // depending on NDEBUG.
369 uint64_t OIIO_API Hash64(const char* s, size_t len);
370 
371 // Hash function for a byte array. For convenience, a 64-bit seed is also
372 // hashed into the result.
373 // May change from time to time, may differ on different platforms, may differ
374 // depending on NDEBUG.
375 uint64_t OIIO_API Hash64WithSeed(const char* s, size_t len, uint64_t seed);
376 
377 // Hash function for a byte array. For convenience, two seeds are also
378 // hashed into the result.
379 // May change from time to time, may differ on different platforms, may differ
380 // depending on NDEBUG.
381 uint64_t OIIO_API Hash64WithSeeds(const char* s, size_t len,
382  uint64_t seed0, uint64_t seed1);
383 
384 // Hash function for a byte array.
385 // May change from time to time, may differ on different platforms, may differ
386 // depending on NDEBUG.
387 uint128_t OIIO_API Hash128(const char* s, size_t len);
388 
389 // Hash function for a byte array. For convenience, a 128-bit seed is also
390 // hashed into the result.
391 // May change from time to time, may differ on different platforms, may differ
392 // depending on NDEBUG.
393 uint128_t OIIO_API Hash128WithSeed(const char* s, size_t len, uint128_t seed);
394 
395 // BASIC NON-STRING HASHING
396 
397 // This is intended to be a reasonably good hash function.
398 // May change from time to time, may differ on different platforms, may differ
399 // depending on NDEBUG.
401  // Murmur-inspired hashing.
402  const uint64_t kMul = 0x9ddfea08eb382d69ULL;
403  uint64_t a = (Uint128Low64(x) ^ Uint128High64(x)) * kMul;
404  a ^= (a >> 47);
405  uint64_t b = (Uint128High64(x) ^ a) * kMul;
406  b ^= (b >> 47);
407  b *= kMul;
408  return b;
409 }
410 
411 // FINGERPRINTING (i.e., good, portable, forever-fixed hash functions)
412 
413 // Fingerprint function for a byte array. Most useful in 32-bit binaries.
414 uint32_t OIIO_API Fingerprint32(const char* s, size_t len);
415 
416 // Fingerprint function for a byte array.
417 uint64_t OIIO_API Fingerprint64(const char* s, size_t len);
418 
419 // Fingerprint function for a byte array.
420 uint128_t OIIO_API Fingerprint128(const char* s, size_t len);
421 
422 // This is intended to be a good fingerprinting primitive.
423 // See below for more overloads.
425  // Murmur-inspired hashing.
426  const uint64_t kMul = 0x9ddfea08eb382d69ULL;
427  uint64_t a = (Uint128Low64(x) ^ Uint128High64(x)) * kMul;
428  a ^= (a >> 47);
429  uint64_t b = (Uint128High64(x) ^ a) * kMul;
430  b ^= (b >> 44);
431  b *= kMul;
432  b ^= (b >> 41);
433  b *= kMul;
434  return b;
435 }
436 
437 // This is intended to be a good fingerprinting primitive.
438 OIIO_HOSTDEVICE inline OIIO_CONSTEXPR14 uint64_t Fingerprint(uint64_t x) {
439  // Murmur-inspired hashing.
440  const uint64_t kMul = 0x9ddfea08eb382d69ULL;
441  uint64_t b = x * kMul;
442  b ^= (b >> 44);
443  b *= kMul;
444  b ^= (b >> 41);
445  b *= kMul;
446  return b;
447 }
448 
449 #ifndef FARMHASH_NO_CXX_STRING
450 
451 // Convenience functions to hash or fingerprint C++ strings.
452 // These require that Str::data() return a pointer to the first char
453 // (as a const char*) and that Str::length() return the string's length;
454 // they work with std::string, for example.
455 
456 // Hash function for a byte array.
457 // May change from time to time, may differ on different platforms, may differ
458 // depending on NDEBUG.
459 template <typename Str>
460 inline size_t Hash(const Str& s) {
461  assert(sizeof(s[0]) == 1);
462  return Hash(s.data(), s.length());
463 }
464 
465 // Hash function for a byte array. Most useful in 32-bit binaries.
466 // May change from time to time, may differ on different platforms, may differ
467 // depending on NDEBUG.
468 template <typename Str>
469 inline uint32_t Hash32(const Str& s) {
470  assert(sizeof(s[0]) == 1);
471  return Hash32(s.data(), s.length());
472 }
473 
474 // Hash function for a byte array. For convenience, a 32-bit seed is also
475 // hashed into the result.
476 // May change from time to time, may differ on different platforms, may differ
477 // depending on NDEBUG.
478 template <typename Str>
479 inline uint32_t Hash32WithSeed(const Str& s, uint32_t seed) {
480  assert(sizeof(s[0]) == 1);
481  return Hash32WithSeed(s.data(), s.length(), seed);
482 }
483 
484 // Hash 128 input bits down to 64 bits of output.
485 // Hash function for a byte array.
486 // May change from time to time, may differ on different platforms, may differ
487 // depending on NDEBUG.
488 template <typename Str>
489 inline uint64_t Hash64(const Str& s) {
490  assert(sizeof(s[0]) == 1);
491  return Hash64(s.data(), s.length());
492 }
493 
494 // Hash function for a byte array. For convenience, a 64-bit seed is also
495 // hashed into the result.
496 // May change from time to time, may differ on different platforms, may differ
497 // depending on NDEBUG.
498 template <typename Str>
499 inline uint64_t Hash64WithSeed(const Str& s, uint64_t seed) {
500  assert(sizeof(s[0]) == 1);
501  return Hash64WithSeed(s.data(), s.length(), seed);
502 }
503 
504 // Hash function for a byte array. For convenience, two seeds are also
505 // hashed into the result.
506 // May change from time to time, may differ on different platforms, may differ
507 // depending on NDEBUG.
508 template <typename Str>
509 inline uint64_t Hash64WithSeeds(const Str& s, uint64_t seed0, uint64_t seed1) {
510  assert(sizeof(s[0]) == 1);
511  return Hash64WithSeeds(s.data(), s.length(), seed0, seed1);
512 }
513 
514 // Hash function for a byte array.
515 // May change from time to time, may differ on different platforms, may differ
516 // depending on NDEBUG.
517 template <typename Str>
518 inline uint128_t Hash128(const Str& s) {
519  assert(sizeof(s[0]) == 1);
520  return Hash128(s.data(), s.length());
521 }
522 
523 // Hash function for a byte array. For convenience, a 128-bit seed is also
524 // hashed into the result.
525 // May change from time to time, may differ on different platforms, may differ
526 // depending on NDEBUG.
527 template <typename Str>
528 inline uint128_t Hash128WithSeed(const Str& s, uint128_t seed) {
529  assert(sizeof(s[0]) == 1);
530  return Hash128(s.data(), s.length(), seed);
531 }
532 
533 // FINGERPRINTING (i.e., good, portable, forever-fixed hash functions)
534 
535 // Fingerprint function for a byte array. Most useful in 32-bit binaries.
536 template <typename Str>
537 inline uint32_t Fingerprint32(const Str& s) {
538  assert(sizeof(s[0]) == 1);
539  return Fingerprint32(s.data(), s.length());
540 }
541 
542 // Fingerprint 128 input bits down to 64 bits of output.
543 // Fingerprint function for a byte array.
544 template <typename Str>
545 inline uint64_t Fingerprint64(const Str& s) {
546  assert(sizeof(s[0]) == 1);
547  return Fingerprint64(s.data(), s.length());
548 }
549 
550 // Fingerprint function for a byte array.
551 template <typename Str>
552 inline uint128_t Fingerprint128(const Str& s) {
553  assert(sizeof(s[0]) == 1);
554  return Fingerprint128(s.data(), s.length());
555 }
556 
557 #endif
558 
559 } // namespace farmhash
560 
561 
562 
563 
564 class CSHA1; // opaque forward declaration
565 
566 
567 /// Class that encapsulates SHA-1 hashing, a crypticographic-strength
568 /// 160-bit hash function. It's not as fast as our other hashing
569 /// methods, but has an extremely low chance of having collisions.
570 class OIIO_API SHA1 {
571 public:
572  /// Create SHA1, optionally read data
573  SHA1 (const void *data=NULL, size_t size=0);
574  ~SHA1 ();
575 
576  /// Append more data
577  void append (const void *data, size_t size);
578 
579  /// Append more data from a string_view
581  append(s.data(), s.size());
582  }
583 
584  /// Append more data from a span, without thinking about sizes.
585  template<class T> void append (span<T> v) {
586  append (v.data(), v.size()*sizeof(T));
587  }
588 
589  /// Type for storing the raw bits of the hash
590  struct Hash {
591  unsigned char hash[20];
592  };
593 
594  /// Get the digest and store it in Hash h.
595  void gethash (Hash &h);
596 
597  /// Get the digest and store it in h (must point to enough storage
598  /// to accommodate 20 bytes).
599  void gethash (void *h) { gethash (*(Hash *)h); }
600 
601  /// Return the digest as a hex string
602  std::string digest ();
603 
604  /// Roll the whole thing into one functor, return the string digest.
605  static std::string digest (const void *data, size_t size) {
606  SHA1 s (data, size); return s.digest();
607  }
608 
609 private:
610  CSHA1 *m_csha1;
611  bool m_final;
612 };
613 
614 
#define OIIO_CONSTEXPR14
Definition: platform.h:101
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glcorearb.h:2540
#define OIIO_FORCEINLINE
Definition: platform.h:395
OIIO_HOSTDEVICE constexpr uint64_t Uint128Low64(const uint128_t x)
Definition: hash.h:326
const GLdouble * v
Definition: glcorearb.h:837
void gethash(void *h)
Definition: hash.h:599
uint128_t OIIO_API Hash128WithSeed(const char *s, size_t len, uint128_t seed)
Definition: farmhash.h:2069
OIIO_HOSTDEVICE uint32_t bjfinal(uint32_t a, uint32_t b, uint32_t c=0xdeadbeef)
Definition: hash.h:180
GLsizei const GLchar *const * string
Definition: glcorearb.h:814
size_t xxhash(const Str &s, size_t seed=1771)
Definition: hash.h:136
size_t strhash(const char *s)
Definition: hash.h:224
Definition: span.h:73
uint32_t OIIO_API hashlittle(const void *key, size_t length, uint32_t seed=1771)
GLboolean GLboolean GLboolean GLboolean a
Definition: glcorearb.h:1222
GLdouble s
Definition: glad.h:3009
GLuint GLsizei GLsizei * length
Definition: glcorearb.h:795
Type for storing the raw bits of the hash.
Definition: hash.h:590
void append(string_view s)
Append more data from a string_view.
Definition: hash.h:580
unsigned long long OIIO_API XXH64(const void *input, size_t length, unsigned long long seed=1771)
OIIO_HOSTDEVICE OIIO_CONSTEXPR14 uint64_t Hash128to64(uint128_t x)
Definition: hash.h:400
uint64_t OIIO_API Hash64WithSeeds(const char *s, size_t len, uint64_t seed0, uint64_t seed1)
Definition: farmhash.h:685
constexpr const_pointer data() const noexcept
Definition: string_view.h:170
size_t OIIO_API Hash(const char *s, size_t len)
Definition: farmhash.h:2038
OIIO_HOSTDEVICE OIIO_CONSTEXPR14 uint128_t Uint128(uint64_t lo, uint64_t hi)
Definition: hash.h:334
size_t xxhash(const void *input, size_t length, size_t seed=1771)
Definition: hash.h:130
constexpr size_type size() const noexcept
Definition: string_view.h:150
unsigned int OIIO_API XXH32(const void *input, size_t length, unsigned seed=1771)
std::string digest()
Return the digest as a hex string.
GLuint GLuint end
Definition: glcorearb.h:475
uint64_t bjfinal64(uint64_t h0, uint64_t h1, uint64_t h2, uint64_t h3)
Definition: hash.h:194
Definition: hash.h:570
#define OIIO_HOSTDEVICE
Definition: platform.h:509
OIIO_HOSTDEVICE constexpr uint64_t Uint128High64(const uint128_t x)
Definition: hash.h:330
constexpr size_type size() const noexcept
Definition: span.h:185
OIIO_FORCEINLINE OIIO_HOSTDEVICE uint64_t rotl64(uint64_t x, int k)
Definition: hash.h:162
OIIO_HOSTDEVICE void bjmix(uint32_t &a, uint32_t &b, uint32_t &c)
Definition: hash.h:168
uint64_t OIIO_API Hash64(const char *s, size_t len)
Definition: farmhash.h:630
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1222
GLint GLenum GLint x
Definition: glcorearb.h:409
uint32_t OIIO_API Fingerprint32(const char *s, size_t len)
Definition: farmhash.h:2078
uint128_t OIIO_API Hash128(const char *s, size_t len)
Definition: farmhash.h:2061
uint32_t fmix(uint32_t h)
Definition: hash.h:273
uint64_t fasthash64(const void *buf, size_t len, uint64_t seed=1771)
Definition: hash.h:73
uint64_t OIIO_API Fingerprint64(const char *s, size_t len)
Definition: farmhash.h:2083
void append(span< T > v)
Append more data from a span, without thinking about sizes.
Definition: hash.h:585
GLsizeiptr size
Definition: glcorearb.h:664
GLfloat GLfloat GLfloat GLfloat h
Definition: glcorearb.h:2002
GLenum GLenum dst
Definition: glcorearb.h:1793
uint64_t OIIO_API Hash64WithSeed(const char *s, size_t len, uint64_t seed)
Definition: farmhash.h:689
uint128_t
Definition: core.h:396
constexpr size_type length() const noexcept
Definition: string_view.h:151
static std::string digest(const void *data, size_t size)
Roll the whole thing into one functor, return the string digest.
Definition: hash.h:605
OIIO_HOSTDEVICE OIIO_CONSTEXPR14 uint64_t Fingerprint(uint128_t x)
Definition: hash.h:424
uint32_t OIIO_API hashword(const uint32_t *key, size_t nwords, uint32_t seed=1771)
#define OIIO_NAMESPACE_END
Definition: oiioversion.h:94
OIIO_HOSTDEVICE OIIO_CONSTEXPR14 void CopyUint128(uint128_t &dst, const uint128_t src)
Definition: hash.h:339
uint32_t OIIO_API Hash32WithSeed(const char *s, size_t len, uint32_t seed)
Definition: farmhash.h:1114
OIIO_FORCEINLINE OIIO_HOSTDEVICE uint32_t rotl32(uint32_t x, int k)
Definition: hash.h:152
constexpr pointer data() const noexcept
Definition: span.h:189
uint32_t OIIO_API Hash32(const char *s, size_t len)
Definition: farmhash.h:1109
std::pair< uint64_t, uint64_t > uint128_t
Definition: hash.h:325
Definition: format.h:895
#define OIIO_NAMESPACE_BEGIN
Definition: oiioversion.h:93
#define OIIO_API
Definition: export.h:65
GLenum src
Definition: glcorearb.h:1793
uint128_t OIIO_API Fingerprint128(const char *s, size_t len)
Definition: farmhash.h:1989