diff options
| author | Tyge Løvset <[email protected]> | 2021-10-05 09:00:28 +0200 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2021-10-05 09:05:25 +0200 |
| commit | bf00ed0e7023cf49cf004dd4b4b39af2b824681e (patch) | |
| tree | adadcc1ac34fd5b614e566028d37d29db8fb7f80 | |
| parent | 88c67afa63e46551c67f573e0557323518c42f81 (diff) | |
| download | STC-modified-bf00ed0e7023cf49cf004dd4b4b39af2b824681e.tar.gz STC-modified-bf00ed0e7023cf49cf004dd4b4b39af2b824681e.zip | |
Changed recommended order of defining template parameters.
48 files changed, 126 insertions, 120 deletions
diff --git a/benchmarks/clist_benchmark.cpp b/benchmarks/clist_benchmark.cpp index 8151afa9..525bcc5a 100644 --- a/benchmarks/clist_benchmark.cpp +++ b/benchmarks/clist_benchmark.cpp @@ -16,8 +16,8 @@ uint64_t seed = 1, mask1 = 0xfffffff, mask2 = 0xffff; static float secs(Range s) { return (float)(s.t2 - s.t1) / CLOCKS_PER_SEC; }
-#define i_tag x
#define i_val size_t
+#define i_tag x
#include <stc/clist.h>
#ifdef __cplusplus
diff --git a/benchmarks/cmap_benchmark.cpp b/benchmarks/cmap_benchmark.cpp index 6e0ef325..d94f2f24 100644 --- a/benchmarks/cmap_benchmark.cpp +++ b/benchmarks/cmap_benchmark.cpp @@ -15,10 +15,10 @@ uint64_t seed = 1, mask1 = 0xffffffff; static float secs(Range s) { return (float)(s.t2 - s.t1) / CLOCKS_PER_SEC; }
-#define i_tag x
#define i_key size_t
#define i_val size_t
#define i_hash c_default_hash64
+#define i_tag x
#include <stc/cmap.h>
#ifdef __cplusplus
diff --git a/benchmarks/cpque_benchmark.cpp b/benchmarks/cpque_benchmark.cpp index 5f7dd364..19a9c701 100644 --- a/benchmarks/cpque_benchmark.cpp +++ b/benchmarks/cpque_benchmark.cpp @@ -2,9 +2,9 @@ #include <time.h>
#include <stc/crandom.h>
-#define i_tag f
#define i_val float
#define i_cmp -c_default_compare
+#define i_tag f
#include <stc/cpque.h>
int main()
diff --git a/benchmarks/csmap_benchmark.cpp b/benchmarks/csmap_benchmark.cpp index 18af9a34..fa1e10cf 100644 --- a/benchmarks/csmap_benchmark.cpp +++ b/benchmarks/csmap_benchmark.cpp @@ -15,9 +15,9 @@ uint64_t seed = 1, mask1 = 0xfffffff; static float secs(Range s) { return (float)(s.t2 - s.t1) / CLOCKS_PER_SEC; }
-#define i_tag x
#define i_key size_t
#define i_val size_t
+#define i_tag x
#include <stc/csmap.h>
#ifdef __cplusplus
diff --git a/benchmarks/cvec_benchmark.cpp b/benchmarks/cvec_benchmark.cpp index 5cc2fb34..f7755cf6 100644 --- a/benchmarks/cvec_benchmark.cpp +++ b/benchmarks/cvec_benchmark.cpp @@ -16,8 +16,8 @@ uint64_t seed = 1, mask1 = 0xfffffff, mask2 = 0xffff; static float secs(Range s) { return (float)(s.t2 - s.t1) / CLOCKS_PER_SEC; }
-#define i_tag x
#define i_val size_t
+#define i_tag x
#include <stc/cvec.h>
#ifdef __cplusplus
diff --git a/benchmarks/shootout1_cmap.cpp b/benchmarks/shootout1_cmap.cpp index 2cdb919f..fab25096 100644 --- a/benchmarks/shootout1_cmap.cpp +++ b/benchmarks/shootout1_cmap.cpp @@ -35,16 +35,16 @@ DEFMAP(map_i, <int, int>); DEFMAP(map_x, <uint64_t, uint64_t>);
DEFMAP(map_s, <std::string, std::string>);
-#define i_tag i
#define i_key int
#define i_val int
#define i_hash c_default_hash32
+#define i_tag i
#include <stc/cmap.h>
-#define i_tag x
#define i_key size_t
#define i_val size_t
#define i_hash c_default_hash64
+#define i_tag x
#include <stc/cmap.h>
#define i_key_str
diff --git a/benchmarks/shootout2_cmap.cpp b/benchmarks/shootout2_cmap.cpp index 77d458bc..fb24465a 100644 --- a/benchmarks/shootout2_cmap.cpp +++ b/benchmarks/shootout2_cmap.cpp @@ -16,10 +16,10 @@ template<typename C> inline void destroy_me(C& c) { C().swap(c); } // Visual Studio: compile with -TP to force C++: cl -TP -EHsc -O2 benchmark.c
// cmap and khash template expansion
-#define i_tag ii
#define i_key int64_t
#define i_val int64_t
#define i_cmp c_default_hash64
+#define i_tag ii
#include <stc/cmap.h>
KHASH_MAP_INIT_INT64(ii, int64_t)
diff --git a/benchmarks/shootout3_csmap.cpp b/benchmarks/shootout3_csmap.cpp index 35abf8a8..3682c874 100644 --- a/benchmarks/shootout3_csmap.cpp +++ b/benchmarks/shootout3_csmap.cpp @@ -15,14 +15,14 @@ using omap_i = std::map<int, int>; using omap_x = std::map<uint64_t, uint64_t>;
using omap_s = std::map<std::string, std::string>;
-#define i_tag i
#define i_key int
#define i_val int
+#define i_tag i
#include <stc/csmap.h>
-#define i_tag x
#define i_key size_t
#define i_val size_t
+#define i_tag x
#include <stc/csmap.h>
#define i_key_str
diff --git a/docs/carray_api.md b/docs/carray_api.md index b567d8aa..d7ece0fa 100644 --- a/docs/carray_api.md +++ b/docs/carray_api.md @@ -9,11 +9,11 @@ See the c++ class [boost::multi_array](https://www.boost.org/doc/libs/release/li ## Header file and declaration ```c -#define i_tag // defaults to i_val name #define i_val // value: REQUIRED +#define i_del // destroy value func - defaults to empty destruct #define i_valfrom // func Raw => i_val - defaults to plain copy #define i_valto // func i_val => Raw - defaults to plain copy -#define i_valdel // destroy value func - defaults to empty destruct +#define i_tag // defaults to i_val #include <stc/carr2.h> // or <stc/carr3.h> ``` @@ -75,12 +75,12 @@ The **carr3** elements can be accessed like `carr3_i arr = ...; int val = arr.da ```c #include <stdio.h> -#define i_tag i #define i_val uint32_t +#define i_tag i #include <stc/carr2.h> -#define i_tag f #define i_val float +#define i_tag f #include <stc/carr3.h> int main() diff --git a/docs/cdeq_api.md b/docs/cdeq_api.md index bacb2f86..26a6bbff 100644 --- a/docs/cdeq_api.md +++ b/docs/cdeq_api.md @@ -8,13 +8,13 @@ See the c++ class [std::deque](https://en.cppreference.com/w/cpp/container/deque ## Header file and declaration ```c -#define i_tag // defaults to i_val name #define i_val // value: REQUIRED #define i_cmp // three-way compare two i_valraw* : REQUIRED IF i_valraw is a non-integral type +#define i_del // destroy value func - defaults to empty destruct #define i_valraw // convertion "raw" type - defaults to i_val #define i_valfrom // convertion func i_valraw => i_val - defaults to plain copy #define i_valto // convertion func i_val* => i_valraw - defaults to plain copy -#define i_valdel // destroy value func - defaults to empty destruct +#define i_tag // defaults to i_val #include <stc/cdeq.h> ``` `X` should be replaced by the value of `i_tag` in all of the following documentation. @@ -94,8 +94,8 @@ cdeq_X_value_t cdeq_X_value_clone(cdeq_X_value_t val); ## Examples ```c -#define i_tag i #define i_val int +#define i_tag i #include <stc/cdeq.h> #include <stdio.h> diff --git a/docs/clist_api.md b/docs/clist_api.md index e1b8f0b1..7ef12153 100644 --- a/docs/clist_api.md +++ b/docs/clist_api.md @@ -22,13 +22,13 @@ See the c++ class [std::list](https://en.cppreference.com/w/cpp/container/list) ## Header file and declaration ```c -#define i_tag // defaults to i_val name #define i_val // value: REQUIRED #define i_cmp // three-way compare two i_valraw* : REQUIRED IF i_valraw is a non-integral type +#define i_del // destroy value func - defaults to empty destruct #define i_valraw // convertion "raw" type - defaults to i_val #define i_valfrom // convertion func i_valraw => i_val - defaults to plain copy #define i_valto // convertion func i_val* => i_valraw - defaults to plain copy -#define i_valdel // destroy value func - defaults to empty destruct +#define i_tag // defaults to i_val #include <stc/clist.h> ``` @@ -96,9 +96,10 @@ clist_X_value_t clist_X_value_clone(clist_X_value_t val); Interleave *push_front()* / *push_back()* then *sort()*: ```c -#define i_tag d #define i_val double +#define i_tag d #include <stc/clist.h> + #include <stdio.h> int main() { diff --git a/docs/cmap_api.md b/docs/cmap_api.md index 08f551e6..0146ff49 100644 --- a/docs/cmap_api.md +++ b/docs/cmap_api.md @@ -17,19 +17,19 @@ See the c++ class [std::unordered_map](https://en.cppreference.com/w/cpp/contain ## Header file and declaration ```c -#define i_tag // defaults to i_key name #define i_key // key: REQUIRED #define i_val // value: REQUIRED -#define i_equ // equality comparison two i_keyraw*. REQUIRED IF i_keyraw is non-integral type -#define i_cmp // three-way compare two i_keyraw* : may be defined instead of i_equ +#define i_cmp // three-way compare two i_keyraw*: REQUIRED IF i_keyraw is non-integral type +#define i_equ // equality comparison two i_keyraw*: ALTERNATIVE to i_cmp +#define i_keydel // destroy key func - defaults to empty destruct #define i_keyraw // convertion "raw" type - defaults to i_key #define i_keyfrom // convertion func i_keyraw => i_key - defaults to plain copy #define i_keyto // convertion func i_key* => i_keyraw - defaults to plain copy -#define i_keydel // destroy key func - defaults to empty destruct +#define i_valdel // destroy value func - defaults to empty destruct #define i_valraw // convertion "raw" type - defaults to i_val #define i_valfrom // convertion func i_valraw => i_val - defaults to plain copy #define i_valto // convertion func i_val* => i_valraw - defaults to plain copy -#define i_valdel // destroy value func - defaults to empty destruct +#define i_tag // defaults to i_key #include <stc/cmap.h> ``` `X` should be replaced by the value of `i_tag` in all of the following documentation. @@ -161,9 +161,9 @@ This example uses a cmap with cstr as mapped value. ```c #include <stc/cstr.h> -#define i_tag id #define i_key int #define i_val_str +#define i_tag id #include <stc/cmap.h> int main() @@ -201,10 +201,10 @@ Demonstrate cmap with plain-old-data key type Vec3i and int as mapped type: cmap #include <stdio.h> typedef struct { int x, y, z; } Vec3i; -#define i_tag vi #define i_key Vec3i #define i_val int -#define i_cmp c_memcmp_equals // bitwise equals, uses c_default_hash +#define i_cmp c_memcmp_equals // bitwise compare, and use c_default_hash +#define i_tag vi #include <stc/cmap.h> int main() @@ -236,9 +236,9 @@ Inverse: demonstrate cmap with mapped POD type Vec3i: cmap<int, Vec3i>: #include <stdio.h> typedef struct { int x, y, z; } Vec3i; -#define i_tag iv #define i_key int #define i_val Vec3i +#define i_tag iv #include <stc/cmap.h> int main() @@ -285,12 +285,12 @@ static void Viking_del(Viking* v) { c_del(cstr, &v->name, &v->country); } -#define i_tag vk #define i_key Viking #define i_val int #define i_equ Viking_equals #define i_hash Viking_hash -#define i_keydel Viking_del +#define i_del Viking_del +#define i_tag vk #include <stc/cmap.h> int main() @@ -358,15 +358,15 @@ static Viking Viking_fromR(RViking r) static RViking Viking_toR(const Viking* v) { return (RViking){v->name.str, v->country.str}; } -#define i_tag vk #define i_key Viking #define i_val int #define i_equ RViking_equals #define i_hash RViking_hash +#define i_keydel Viking_del #define i_keyraw RViking #define i_keyfrom Viking_fromR #define i_keyto Viking_toR -#define i_keydel Viking_del +#define i_tag vk #include <stc/cmap.h> int main() diff --git a/docs/cpque_api.md b/docs/cpque_api.md index 4e58a323..4f22fe0e 100644 --- a/docs/cpque_api.md +++ b/docs/cpque_api.md @@ -8,13 +8,13 @@ See the c++ class [std::priority_queue](https://en.cppreference.com/w/cpp/contai ## Header file and declaration ```c -#define i_tag // defaults to i_val name #define i_val // value: REQUIRED #define i_cmp // three-way compare two i_valraw* : REQUIRED IF i_valraw is a non-integral type +#define i_del // destroy value func - defaults to empty destruct #define i_valraw // convertion "raw" type - defaults to i_val #define i_valfrom // convertion func i_valraw => i_val - defaults to plain copy #define i_valto // convertion func i_val* => i_valraw - defaults to plain copy -#define i_valdel // destroy value func - defaults to empty destruct +#define i_tag // defaults to i_val #include <stc/cpque.h> ``` `X` should be replaced by the value of `i_tag` in all of the following documentation. @@ -58,9 +58,9 @@ cpque_X_value_t cpque_X_value_clone(cpque_X_value_t val); #include <stc/crandom.h> #include <stdio.h> -#define i_tag i #define i_val int64_t #define i_cmp -c_default_compare // min-heap +#define i_tag i #include <stc/cpque.h> int main() diff --git a/docs/cqueue_api.md b/docs/cqueue_api.md index d5843614..76c189e5 100644 --- a/docs/cqueue_api.md +++ b/docs/cqueue_api.md @@ -7,13 +7,13 @@ See the c++ class [std::queue](https://en.cppreference.com/w/cpp/container/queue ## Header file and declaration ```c -#define i_tag // defaults to i_val name #define i_val // value: REQUIRED #define i_cmp // three-way compare two i_valraw* : REQUIRED IF i_valraw is a non-integral type +#define i_del // destroy value func - defaults to empty destruct #define i_valraw // convertion "raw" type - defaults to i_val #define i_valfrom // convertion func i_valraw => i_val - defaults to plain copy #define i_valto // convertion func i_val* => i_valraw - defaults to plain copy -#define i_valdel // destroy value func - defaults to empty destruct +#define i_tag // defaults to i_val #include <stc/cqueue.h> ``` `X` should be replaced by the value of `i_tag` in all of the following documentation. @@ -57,8 +57,8 @@ cqueue_X_value_t cqueue_X_value_clone(cqueue_X_value_t val); ## Examples ```c -#define i_tag i #define i_val int +#define i_tag i #include <stc/cqueue.h> #include <stdio.h> diff --git a/docs/crandom_api.md b/docs/crandom_api.md index 6398e197..3dd829aa 100644 --- a/docs/crandom_api.md +++ b/docs/crandom_api.md @@ -74,9 +74,9 @@ double stc64_normalf(stc64_t* rng, stc64_normalf_t* dist); #include <stc/cstr.h> // Declare int -> int sorted map. Uses typetag 'i' for ints. -#define i_tag i #define i_key int #define i_val size_t +#define i_tag i #include <stc/csmap.h> int main() diff --git a/docs/cset_api.md b/docs/cset_api.md index d6c4ab80..e09436ea 100644 --- a/docs/cset_api.md +++ b/docs/cset_api.md @@ -7,15 +7,15 @@ A **cset** is an associative container that contains a set of unique objects of ## Header file and declaration
```c
-#define i_tag // defaults to i_key name
#define i_key // key: REQUIRED
#define i_hash // hash func: REQUIRED IF i_keyraw is a non-pod type
-#define i_equ // equality comparison two i_keyraw*. REQUIRED IF i_keyraw is a non-integral type
-#define i_cmp // three-way compare two i_keyraw* : alternative to i_equ
+#define i_cmp // three-way compare two i_keyraw*: REQUIRED IF i_keyraw is a non-integral type
+#define i_equ // equality comparison two i_keyraw*: ALTERNATIVE to i_cmp
+#define i_del // destroy key func - defaults to empty destruct
#define i_keyraw // convertion "raw" type - defaults to i_key
#define i_keyfrom // convertion func i_keyraw => i_key - defaults to plain copy
#define i_keyto // convertion func i_key* => i_keyraw - defaults to plain copy
-#define i_keydel // destroy key func - defaults to empty destruct
+#define i_tag // defaults to i_key
#include <stc/cset.h>
```
`X` should be replaced by the value of `i_tag` in all of the following documentation.
diff --git a/docs/csmap_api.md b/docs/csmap_api.md index a1d3a5c7..46d5eff7 100644 --- a/docs/csmap_api.md +++ b/docs/csmap_api.md @@ -15,18 +15,18 @@ See the c++ class [std::map](https://en.cppreference.com/w/cpp/container/map) fo ## Header file and declaration ```c -#define i_tag // defaults to i_key name #define i_key // key: REQUIRED #define i_val // value: REQUIRED #define i_cmp // three-way compare two i_keyraw* : REQUIRED IF i_keyraw is a non-integral type +#define i_keydel // destroy key func - defaults to empty destruct #define i_keyraw // convertion "raw" type - defaults to i_key #define i_keyfrom // convertion func i_keyraw => i_key - defaults to plain copy #define i_keyto // convertion func i_key* => i_keyraw - defaults to plain copy -#define i_keydel // destroy key func - defaults to empty destruct +#define i_valdel // destroy value func - defaults to empty destruct #define i_valraw // convertion "raw" type - defaults to i_val #define i_valfrom // convertion func i_valraw => i_val - defaults to plain copy #define i_valto // convertion func i_val* => i_valraw - defaults to plain copy -#define i_valdel // destroy value func - defaults to empty destruct +#define i_tag // defaults to i_key #include <stc/csmap.h> ``` `X` should be replaced by the value of `i_tag` in all of the following documentation. @@ -132,9 +132,9 @@ This example uses a csmap with cstr as mapped value. ```c #include <stc/cstr.h> -#define i_tag id #define i_key int #define i_val_str +#define i_tag id #include <stc/csmap.h> int main() @@ -145,7 +145,7 @@ int main() {100, "Red"}, {110, "Blue"}, }); - c_autoscope (0, csmap_id_del(&idnames)) + c_autodefer (csmap_id_del(&idnames)) { // put replaces existing mapped value: csmap_id_emplace_or_assign(&idnames, 110, "White"); @@ -178,10 +178,10 @@ static int Vec3i_compare(const Vec3i* a, const Vec3i* b) { return (a->z > b->z) - (a->z < b->z); } -#define i_tag vi #define i_key Vec3i #define i_val int #define i_cmp Vec3i_compare // uses c_default_hash +#define i_tag vi #include <stc/csmap.h> #include <stdio.h> diff --git a/docs/csptr_api.md b/docs/csptr_api.md index 026ce6c3..bd9bf7d2 100644 --- a/docs/csptr_api.md +++ b/docs/csptr_api.md @@ -26,10 +26,10 @@ See the c++ classes [std::shared_ptr](https://en.cppreference.com/w/cpp/memory/s ## Header file and declaration ```c -#define i_tag // defaults to i_val name #define i_val // value: REQUIRED #define i_cmp // three-way compare two i_val* : REQUIRED IF i_val is a non-integral type -#define i_valdel // destroy value func - defaults to empty destruct +#define i_del // destroy value func - defaults to empty destruct +#define i_tag // defaults to i_val #include <stc/csptr.h> ``` `X` should be replaced by the value of `i_tag` in all of the following documentation. diff --git a/docs/csset_api.md b/docs/csset_api.md index f7cf0dc4..67ff1911 100644 --- a/docs/csset_api.md +++ b/docs/csset_api.md @@ -8,13 +8,13 @@ See the c++ class [std::set](https://en.cppreference.com/w/cpp/container/set) fo ## Header file and declaration
```c
-#define i_tag // defaults to i_key name
#define i_key // key: REQUIRED
#define i_cmp // three-way compare two i_keyraw* : REQUIRED IF i_keyraw is a non-integral type
+#define i_del // destroy key func - defaults to empty destruct
#define i_keyraw // convertion "raw" type - defaults to i_key
#define i_keyfrom // convertion func i_keyraw => i_key - defaults to plain copy
#define i_keyto // convertion func i_key* => i_keyraw - defaults to plain copy
-#define i_keydel // destroy key func - defaults to empty destruct
+#define i_tag // defaults to i_key
#include <stc/csset.h>
```
`X` should be replaced by the value of `i_tag` in all of the following documentation.
diff --git a/docs/cstack_api.md b/docs/cstack_api.md index 91fa7de5..31f6ade7 100644 --- a/docs/cstack_api.md +++ b/docs/cstack_api.md @@ -8,13 +8,13 @@ See the c++ class [std::stack](https://en.cppreference.com/w/cpp/container/stack ## Header file and declaration ```c -#define i_tag // defaults to i_val name #define i_val // value: REQUIRED #define i_cmp // three-way compare two i_valraw* : REQUIRED IF i_valraw is a non-integral type +#define i_del // destroy value func - defaults to empty destruct #define i_valraw // convertion "raw" type - defaults to i_val #define i_valfrom // convertion func i_valraw => i_val - defaults to plain copy #define i_valto // convertion func i_val* => i_valraw - defaults to plain copy -#define i_valdel // destroy value func - defaults to empty destruct +#define i_tag // defaults to i_val name #include <stc/cstack.h> ``` `X` should be replaced by the value of `i_tag` in all of the following documentation. @@ -59,9 +59,10 @@ cstack_X_value_t cstack_X_value_clone(cstack_X_value_t val); ## Example ```c -#define i_tag i #define i_val int +#define i_tag i #include <stc/cstack.h> + #include <stdio.h> int main() { diff --git a/docs/cvec_api.md b/docs/cvec_api.md index ee02950f..549bce2a 100644 --- a/docs/cvec_api.md +++ b/docs/cvec_api.md @@ -12,13 +12,13 @@ See the c++ class [std::vector](https://en.cppreference.com/w/cpp/container/vect ## Header file and declaration ```c -#define i_tag // defaults to i_val name #define i_val // value: REQUIRED #define i_cmp // three-way compare two i_valraw* : REQUIRED IF i_valraw is a non-integral type +#define i_del // destroy value func - defaults to empty destruct #define i_valraw // convertion "raw" type - defaults to i_val #define i_valfrom // convertion func i_valraw => i_val - defaults to plain copy #define i_valto // convertion func i_val* => i_valraw - defaults to plain copy -#define i_valdel // destroy value func - defaults to empty destruct +#define i_tag // defaults to i_val #include <stc/cvec.h> ``` `X` should be replaced by the value of `i_tag` in all of the following documentation. @@ -99,9 +99,10 @@ cvec_X_value_t cvec_X_value_clone(cvec_X_value_t val); ## Examples ```c -#define i_tag i #define i_val int +#define i_tag i #include <stc/cvec.h> + #include <stdio.h> int main() @@ -192,12 +193,13 @@ User User_clone(User user) { return user; } -// declare a memory managed, clonable vector of users: -#define i_tag u +// Declare a memory managed, clonable vector of users. +// Note that cvec_u_emplace_back() will clone input: #define i_val User #define i_cmp User_compare -#define i_valdel User_del +#define i_del User_del #define i_valfrom User_clone +#define i_tag u #include <stc/cvec.h> int main(void) { diff --git a/examples/astar.c b/examples/astar.c index 5316b954..8c37d070 100644 --- a/examples/astar.c +++ b/examples/astar.c @@ -64,16 +64,16 @@ point_key_compare(const point* a, const point* b) #define i_cmp c_no_compare
#include <stc/cdeq.h>
-#define i_tag pcost
#define i_key point
#define i_val int
#define i_cmp point_key_compare
+#define i_tag pcost
#include <stc/csmap.h>
-#define i_tag pstep
#define i_key point
#define i_val point
#define i_cmp point_key_compare
+#define i_tag pstep
#include <stc/csmap.h>
cdeq_point
diff --git a/examples/birthday.c b/examples/birthday.c index 242ce78a..f9b777c0 100644 --- a/examples/birthday.c +++ b/examples/birthday.c @@ -29,9 +29,9 @@ static void test_repeats(void) }
}
-#define i_tag x
#define i_key uint32_t
#define i_val uint64_t
+#define i_tag x
#include <stc/cmap.h>
void test_distribution(void)
diff --git a/examples/complex.c b/examples/complex.c index e7789815..c910be80 100644 --- a/examples/complex.c +++ b/examples/complex.c @@ -2,27 +2,27 @@ void check_del(float* v) {printf("destroy %g\n", *v);}
-#define i_tag f
#define i_val float
#define i_valdel check_del
+#define i_tag f
#include <stc/cstack.h>
-#define i_tag arr
#define i_val cstack_f
#define i_cmp c_no_compare
#define i_valdel cstack_f_del
+#define i_tag arr
#include <stc/clist.h>
-#define i_tag lst
#define i_key int
#define i_val clist_arr
#define i_valdel clist_arr_del
+#define i_tag lst
#include <stc/cmap.h>
-#define i_tag map
#define i_key_str
#define i_val cmap_lst
#define i_valdel cmap_lst_del
+#define i_tag map
#include <stc/cmap.h>
// c++:
diff --git a/examples/cpque.c b/examples/cpque.c index eabf11d0..541dcb6e 100644 --- a/examples/cpque.c +++ b/examples/cpque.c @@ -7,8 +7,8 @@ static int (*icmp_fn)(const int* x, const int* y);
#define i_val int
-#define i_cnt ipque
#define i_cmp icmp_fn
+#define i_cnt ipque
#include <stc/cpque.h>
#define imix_less(x, y) ((*(x) ^ 1) < (*(y) ^ 1))
diff --git a/examples/csmap_find.c b/examples/csmap_find.c index eca14c52..39ffd975 100644 --- a/examples/csmap_find.c +++ b/examples/csmap_find.c @@ -2,14 +2,14 @@ // https://docs.microsoft.com/en-us/cpp/standard-library/map-class?view=msvc-160#example-17 #include <stc/cstr.h> -#define i_tag istr #define i_key int #define i_val_str +#define i_tag istr #include <stc/csmap.h> -#define i_tag istr #define i_val csmap_istr_rawvalue_t #define i_cmp c_no_compare +#define i_tag istr #include <stc/cvec.h> void print_elem(csmap_istr_rawvalue_t p) { diff --git a/examples/csmap_insert.c b/examples/csmap_insert.c index ede1e5f0..939f2eca 100644 --- a/examples/csmap_insert.c +++ b/examples/csmap_insert.c @@ -4,19 +4,19 @@ // This implements the std::map insert c++ example at:
// https://docs.microsoft.com/en-us/cpp/standard-library/map-class?view=msvc-160#example-19
-#define i_tag ii // Map of int => int
#define i_key int
#define i_val int
+#define i_tag ii // Map of int => int
#include <stc/csmap.h>
-#define i_tag istr // Map of int => cstr
#define i_key int
#define i_val_str
+#define i_tag istr // Map of int => cstr
#include <stc/csmap.h>
-#define i_tag ii
#define i_val csmap_ii_rawvalue_t
#define i_cmp c_no_compare
+#define i_tag ii
#include <stc/cvec.h>
void print_ii(csmap_ii map) {
diff --git a/examples/demos.c b/examples/demos.c index a874d38d..ab1a95ff 100644 --- a/examples/demos.c +++ b/examples/demos.c @@ -28,8 +28,8 @@ void stringdemo1() }
}
-#define i_tag ix
#define i_val int64_t
+#define i_tag ix
#include <stc/cvec.h>
void vectordemo1()
@@ -72,8 +72,8 @@ void vectordemo2() }
}
-#define i_tag ix
#define i_val int
+#define i_tag ix
#include <stc/clist.h>
void listdemo1()
@@ -106,8 +106,8 @@ void listdemo1() }
}
-#define i_tag i
#define i_key int
+#define i_tag i
#include <stc/cset.h>
void setdemo1()
@@ -122,9 +122,9 @@ void setdemo1() cset_i_del(&nums);
}
-#define i_tag ii
#define i_key int
#define i_val int
+#define i_tag ii
#include <stc/cmap.h>
void mapdemo1()
@@ -137,9 +137,9 @@ void mapdemo1() cmap_ii_del(&nums);
}
-#define i_tag si
#define i_key_str
#define i_val int
+#define i_tag si
#include <stc/cmap.h>
void mapdemo2()
@@ -186,8 +186,8 @@ void mapdemo3() }
//#define i_prefix carray3 // backward compatible.
-#define i_tag f
#define i_val float
+#define i_tag f
#include <stc/carr3.h>
void arraydemo1()
diff --git a/examples/ex_gauss1.c b/examples/ex_gauss1.c index 42337d3b..c96562b6 100644 --- a/examples/ex_gauss1.c +++ b/examples/ex_gauss1.c @@ -5,9 +5,9 @@ #include <stc/cstr.h>
// Declare int -> int hashmap. Uses typetag 'ii' for ints.
-#define i_tag ii
#define i_key int32_t
#define i_val size_t
+#define i_tag ii
#include <stc/cmap.h>
// Declare int vector with map entries that can be sorted by map keys.
@@ -16,9 +16,9 @@ static int compare(mapval *a, mapval *b) { return c_default_compare(&a->first, &b->first);
}
-#define i_tag pair
#define i_val mapval
#define i_cmp compare
+#define i_tag pair
#include <stc/cvec.h>
int main()
diff --git a/examples/inits.c b/examples/inits.c index 47d01dac..be0914c2 100644 --- a/examples/inits.c +++ b/examples/inits.c @@ -1,14 +1,14 @@ #include <stdio.h>
#include <stc/cstr.h>
-#define i_tag id // Map of int => cstr
#define i_key int
#define i_val_str
+#define i_tag id // Map of int => cstr
#include <stc/cmap.h>
-#define i_tag cnt // Map of cstr => int
#define i_key_str
#define i_val int
+#define i_tag cnt // Map of cstr => int
#include <stc/cmap.h>
typedef struct {int x, y;} ipair_t;
@@ -17,18 +17,19 @@ inline static int ipair_compare(const ipair_t* a, const ipair_t* b) { return cx == 0 ? c_default_compare(&a->y, &b->y) : cx;
}
-#define i_tag ip
+
#define i_val ipair_t
#define i_cmp ipair_compare
+#define i_tag ip
#include <stc/cvec.h>
-#define i_tag ip
#define i_val ipair_t
#define i_cmp ipair_compare
+#define i_tag ip
#include <stc/clist.h>
-#define i_tag f
#define i_val float
+#define i_tag f
#include <stc/cpque.h>
int main(void)
diff --git a/examples/list.c b/examples/list.c index 94ee091f..30923e8b 100644 --- a/examples/list.c +++ b/examples/list.c @@ -2,8 +2,8 @@ #include <time.h>
#include <stc/crandom.h>
-#define i_tag fx
#define i_val double
+#define i_tag fx
#include <stc/clist.h>
int main() {
diff --git a/examples/list_erase.c b/examples/list_erase.c index db05fb42..c1e5ab61 100644 --- a/examples/list_erase.c +++ b/examples/list_erase.c @@ -1,8 +1,8 @@ // erasing from clist
#include <stdio.h>
-#define i_tag i
#define i_val int
+#define i_tag i
#include <stc/clist.h>
int main ()
diff --git a/examples/list_splice.c b/examples/list_splice.c index 425a344a..517cbcce 100644 --- a/examples/list_splice.c +++ b/examples/list_splice.c @@ -1,7 +1,7 @@ #include <stdio.h> -#define i_tag i #define i_val int +#define i_tag i #include <stc/clist.h> void print_ilist(const char* s, clist_i list) diff --git a/examples/mapmap.c b/examples/mapmap.c index d24c4748..44cf7da5 100644 --- a/examples/mapmap.c +++ b/examples/mapmap.c @@ -8,10 +8,10 @@ #define i_val_str
#include <stc/cmap.h>
-#define i_tag cfg
#define i_key_str
#define i_val cmap_str
#define i_valdel cmap_str_del
+#define i_tag cfg
#include <stc/cmap.h>
int main(void)
diff --git a/examples/mmap.c b/examples/mmap.c index ad2e28c8..2defbd96 100644 --- a/examples/mmap.c +++ b/examples/mmap.c @@ -6,11 +6,11 @@ #define i_val_str
#include <stc/clist.h>
-#define i_tag mult
#define i_key int
#define i_val clist_str
-#define i_valdel clist_str_del
#define i_cmp -c_default_compare
+#define i_valdel clist_str_del
+#define i_tag mult
#include <stc/csmap.h>
void print(const csmap_mult mmap)
diff --git a/examples/multimap.c b/examples/multimap.c index 64e3493b..3dbe952d 100644 --- a/examples/multimap.c +++ b/examples/multimap.c @@ -43,17 +43,17 @@ void OlympicLocation_del(OlympicLocation* self) { }
// Create a clist<OlympicLocation>, can be sorted by year.
-#define i_tag OL
#define i_val OlympicLocation
-#define i_valdel OlympicLocation_del
#define i_cmp OlympicLocation_compare
+#define i_del OlympicLocation_del
+#define i_tag OL
#include <stc/clist.h>
// Create a csmap<cstr, clist_OL> where key is country name
-#define i_tag OL
#define i_key_str
#define i_val clist_OL
#define i_valdel clist_OL_del
+#define i_tag OL
#include <stc/csmap.h>
int main()
diff --git a/examples/new_deq.c b/examples/new_deq.c index 58ca7722..7d30343f 100644 --- a/examples/new_deq.c +++ b/examples/new_deq.c @@ -10,9 +10,9 @@ struct MyStruct { } typedef MyStruct;
+#define i_val int
#define i_fwd
#define i_tag i32
-#define i_val int
#include <stc/cdeq.h>
struct Point { int x, y; } typedef Point;
@@ -21,10 +21,10 @@ int point_compare(const Point* a, const Point* b) { return c ? c : c_default_compare(&a->y, &b->y);
}
-#define i_fwd
-#define i_tag pnt
#define i_val Point
#define i_cmp point_compare
+#define i_fwd
+#define i_tag pnt
#include <stc/cdeq.h>
#define i_val float
diff --git a/examples/new_list.c b/examples/new_list.c index 879f26aa..4d2328be 100644 --- a/examples/new_list.c +++ b/examples/new_list.c @@ -9,9 +9,9 @@ struct MyStruct { clist_pnt pntlst; } typedef MyStruct; +#define i_val int #define i_fwd #define i_tag i32 -#define i_val int #include <stc/clist.h> struct Point { int x, y; } typedef Point; @@ -20,10 +20,10 @@ int point_compare(const Point* a, const Point* b) { return c ? c : c_default_compare(&a->y, &b->y); } -#define i_fwd -#define i_tag pnt #define i_val Point #define i_cmp point_compare +#define i_fwd +#define i_tag pnt #include <stc/clist.h> #define i_val float diff --git a/examples/new_map.c b/examples/new_map.c index 297e9be7..7ed192a3 100644 --- a/examples/new_map.c +++ b/examples/new_map.c @@ -20,11 +20,11 @@ int point_compare(const Point* a, const Point* b) { return c ? c : c_default_compare(&a->y, &b->y);
}
-#define i_fwd // forward declared
-#define i_tag pnt
#define i_key Point
#define i_val int
#define i_cmp point_compare
+#define i_fwd // forward declared
+#define i_tag pnt
#include <stc/cmap.h>
// int => int map
diff --git a/examples/new_pque.c b/examples/new_pque.c index 08962e1f..8335e46e 100644 --- a/examples/new_pque.c +++ b/examples/new_pque.c @@ -20,10 +20,10 @@ int Point_cmp(const Point* a, const Point* b) { return c ? c : c_default_compare(&a->y, &b->y);
}
-#define i_fwd // forward declared.
-#define i_tag pnt
#define i_val Point
#define i_cmp Point_cmp
+#define i_fwd // forward declared.
+#define i_tag pnt
#include <stc/cpque.h>
#include <stdio.h>
diff --git a/examples/new_queue.c b/examples/new_queue.c index 6e62abe6..53a5b341 100644 --- a/examples/new_queue.c +++ b/examples/new_queue.c @@ -1,6 +1,7 @@ #include <stc/crandom.h>
#include <stc/forward.h>
#include <stdio.h>
+#include <time.h>
forward_cqueue(cqueue_pnt, struct Point);
@@ -9,14 +10,14 @@ int point_compare(const Point* a, const Point* b) { int c = c_default_compare(&a->x, &b->x);
return c ? c : c_default_compare(&a->y, &b->y);
}
-#define F_tag pnt
#define i_val Point
#define i_cmp point_compare
+#define i_fwd
+#define i_tag pnt
#include <stc/cqueue.h>
#define i_val int
#include <stc/cqueue.h>
-#include <time.h>
int main() {
int n = 60000000;
diff --git a/examples/new_smap.c b/examples/new_smap.c index bbaa3dd1..1c84a961 100644 --- a/examples/new_smap.c +++ b/examples/new_smap.c @@ -20,11 +20,11 @@ int point_compare(const Point* a, const Point* b) { return c ? c : c_default_compare(&a->y, &b->y);
}
-#define i_fwd
-#define i_tag pnt
#define i_key Point
#define i_val int
#define i_cmp point_compare
+#define i_fwd
+#define i_tag pnt
#include <stc/csmap.h>
// int => int map
diff --git a/examples/new_sptr.c b/examples/new_sptr.c index e4ed5e89..25eb6702 100644 --- a/examples/new_sptr.c +++ b/examples/new_sptr.c @@ -10,10 +10,10 @@ void Person_del(Person* p) { c_del(cstr, &p->name, &p->last);
}
-#define i_tag person
#define i_val Person
#define i_del Person_del
#define i_cmp c_no_compare
+#define i_tag person
#include <stc/csptr.h>
// ...
@@ -21,8 +21,8 @@ void Person_del(Person* p) { #define i_val int
#include <stc/csptr.h>
-#define i_tag iptr
#define i_key_csptr csptr_int
+#define i_tag iptr
#include <stc/csset.h>
int main(void) {
diff --git a/examples/new_vec.c b/examples/new_vec.c index 34029168..5460789a 100644 --- a/examples/new_vec.c +++ b/examples/new_vec.c @@ -20,10 +20,10 @@ int point_compare(const Point* a, const Point* b) { return c ? c : c_default_compare(&a->y, &b->y);
}
-#define i_fwd pnt
-#define i_tag pnt
#define i_val Point
#define i_cmp point_compare
+#define i_fwd pnt
+#define i_tag pnt
#include <stc/cvec.h>
#define i_val float
diff --git a/examples/priority.c b/examples/priority.c index 03bd1a03..1068cb91 100644 --- a/examples/priority.c +++ b/examples/priority.c @@ -3,9 +3,9 @@ #include <time.h>
#include <stc/crandom.h>
-#define i_tag i
#define i_val int64_t
#define i_cmp -c_default_compare // min-heap (increasing values)
+#define i_tag i
#include <stc/cpque.h>
int main() {
diff --git a/examples/queue.c b/examples/queue.c index 602e9f0f..2c2052e5 100644 --- a/examples/queue.c +++ b/examples/queue.c @@ -1,8 +1,8 @@ #include <stc/crandom.h>
#include <stdio.h>
-#define i_tag i
#define i_val int
+#define i_tag i
#include <stc/cqueue.h>
int main() {
diff --git a/examples/replace.c b/examples/replace.c index 9e658922..ebb40cc5 100644 --- a/examples/replace.c +++ b/examples/replace.c @@ -13,7 +13,7 @@ int main () // Ustring positions: 0123456789*123456789*12345
cstr s = cstr_from(base); // "this is a test string."
cstr m = cstr_clone(s);
- c_autoscope (0, cstr_del(&s), cstr_del(&m)) {
+ c_autodefer (cstr_del(&s), cstr_del(&m)) {
cstr_append(&m, m.str);
cstr_append(&m, m.str);
printf("%s\n", m.str);
diff --git a/examples/stack.c b/examples/stack.c index 7da3063a..54d5aeed 100644 --- a/examples/stack.c +++ b/examples/stack.c @@ -13,7 +13,7 @@ int main() {
cstack_i stack = cstack_i_init();
cstack_c chars = cstack_c_init();
- c_autoscope (0, cstack_i_del(&stack), cstack_c_del(&chars))
+ c_autodefer (cstack_i_del(&stack), cstack_c_del(&chars))
{
c_forrange (i, int, 101)
cstack_i_push(&stack, i*i);
|
