diff options
| author | Tyge Løvset <[email protected]> | 2021-01-19 12:50:02 +0100 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2021-01-19 12:50:02 +0100 |
| commit | 60132bb5653cf5bd5cf5c0c331bf827456097af5 (patch) | |
| tree | d9c3212a9214ab7fd6549a48505dc270e6595e0a | |
| parent | 7fa5cd3a4092991268276259fa07fda2bb12cfc1 (diff) | |
| download | STC-modified-60132bb5653cf5bd5cf5c0c331bf827456097af5.tar.gz STC-modified-60132bb5653cf5bd5cf5c0c331bf827456097af5.zip | |
Changed template args sequence in cmap.
| -rw-r--r-- | benchmarks/cmap_benchmark.cpp | 2 | ||||
| -rw-r--r-- | benchmarks/cmap_benchmark2.cpp | 4 | ||||
| -rw-r--r-- | docs/cmap_api.md | 14 | ||||
| -rw-r--r-- | docs/csmap_api.md | 2 | ||||
| -rw-r--r-- | examples/advanced.c | 4 | ||||
| -rw-r--r-- | examples/complex.c | 2 | ||||
| -rw-r--r-- | examples/inits.c | 2 | ||||
| -rw-r--r-- | stc/cmap.h | 50 |
8 files changed, 39 insertions, 41 deletions
diff --git a/benchmarks/cmap_benchmark.cpp b/benchmarks/cmap_benchmark.cpp index bdbcb9c9..47f60b00 100644 --- a/benchmarks/cmap_benchmark.cpp +++ b/benchmarks/cmap_benchmark.cpp @@ -21,7 +21,7 @@ static inline uint32_t fibonacci_hash(const void* data, size_t len) { }
// cmap and khash template expansion
-using_cmap(ii, int64_t, int64_t, c_default_del, c_default_clone, c_default_equals, fibonacci_hash); // c_default_hash);
+using_cmap(ii, int64_t, int64_t, c_default_equals, fibonacci_hash); // c_default_hash);
KHASH_MAP_INIT_INT64(ii, int64_t)
diff --git a/benchmarks/cmap_benchmark2.cpp b/benchmarks/cmap_benchmark2.cpp index 14037719..6eedeb9f 100644 --- a/benchmarks/cmap_benchmark2.cpp +++ b/benchmarks/cmap_benchmark2.cpp @@ -41,8 +41,8 @@ DEFMAP(map_i, <int, int>); DEFMAP(map_x, <uint64_t, uint64_t>);
DEFMAP(map_s, <std::string, std::string>);
-using_cmap(i, int, int, c_default_del, c_default_clone, c_default_equals, hash32);
-using_cmap(x, uint64_t, uint64_t, c_default_del, c_default_clone, c_default_equals, hash64);
+using_cmap(i, int, int, c_default_equals, hash32);
+using_cmap(x, uint64_t, uint64_t, c_default_equals, hash64);
using_cmap_strkey(s, cstr, cstr_del, cstr_clone);
template <class MapInt>
diff --git a/docs/cmap_api.md b/docs/cmap_api.md index cbfa3d1c..c0fb81d2 100644 --- a/docs/cmap_api.md +++ b/docs/cmap_api.md @@ -8,10 +8,10 @@ See [std::unordered_map](https://en.cppreference.com/w/cpp/container/unordered_m ## Declaration ```c -#define using_cmap(X, Key, Mapped, mappedDestroy=c_default_del, - mappedClone=c_default_clone, - keyEqualsRaw=c_default_equals, +#define using_cmap(X, Key, Mapped, keyEqualsRaw=c_default_equals, keyHashRaw=c_default_hash, + mappedDestroy=c_default_del, + mappedClone=c_default_clone, keyDestroy=c_default_del, keyFromRaw=c_default_clone, keyToRaw=c_default_to_raw, @@ -202,9 +202,7 @@ Demonstrate cmap with plain-old-data key type Vec3i and int as mapped type: cmap typedef struct { int x, y, z; } Vec3i; -using_cmap(v3, Vec3i, int, c_default_del, // mapped: empty int destroy func - c_default_clone, // mapped: clone int by "memcpy" - c_mem_equals, // key: compare Vec3i bit-by-bit +using_cmap(v3, Vec3i, int, c_mem_equals, // key: compare Vec3i bit-by-bit c_default_hash32); // key: hash Vec3i in 32-bits word-by-word. int main() @@ -303,8 +301,8 @@ static inline VikingRaw viking_toRaw(Viking* vk) { // With this in place, we use the full using_cmap() macro to define {Viking -> int} hash map type: -using_cmap(vk, Viking, int, c_default_del, c_default_clone, - vikingraw_equals, vikingraw_hash, +using_cmap(vk, Viking, int, vikingraw_equals, vikingraw_hash, + c_default_del, c_default_clone, // mapped: int => use default. viking_del, viking_fromRaw, viking_toRaw, VikingRaw); int main() diff --git a/docs/csmap_api.md b/docs/csmap_api.md index 907c379a..f4cfcf48 100644 --- a/docs/csmap_api.md +++ b/docs/csmap_api.md @@ -25,7 +25,7 @@ See [std::map](https://en.cppreference.com/w/cpp/container/map) for a similar c+ RawKey=Key) #define using_csmap_str() ``` -The macro `using_csmap()` can be instantiated with 3, 5, 6, 8, or 10 arguments in the global scope. +The macro `using_csmap()` can be instantiated with 3, 4, 6, 8, or 10 arguments in the global scope. Default values are given above for args not specified. `X` is a type tag name and will affect the names of all csmap types and methods. E.g. declaring `using_csmap(my, int);`, `X` should be replaced by `my` in all of the following documentation. diff --git a/examples/advanced.c b/examples/advanced.c index f5a31587..753bba1e 100644 --- a/examples/advanced.c +++ b/examples/advanced.c @@ -38,8 +38,8 @@ static inline VikingRaw viking_toRaw(Viking* vk) { // With this in place, we use the full using_cmap() macro to define {Viking -> int} hash map type: -using_cmap(vk, Viking, int, c_default_del, c_default_clone, - vikingraw_equals, vikingraw_hash, +using_cmap(vk, Viking, int, vikingraw_equals, vikingraw_hash, + c_default_del, c_default_clone, viking_del, viking_fromRaw, viking_toRaw, VikingRaw); int main() diff --git a/examples/complex.c b/examples/complex.c index 16aa75b7..1346007a 100644 --- a/examples/complex.c +++ b/examples/complex.c @@ -7,7 +7,7 @@ void check_del(float* v) {printf("destroy %g\n", *v);} using_carray(f, float, check_del, c_default_clone); // normally omit the last 2 arguments - float type need no destroy.
using_clist(a, carray2f, c_no_compare, carray2f_del, carray2f_clone);
-using_cmap(l, int, clist_a, clist_a_del, clist_a_clone);
+using_cmap(l, int, clist_a, c_default_equals, c_default_hash, clist_a_del, clist_a_clone);
using_cmap_strkey(s, cmap_l, cmap_l_del, cmap_l_clone);
int main() {
diff --git a/examples/inits.c b/examples/inits.c index 320e5b9a..1ef722ea 100644 --- a/examples/inits.c +++ b/examples/inits.c @@ -5,7 +5,7 @@ #include <stc/cpque.h>
#include <stc/clist.h>
-using_cmap(id, int, cstr, cstr_del, cstr_clone); // Map of int -> cstr
+using_cmap(id, int, cstr, c_default_equals, c_default_hash, cstr_del, cstr_clone); // Map of int -> cstr
using_cmap_strkey(cnt, int);
typedef struct {int x, y;} ipair_t;
@@ -69,22 +69,22 @@ typedef struct {size_t idx; uint32_t hx;} cmap_bucket_t, cset_bucket_t; c_MACRO_OVERLOAD(using_cmap, __VA_ARGS__)
#define using_cmap_3(X, Key, Mapped) \
- using_cmap_5(X, Key, Mapped, c_default_del, c_default_clone)
+ using_cmap_5(X, Key, Mapped, c_default_equals, c_default_hash)
-#define using_cmap_5(X, Key, Mapped, mappedDel, mappedClone) \
- using_cmap_7(X, Key, Mapped, mappedDel, mappedClone, c_default_equals, c_default_hash)
+#define using_cmap_5(X, Key, Mapped, keyEquals, keyHash) \
+ using_cmap_7(X, Key, Mapped, keyEquals, keyHash, c_default_del, c_default_clone)
-#define using_cmap_7(X, Key, Mapped, mappedDel, mappedClone, keyEquals, keyHash) \
- using_cmap_9(X, Key, Mapped, mappedDel, mappedClone, keyEquals, keyHash, c_default_del, c_default_clone)
+#define using_cmap_7(X, Key, Mapped, keyEquals, keyHash, mappedDel, mappedClone) \
+ using_cmap_9(X, Key, Mapped, keyEquals, keyHash, mappedDel, mappedClone, c_default_del, c_default_clone)
-#define using_cmap_9(X, Key, Mapped, mappedDel, mappedClone, keyEquals, keyHash, keyDel, keyClone) \
- using_cmap_11(X, Key, Mapped, mappedDel, mappedClone, keyEquals, keyHash, keyDel, \
- keyClone, c_default_to_raw, Key)
+#define using_cmap_9(X, Key, Mapped, keyEquals, keyHash, mappedDel, mappedClone, keyDel, keyClone) \
+ using_cmap_11(X, Key, Mapped, keyEquals, keyHash, mappedDel, mappedClone, \
+ keyDel, keyClone, c_default_to_raw, Key)
-#define using_cmap_11(X, Key, Mapped, mappedDel, mappedClone, keyEqualsRaw, keyHashRaw, keyDel, \
- keyFromRaw, keyToRaw, RawKey) \
- _using_CHASH(X, cmap, Key, Mapped, mappedDel, keyEqualsRaw, keyHashRaw, keyDel, \
- keyFromRaw, keyToRaw, RawKey, mappedClone, c_default_to_raw, Mapped)
+#define using_cmap_11(X, Key, Mapped, keyEqualsRaw, keyHashRaw, mappedDel, mappedClone, \
+ keyDel, keyFromRaw, keyToRaw, RawKey) \
+ _using_CHASH(X, cmap, Key, Mapped, keyEqualsRaw, keyHashRaw, mappedDel, mappedClone, \
+ keyDel, keyFromRaw, keyToRaw, RawKey, c_default_to_raw, Mapped)
/* cset: */
#define using_cset(...) \
@@ -100,15 +100,15 @@ typedef struct {size_t idx; uint32_t hx;} cmap_bucket_t, cset_bucket_t; using_cset_8(X, Key, keyEquals, keyHash, keyDel, keyClone, c_default_to_raw, Key)
#define using_cset_8(X, Key, keyEqualsRaw, keyHashRaw, keyDel, keyFromRaw, keyToRaw, RawKey) \
- _using_CHASH(X, cset, Key, Key, _UNUSED_, keyEqualsRaw, keyHashRaw, keyDel, \
- keyFromRaw, keyToRaw, RawKey, _UNUSED_, _UNUSED_, void)
+ _using_CHASH(X, cset, Key, Key, keyEqualsRaw, keyHashRaw, _UNUSED_, _UNUSED_, \
+ keyDel, keyFromRaw, keyToRaw, RawKey, _UNUSED_, void)
/* cset_str, cmap_str, cmap_strkey, cmap_strval: */
#define using_cset_str() \
_using_CHASH_strkey(str, cset, cstr_t, _UNUSED_, _UNUSED_)
#define using_cmap_str() \
- _using_CHASH(str, cmap, cstr_t, cstr_t, cstr_del, cstr_equals_raw, cstr_hash_raw, cstr_del, \
- cstr_from, cstr_to_raw, const char*, cstr_from, cstr_to_raw, const char*)
+ _using_CHASH(str, cmap, cstr_t, cstr_t, cstr_equals_raw, cstr_hash_raw, cstr_del, cstr_from, \
+ cstr_del, cstr_from, cstr_to_raw, const char*, cstr_to_raw, const char*)
#define using_cmap_strkey(...) \
c_MACRO_OVERLOAD(using_cmap_strkey, __VA_ARGS__)
@@ -130,12 +130,12 @@ typedef struct {size_t idx; uint32_t hx;} cmap_bucket_t, cset_bucket_t; using_cmap_strval_8(X, Key, keyEquals, keyHash, keyDel, keyClone, c_default_to_raw, Key)
#define using_cmap_strval_8(X, Key, keyEquals, keyHash, keyDel, keyFromRaw, keyToRaw, RawKey) \
- _using_CHASH(X, cmap, Key, cstr_t, cstr_del, keyEquals, keyHash, keyDel, \
- keyFromRaw, keyToRaw, RawKey, cstr_from, cstr_to_raw, const char*)
+ _using_CHASH(X, cmap, Key, cstr_t, keyEquals, keyHash, cstr_del, cstr_from, \
+ keyDel, keyFromRaw, keyToRaw, RawKey, cstr_to_raw, const char*)
#define _using_CHASH_strkey(X, C, Mapped, mappedDel, mappedClone) \
- _using_CHASH(X, C, cstr_t, Mapped, mappedDel, cstr_equals_raw, cstr_hash_raw, cstr_del, \
- cstr_from, cstr_to_raw, const char*, mappedClone, c_default_to_raw, Mapped)
+ _using_CHASH(X, C, cstr_t, Mapped, cstr_equals_raw, cstr_hash_raw, mappedDel, mappedClone, \
+ cstr_del, cstr_from, cstr_to_raw, const char*, c_default_to_raw, Mapped)
#define SET_ONLY_cset(...) __VA_ARGS__
#define SET_ONLY_cmap(...)
@@ -144,8 +144,8 @@ typedef struct {size_t idx; uint32_t hx;} cmap_bucket_t, cset_bucket_t; #define KEY_REF_cset(vp) (vp)
#define KEY_REF_cmap(vp) (&(vp)->first)
-#define _using_CHASH(X, C, Key, Mapped, mappedDel, keyEqualsRaw, keyHashRaw, keyDel, \
- keyFromRaw, keyToRaw, RawKey, mappedFromRaw, mappedToRaw, RawMapped) \
+#define _using_CHASH(X, C, Key, Mapped, keyEqualsRaw, keyHashRaw, mappedDel, mappedFromRaw, \
+ keyDel, keyFromRaw, keyToRaw, RawKey, mappedToRaw, RawMapped) \
typedef Key C##_##X##_key_t; \
typedef Mapped C##_##X##_mapped_t; \
typedef RawKey C##_##X##_rawkey_t; \
@@ -307,14 +307,14 @@ typedef struct {size_t idx; uint32_t hx;} cmap_bucket_t, cset_bucket_t; STC_API uint32_t c_default_hash(const void *data, size_t len); \
STC_API uint32_t c_default_hash32(const void* data, size_t len); \
\
- _implement_CHASH(X, C, Key, Mapped, mappedDel, keyEqualsRaw, keyHashRaw, keyDel, \
+ _implement_CHASH(X, C, Key, Mapped, keyEqualsRaw, keyHashRaw, mappedDel, keyDel, \
keyFromRaw, keyToRaw, RawKey, mappedFromRaw, mappedToRaw, RawMapped) \
typedef C##_##X C##_##X##_t
/* -------------------------- IMPLEMENTATION ------------------------- */
#if !defined(STC_HEADER) || defined(STC_IMPLEMENTATION)
-#define _implement_CHASH(X, C, Key, Mapped, mappedDel, keyEqualsRaw, keyHashRaw, keyDel, \
+#define _implement_CHASH(X, C, Key, Mapped, keyEqualsRaw, keyHashRaw, mappedDel, keyDel, \
keyFromRaw, keyToRaw, RawKey, mappedFromRaw, mappedToRaw, RawMapped) \
STC_DEF C##_##X \
C##_##X##_with_capacity(size_t cap) { \
@@ -462,7 +462,7 @@ STC_DEF uint32_t c_default_hash32(const void* data, size_t len) { }
#else
-#define _implement_CHASH(X, C, Key, Mapped, mappedDel, keyEqualsRaw, keyHashRaw, keyDel, \
+#define _implement_CHASH(X, C, Key, Mapped, keyEqualsRaw, keyHashRaw, mappedDel, keyDel, \
keyFromRaw, keyToRaw, RawKey, mappedFromRaw, mappedToRaw, RawMapped)
#endif
|
