diff options
| author | Tyge Løvset <[email protected]> | 2022-05-09 14:22:23 +0200 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2022-05-09 14:22:23 +0200 |
| commit | a34354bd24d81949567a1480209a2f7bbbe3bfbe (patch) | |
| tree | 72adf4c0c844913dd0bb975cbfbc805a0549a15b | |
| parent | e9c30e66af9c5c3054735eeb65c0bb384dea96b4 (diff) | |
| download | STC-modified-a34354bd24d81949567a1480209a2f7bbbe3bfbe.tar.gz STC-modified-a34354bd24d81949567a1480209a2f7bbbe3bfbe.zip | |
Small improvement in c_default_hash()
| -rw-r--r-- | benchmarks/shootout_hashmaps.cpp | 27 | ||||
| -rw-r--r-- | include/stc/ccommon.h | 2 |
2 files changed, 5 insertions, 24 deletions
diff --git a/benchmarks/shootout_hashmaps.cpp b/benchmarks/shootout_hashmaps.cpp index 4ed961e7..5fea8c9a 100644 --- a/benchmarks/shootout_hashmaps.cpp +++ b/benchmarks/shootout_hashmaps.cpp @@ -134,7 +134,7 @@ size_t seed; #define PMAP_DTOR(X) UMAP_DTOR(X) -#define MAP_TEST0(M, X, n) \ +#define MAP_TEST1(M, X, n) \ { /* Insert, update */ \ M##_SETUP(X, int64_t, int64_t); \ uint64_t sum = 0; \ @@ -149,22 +149,6 @@ size_t seed; M##_DTOR(X); \ } -#define MAP_TEST1(M, X, n) \ -{ /* Insert, update and erase another */ \ - M##_SETUP(X, int64_t, int64_t); \ - uint64_t sum = 0, erased = 0; \ - SEED(seed); \ - clock_t difference, before = clock(); \ - for (size_t i = 0; i < n; ++i) { \ - sum += ++ M##_EMPLACE(X, RAND(keybits), i); \ - erased += M##_ERASE(X, RAND(keybits)); \ - } \ - difference = clock() - before; \ - printf(#M ": time: %5.02f, size: %" PRIuMAX ", buckets: %8zu, erased %" PRIuMAX ", sum: %" PRIuMAX "\n", \ - (float) difference / CLOCKS_PER_SEC, (size_t) M##_SIZE(X), (size_t) M##_BUCKETS(X), erased, sum); \ - M##_DTOR(X); \ -} - #define MAP_TEST2(M, X, n) \ { /* Insert sequential keys, then erase them */ \ M##_SETUP(X, int64_t, int64_t); \ @@ -240,12 +224,12 @@ size_t seed; #ifdef __cplusplus -#define RUN_TEST(n) MAP_TEST##n(CMAP, ii, N##n) MAP_TEST##n(KMAP, ii, N##n) \ +#define RUN_TEST(n) MAP_TEST##n(KMAP, ii, N##n) MAP_TEST##n(CMAP, ii, N##n) \ MAP_TEST##n(PMAP, ii, N##n) MAP_TEST##n(FMAP, ii, N##n) \ MAP_TEST##n(RMAP, ii, N##n) MAP_TEST##n(HMAP, ii, N##n) \ MAP_TEST##n(TMAP, ii, N##n) MAP_TEST##n(UMAP, ii, N##n) #else -#define RUN_TEST(n) MAP_TEST##n(CMAP, ii, N##n) MAP_TEST##n(KMAP, ii, N##n) +#define RUN_TEST(n) MAP_TEST##n(KMAP, ii, N##n) MAP_TEST##n(CMAP, ii, N##n) #endif enum { @@ -274,10 +258,7 @@ int main(int argc, char* argv[]) printf("Usage %s [n-million=%d key-bits=%d]\n", argv[0], DEFAULT_N_MILL, DEFAULT_KEYBITS); printf("N-base = %d. Random keys are in range [0, 2^%d). Seed = %" PRIuMAX ":\n", n_mill, keybits, seed); - printf("\nT0: Insert/update random keys:\n"); - RUN_TEST(0) - - printf("\nT1: Insert/update random key + try to remove another random key:\n"); + printf("\nT1: Insert/update random keys:\n"); RUN_TEST(1) printf("\nT2: Insert sequential keys, then remove them in same order:\n"); diff --git a/include/stc/ccommon.h b/include/stc/ccommon.h index b0342928..68e45f43 100644 --- a/include/stc/ccommon.h +++ b/include/stc/ccommon.h @@ -123,7 +123,7 @@ STC_INLINE uint64_t c_fasthash(const void* key, size_t len) { uint32_t u4;
const uint8_t *x = (const uint8_t*) key;
while (n--)
- memcpy(&u8, x, 8), x += 8, h += (h << 10) ^ (u8*0xc6a4a7935bd1e99d);
+ memcpy(&u8, x, 8), x += 8, h += (_c_ROTL(u8, 26) ^ u8)*0xc6a4a7935bd1e99d;
switch (len &= 7) {
case 0: return h;
case 4: memcpy(&u4, x, 4); return h + u4*0xc6a4a7935bd1e99d;
|
