diff options
| author | Tyge Løvset <[email protected]> | 2020-08-10 10:43:12 +0200 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2020-08-10 10:43:12 +0200 |
| commit | 70decdb703f5d053da3dbe349e9a7328a14aa1f2 (patch) | |
| tree | 181c05cb8fc208867ea91ee1198089039b3af134 /stc | |
| parent | d3110bfa37d12771e22c20aa503059476432a59d (diff) | |
| download | STC-modified-70decdb703f5d053da3dbe349e9a7328a14aa1f2.tar.gz STC-modified-70decdb703f5d053da3dbe349e9a7328a14aa1f2.zip | |
Updated hash funcs.
Diffstat (limited to 'stc')
| -rw-r--r-- | stc/cmap.h | 22 | ||||
| -rw-r--r-- | stc/crandom.h | 5 |
2 files changed, 8 insertions, 19 deletions
@@ -379,32 +379,20 @@ ctype##_##tag##_next(ctype##_##tag##_iter_t* it) { \ while (++it->item != it->end && *++it->_hx == 0) ; \
}
-
-/* One-byte-at-a-time hash based on Murmur's mix */
-STC_API uint32_t c_default_hash(const void *data, size_t len) {
- const volatile uint8_t *key = (const uint8_t *) data;
- uint32_t x = UINT32_C(0xc613fc15);
- while (len--) {
- x ^= *key++;
- x *= UINT32_C(0x5bd1e995);
- x ^= x >> 15;
- }
+STC_API uint32_t c_default_hash(const void *data, size_t len) {
+ const volatile uint16_t *key = (const uint16_t *) data;
+ uint64_t x = 0xc613fc15u;
+ while (len -= 2) x = ((*key++ + x) * 2654435769u) >> 13;
return x;
}
/* https://programmingpraxis.com/2018/06/19/fibonacci-hash */
/* https://probablydance.com/2018/06/16/fibonacci-hashing-the-optimization-that-the-world-forgot-or-a-better-alternative-to-integer-modulo/ */
-STC_API uint32_t c_fibonacci_hash32(const void* data, size_t len) {
+STC_API uint32_t c_default_hash32(const void* data, size_t len) {
const volatile uint32_t *key = (const uint32_t *) data;
uint32_t x = *key++ * 2654435769u;
while (len -= 4) x ^= *key++ * 2654435769u;
return x;
}
-STC_API uint32_t c_fibonacci_hash64(const void* data, size_t len) {
- const volatile uint64_t *key = (const uint64_t *) data;
- uint64_t x = *key++ * 11400714819323198485ull;
- while (len -= 8) x ^= *key++ * 11400714819323198485ull;
- return (uint32_t) x; // (x >> 13);
-}
#else
#define implement_CHASH(tag, ctype, Key, Value, valueDestroy, keyEqualsRaw, keyHashRaw, \
diff --git a/stc/crandom.h b/stc/crandom.h index 96a07fc4..1e3b2107 100644 --- a/stc/crandom.h +++ b/stc/crandom.h @@ -97,8 +97,9 @@ STC_INLINE crandom_distrib_i64_t crandom_uniform_i64_init(int64_t low, int64_t h STC_INLINE int64_t crandom_uniform_i64(crandom_eng64_t* rng, crandom_distrib_i64_t dist) {
#if defined(__SIZEOF_INT128__)
return dist.offset + (int64_t) (((__uint128_t) crandom_i64(rng) * dist.range) >> 64);
-#elif defined(_MSC_VER)
- int64_t hi; _mul128(crandom_i64(rng) >> 1, dist.range << 1, &hi); return dist.offset + hi;
+
+#elif defined(_MSC_VER) && defined(_WIN64)
+ int64_t hi; _umul128(crandom_i64(rng), dist.range, &hi); return dist.offset + hi;
#else
return dist.offset + crandom_i64(rng) % dist.range; // slower
#endif
|
