19 #include <unordered_map>
30 #if OIIO_VERSION < OIIO_MAKE_VERSION(3,0,0)
39 using std::unordered_map;
66 static inline uint64_t mix(uint64_t
h) {
68 h *= 0x2127599bf4325c37ULL;
73 inline uint64_t
fasthash64(
const void *
buf,
size_t len, uint64_t seed=1771)
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);
88 pos2 = (
const unsigned char*)pos;
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];
108 const uint64_t m = 0x880355f21e6d1965ULL;
109 uint64_t h = (buf.size() *
sizeof(uint64_t)) * m;
110 for (
const uint64_t
v : buf) {
127 unsigned long long OIIO_API XXH64 (
const void* input,
size_t length,
128 unsigned long long seed=1771);
130 inline size_t xxhash (
const void* input,
size_t length,
size_t seed=1771)
132 return size_t (XXH64 (input, length, (
unsigned long long)seed));
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);
154 #if defined(__CUDA_ARCH__) && __CUDA_ARCH__ >= 320
155 return __funnelshift_lc(x, x, k);
157 return (x << k) | (x >> (32 - k));
164 return (x << k) | (x >> (64 - k));
194 inline uint64_t
bjfinal64 (uint64_t h0, uint64_t h1, uint64_t h2, uint64_t h3)
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;
229 h += (
unsigned char)(*s);
251 for (
size_t i = 0; i < len; ++i) {
252 h += (
unsigned char)(s[i]);
283 inline uint64_t
fmix (uint64_t k)
286 k *= 0xff51afd7ed558ccdULL;
288 k *= 0xc4ceb9fe1a85ec53ULL;
304 #if defined(FARMHASH_UINT128_T_DEFINED)
307 return static_cast<uint64_t
>(
x);
311 return static_cast<uint64_t
>(x >> 64);
340 dst.first = src.first;
341 dst.second = src.second;
382 uint64_t seed0, uint64_t seed1);
402 const uint64_t kMul = 0x9ddfea08eb382d69ULL;
426 const uint64_t kMul = 0x9ddfea08eb382d69ULL;
440 const uint64_t kMul = 0x9ddfea08eb382d69ULL;
441 uint64_t
b = x * kMul;
449 #ifndef FARMHASH_NO_CXX_STRING
459 template <
typename Str>
461 assert(
sizeof(s[0]) == 1);
462 return Hash(s.data(), s.length());
468 template <
typename Str>
470 assert(
sizeof(s[0]) == 1);
471 return Hash32(s.data(), s.length());
478 template <
typename Str>
480 assert(
sizeof(s[0]) == 1);
488 template <
typename Str>
490 assert(
sizeof(s[0]) == 1);
491 return Hash64(s.data(), s.length());
498 template <
typename Str>
500 assert(
sizeof(s[0]) == 1);
508 template <
typename Str>
510 assert(
sizeof(s[0]) == 1);
517 template <
typename Str>
519 assert(
sizeof(s[0]) == 1);
520 return Hash128(s.data(), s.length());
527 template <
typename Str>
529 assert(
sizeof(s[0]) == 1);
530 return Hash128(s.data(), s.length(), seed);
536 template <
typename Str>
538 assert(
sizeof(s[0]) == 1);
544 template <
typename Str>
546 assert(
sizeof(s[0]) == 1);
551 template <
typename Str>
553 assert(
sizeof(s[0]) == 1);
577 void append (
const void *
data,
size_t size);
591 unsigned char hash[20];
595 void gethash (
Hash &
h);
GLenum GLuint GLenum GLsizei const GLchar * buf
OIIO_HOSTDEVICE constexpr uint64_t Uint128Low64(const uint128_t x)
uint128_t OIIO_API Hash128WithSeed(const char *s, size_t len, uint128_t seed)
OIIO_HOSTDEVICE uint32_t bjfinal(uint32_t a, uint32_t b, uint32_t c=0xdeadbeef)
GLsizei const GLchar *const * string
size_t xxhash(const Str &s, size_t seed=1771)
size_t strhash(const char *s)
uint32_t OIIO_API hashlittle(const void *key, size_t length, uint32_t seed=1771)
GLboolean GLboolean GLboolean GLboolean a
GLuint GLsizei GLsizei * length
Type for storing the raw bits of the hash.
void append(string_view s)
Append more data from a string_view.
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)
uint64_t OIIO_API Hash64WithSeeds(const char *s, size_t len, uint64_t seed0, uint64_t seed1)
constexpr const_pointer data() const noexcept
size_t OIIO_API Hash(const char *s, size_t len)
OIIO_HOSTDEVICE OIIO_CONSTEXPR14 uint128_t Uint128(uint64_t lo, uint64_t hi)
size_t xxhash(const void *input, size_t length, size_t seed=1771)
constexpr size_type size() const noexcept
unsigned int OIIO_API XXH32(const void *input, size_t length, unsigned seed=1771)
std::string digest()
Return the digest as a hex string.
uint64_t bjfinal64(uint64_t h0, uint64_t h1, uint64_t h2, uint64_t h3)
OIIO_HOSTDEVICE constexpr uint64_t Uint128High64(const uint128_t x)
constexpr size_type size() const noexcept
OIIO_FORCEINLINE OIIO_HOSTDEVICE uint64_t rotl64(uint64_t x, int k)
OIIO_HOSTDEVICE void bjmix(uint32_t &a, uint32_t &b, uint32_t &c)
uint64_t OIIO_API Hash64(const char *s, size_t len)
GLboolean GLboolean GLboolean b
uint32_t OIIO_API Fingerprint32(const char *s, size_t len)
uint128_t OIIO_API Hash128(const char *s, size_t len)
uint32_t fmix(uint32_t h)
uint64_t fasthash64(const void *buf, size_t len, uint64_t seed=1771)
uint64_t OIIO_API Fingerprint64(const char *s, size_t len)
void append(span< T > v)
Append more data from a span, without thinking about sizes.
GLfloat GLfloat GLfloat GLfloat h
uint64_t OIIO_API Hash64WithSeed(const char *s, size_t len, uint64_t seed)
constexpr size_type length() const noexcept
static std::string digest(const void *data, size_t size)
Roll the whole thing into one functor, return the string digest.
OIIO_HOSTDEVICE OIIO_CONSTEXPR14 uint64_t Fingerprint(uint128_t x)
uint32_t OIIO_API hashword(const uint32_t *key, size_t nwords, uint32_t seed=1771)
#define OIIO_NAMESPACE_END
OIIO_HOSTDEVICE OIIO_CONSTEXPR14 void CopyUint128(uint128_t &dst, const uint128_t src)
uint32_t OIIO_API Hash32WithSeed(const char *s, size_t len, uint32_t seed)
OIIO_FORCEINLINE OIIO_HOSTDEVICE uint32_t rotl32(uint32_t x, int k)
constexpr pointer data() const noexcept
uint32_t OIIO_API Hash32(const char *s, size_t len)
std::pair< uint64_t, uint64_t > uint128_t
#define OIIO_NAMESPACE_BEGIN
uint128_t OIIO_API Fingerprint128(const char *s, size_t len)