From 7d98bb163c9c1db7bf352f63deb8e186ac212676 Mon Sep 17 00:00:00 2001 From: Tyge Løvset Date: Tue, 23 Nov 2021 08:26:45 +0100 Subject: Renamed c_default_hash32/64 to c_hash32/64. Old are deprecated (still available). --- benchmarks/misc/rust_cmap.c | 2 +- benchmarks/picobench/picobench_cmap.cpp | 14 +++++++------- benchmarks/plotbench/cmap_benchmark.cpp | 8 ++++---- benchmarks/shootout_hashmaps.cpp | 6 +++--- docs/cmap_api.md | 12 ++++++------ include/stc/ccommon.h | 6 ++++-- 6 files changed, 25 insertions(+), 23 deletions(-) diff --git a/benchmarks/misc/rust_cmap.c b/benchmarks/misc/rust_cmap.c index 88dfbec1..d4a6f30c 100644 --- a/benchmarks/misc/rust_cmap.c +++ b/benchmarks/misc/rust_cmap.c @@ -2,7 +2,7 @@ #include #define i_key uint64_t #define i_val uint64_t -#define i_hash c_default_hash64 +#define i_hash c_hash64 #define i_tag u64 #include diff --git a/benchmarks/picobench/picobench_cmap.cpp b/benchmarks/picobench/picobench_cmap.cpp index 68d91f86..330c5e51 100644 --- a/benchmarks/picobench/picobench_cmap.cpp +++ b/benchmarks/picobench/picobench_cmap.cpp @@ -31,19 +31,19 @@ template using rmap = robin_hood::unordered_flat_map); +DEFMAP(map_i, ); DEFMAP(map_x, ); DEFMAP(map_s, ); -#define i_key int -#define i_val int -#define i_hash c_default_hash32 +#define i_key int32_t +#define i_val int32_t +#define i_hash c_hash32 #define i_tag i #include -#define i_key size_t -#define i_val size_t -#define i_hash c_default_hash64 +#define i_key uint64_t +#define i_val uint64_t +#define i_hash c_hash64 #define i_tag x #include diff --git a/benchmarks/plotbench/cmap_benchmark.cpp b/benchmarks/plotbench/cmap_benchmark.cpp index 0dbe5a31..4c9c6c16 100644 --- a/benchmarks/plotbench/cmap_benchmark.cpp +++ b/benchmarks/plotbench/cmap_benchmark.cpp @@ -15,15 +15,15 @@ uint64_t seed = 1, mask1 = 0xffffffff; static float secs(Range s) { return (float)(s.t2 - s.t1) / CLOCKS_PER_SEC; } -#define i_key size_t -#define i_val size_t -#define i_hash c_default_hash64 +#define i_key uint64_t +#define i_val uint64_t +#define i_hash c_hash64 #define i_tag x #include #ifdef __cplusplus Sample test_std_unordered_map() { - typedef std::unordered_map container; + typedef std::unordered_map container; Sample s = {"std,unordered_map"}; { stc64_srandom(seed); diff --git a/benchmarks/shootout_hashmaps.cpp b/benchmarks/shootout_hashmaps.cpp index 382a6334..40e0e579 100644 --- a/benchmarks/shootout_hashmaps.cpp +++ b/benchmarks/shootout_hashmaps.cpp @@ -26,7 +26,7 @@ KHASH_MAP_INIT_INT64(ii, int64_t) // cmap and khash template expansion #define i_key int64_t #define i_val int64_t -#define i_hash c_default_hash64 +#define i_hash c_hash64 #define i_tag ii #include @@ -207,7 +207,7 @@ size_t seed; SEED(seed); \ for (size_t i = 0; i < m; ++i) \ M##_PUT(X, RAND(keybits), i); \ - size_t x = 500000000/M##_SIZE(X); \ + size_t x = 300000000/M##_SIZE(X); \ clock_t difference, before = clock(); \ for (int k=0; k < x; k++) M##_FOR (X, it) \ sum += M##_ITEM(X, it); \ @@ -227,7 +227,7 @@ size_t seed; for (size_t i = 0; i < m; ++i) \ M##_PUT(X, RAND(keybits), i); \ before = clock(); \ - size_t x = m * 20000000/M##_SIZE(X); \ + size_t x = m * 10000000/M##_SIZE(X); \ for (size_t i = 0; i < x; ++i) \ found += M##_FIND(X, RAND(keybits)); \ SEED(seed); \ diff --git a/docs/cmap_api.md b/docs/cmap_api.md index a1f391bc..a33dc5c0 100644 --- a/docs/cmap_api.md +++ b/docs/cmap_api.md @@ -80,22 +80,22 @@ cmap_X_rawvalue cmap_X_value_toraw(cmap_X_value* pval); ``` Helpers: ```c -uint64_t c_strhash(const char *str); // utility function +uint64_t c_strhash(const char *str); // utility function int c_rawstr_compare(const char* const* a, const char* const* b); bool c_rawstr_equalto(const char* const* a, const char* const* b); uint64_t c_rawstr_hash(const char* const* strp, ...); -uint64_t c_default_hash(const void *data, size_t len); // key any trivial type -uint64_t c_default_hash32(const void* data, size_t is4); // key one 32bit int -uint64_t c_default_hash64(const void* data, size_t is8); // key one 64bit int +uint64_t c_default_hash(const void *data, size_t len); // key is any integral type +uint64_t c_hash32(const void* data, size_t is4); // key is one 32-bit int +uint64_t c_hash64(const void* data, size_t is8); // key is one 64-bit int bool c_default_equalto(const i_keyraw* a, const i_keyraw* b); // the == operator bool c_memcmp_equalto(const i_keyraw* a, const i_keyraw* b); // uses memcmp Type c_no_clone(Type val); -Type c_default_fromraw(Type val); // plain copy +Type c_default_fromraw(Type val); // plain copy Type c_default_toraw(Type* val); -void c_default_del(Type* val); // does nothing +void c_default_del(Type* val); // does nothing ``` ## Types diff --git a/include/stc/ccommon.h b/include/stc/ccommon.h index f71660b8..acf09dde 100644 --- a/include/stc/ccommon.h +++ b/include/stc/ccommon.h @@ -130,10 +130,12 @@ STC_INLINE uint64_t c_default_hash(const void* key, size_t len) { while (--len) h = (h << 10) - h + *x++; return _c_rotl(h, 26) ^ h; } -#define c_default_hash32(data, len_is_4) \ +#define c_hash32(data, len_is_4) \ ((*(const uint32_t*)data * 0xc6a4a7935bd1e99d) >> 15) -#define c_default_hash64(data, len_is_8) \ +#define c_hash64(data, len_is_8) \ (*(const uint64_t *)data * 0xc6a4a7935bd1e99d) +#define c_default_hash32 c_hash32 // [deprecated] +#define c_default_hash64 c_hash64 // [deprecated] #define c_foreach(...) c_MACRO_OVERLOAD(c_foreach, __VA_ARGS__) #define c_foreach_3(it, CX, cnt) \ -- cgit v1.2.3