summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authortylov <[email protected]>2023-07-12 19:39:59 +0200
committertylov <[email protected]>2023-07-12 21:01:46 +0200
commitebe5abc29d51c643520301e42124365477f44957 (patch)
treef1188f5c649f4244c384484ae584894280396272
parent715a02ba8155de2f7d446e8d7d2ae305c27996b9 (diff)
downloadSTC-modified-ebe5abc29d51c643520301e42124365477f44957.tar.gz
STC-modified-ebe5abc29d51c643520301e42124365477f44957.zip
Changed docs and examples to use i_key* template parameters instead of i_val* for all non-maps.
Renamed c_ASSERT() to c_assert() and added optional message parameter to c_static_assert().
-rw-r--r--README.md36
-rw-r--r--docs/carc_api.md38
-rw-r--r--docs/cbox_api.md52
-rw-r--r--docs/ccommon_api.md10
-rw-r--r--docs/cdeq_api.md54
-rw-r--r--docs/clist_api.md56
-rw-r--r--docs/cpque_api.md32
-rw-r--r--docs/cqueue_api.md28
-rw-r--r--docs/cset_api.md2
-rw-r--r--docs/cspan_api.md7
-rw-r--r--docs/csset_api.md2
-rw-r--r--docs/cstack_api.md38
-rw-r--r--docs/csview_api.md2
-rw-r--r--docs/cvec_api.md64
-rw-r--r--include/stc/algo/sort.h21
-rw-r--r--include/stc/cbits.h8
-rw-r--r--include/stc/ccommon.h14
-rw-r--r--include/stc/cdeq.h4
-rw-r--r--include/stc/clist.h2
-rw-r--r--include/stc/cmap.h2
-rw-r--r--include/stc/cpque.h2
-rw-r--r--include/stc/cqueue.h4
-rw-r--r--include/stc/cspan.h28
-rw-r--r--include/stc/cstack.h8
-rw-r--r--include/stc/cvec.h8
-rw-r--r--include/stc/extend.h4
-rw-r--r--misc/benchmarks/various/csort_bench.c2
-rw-r--r--misc/examples/arc_containers.c8
-rw-r--r--misc/examples/arc_demo.c8
-rw-r--r--misc/examples/arcvec_erase.c6
-rw-r--r--misc/examples/astar.c4
-rw-r--r--misc/examples/box.c4
-rw-r--r--misc/examples/box2.c6
-rw-r--r--misc/examples/cointerleave.c2
-rw-r--r--misc/examples/complex.c4
-rw-r--r--misc/examples/convert.c4
-rw-r--r--misc/examples/csmap_find.c2
-rw-r--r--misc/examples/csmap_insert.c2
-rw-r--r--misc/examples/demos.c6
-rw-r--r--misc/examples/forfilter.c4
-rw-r--r--misc/examples/forloops.c2
-rw-r--r--misc/examples/functor.c2
-rw-r--r--misc/examples/inits.c6
-rw-r--r--misc/examples/intrusive.c2
-rw-r--r--misc/examples/list.c2
-rw-r--r--misc/examples/list_erase.c2
-rw-r--r--misc/examples/list_splice.c2
-rw-r--r--misc/examples/lower_bound.c4
-rw-r--r--misc/examples/mmap.c2
-rw-r--r--misc/examples/multimap.c2
-rw-r--r--misc/examples/music_arc.c4
-rw-r--r--misc/examples/new_list.c10
-rw-r--r--misc/examples/new_pque.c2
-rw-r--r--misc/examples/new_queue.c4
-rw-r--r--misc/examples/new_sptr.c10
-rw-r--r--misc/examples/new_vec.c4
-rw-r--r--misc/examples/person_arc.c4
-rw-r--r--misc/examples/printspan.c8
-rw-r--r--misc/examples/priority.c2
-rw-r--r--misc/examples/queue.c2
-rw-r--r--misc/examples/rawptr_elements.c2
-rw-r--r--misc/examples/read.c2
-rw-r--r--misc/examples/regex_match.c2
-rw-r--r--misc/examples/scheduler.c2
-rw-r--r--misc/examples/shape.c6
-rw-r--r--misc/examples/stack.c4
-rw-r--r--misc/tests/cspan_test.c4
67 files changed, 348 insertions, 338 deletions
diff --git a/README.md b/README.md
index ab350488..67c4d7fd 100644
--- a/README.md
+++ b/README.md
@@ -81,7 +81,7 @@ List of contents
1. ***Centralized analysis of template parameters***. The analyser assigns values to all
non-specified template parameters (based on the specified ones) using meta-programming, so
that you don't have to! You may specify a set of "standard" template parameters for each
-container, but as a minimum *only one is required*: `i_val` (+ `i_key` for maps). In this
+container, but as a minimum *only one is required*: `i_key` (+ `i_val` for maps). In this
case, STC assumes that the elements are of basic types. For non-trivial types, additional
template parameters must be given.
2. ***Alternative insert/lookup type***. You may specify an alternative type to use for
@@ -118,7 +118,7 @@ Benchmark notes:
- Container names are prefixed by `c`, e.g. `cvec`, `cstr`.
- Public STC macros are prefixed by `c_`, e.g. `c_foreach`, `c_init`.
-- Template parameter macros are prefixed by `i_`, e.g. `i_val`, `i_type`.
+- Template parameter macros are prefixed by `i_`, e.g. `i_key`, `i_type`.
- All containers can be initialized with `{0}`, i.e. no heap allocation used by default init.
- Common types for a container type Con:
- Con
@@ -150,7 +150,7 @@ templated types in C++. However, to specify template parameters with STC, you de
including the container:
```c
#define i_type Floats // Container type name; unless defined name would be cvec_float
-#define i_val float // Container element type
+#define i_key float // Container element type
#include <stc/cvec.h> // "instantiate" the desired container type
#include <stdio.h>
@@ -177,7 +177,7 @@ You may switch to a different container type, e.g. a sorted set (csset):
[ [Run this code](https://godbolt.org/z/qznfa65e1) ]
```c
#define i_type Floats
-#define i_val float
+#define i_key float
#include <stc/csset.h> // Use a sorted set instead
#include <stdio.h>
@@ -196,7 +196,7 @@ int main()
}
```
For user-defined struct elements, `i_cmp` compare function should be defined as the default `<` and `==`
-only works for integral types. *Alternatively, `#define i_opt c_no_cmp` to disable sorting and searching*. Similarily, if an element destructor `i_valdrop` is defined, `i_valclone` function is required.
+only works for integral types. *Alternatively, `#define i_opt c_no_cmp` to disable sorting and searching*. Similarily, if an element destructor `i_keydrop` is defined, `i_keyclone` function is required.
*Alternatively `#define i_opt c_no_clone` to disable container cloning.*
Let's make a vector of vectors, which can be cloned. All of its element vectors will be destroyed when destroying the Vec2D.
@@ -206,11 +206,11 @@ Let's make a vector of vectors, which can be cloned. All of its element vectors
#include <stdio.h>
#define i_type Vec
-#define i_val float
+#define i_key float
#include <stc/cvec.h>
#define i_type Vec2D
-#define i_valclass Vec // Use i_valclass when element type has "members" _clone(), _drop() and _cmp().
+#define i_keyclass Vec // Use i_keyclass when element type has "members" _clone(), _drop() and _cmp().
#define i_opt c_no_cmp // Disable cmp (search/sort) for Vec2D because Vec_cmp() is not defined.
#include <stc/cvec.h>
@@ -246,12 +246,12 @@ This example uses four different container types:
struct Point { float x, y; };
// Define cvec_pnt with a less-comparison function for Point.
-#define i_val struct Point
+#define i_key struct Point
#define i_less(a, b) a->x < b->x || (a->x == b->x && a->y < b->y)
#define i_tag pnt
#include <stc/cvec.h> // cvec_pnt: vector of struct Point
-#define i_val int
+#define i_key int
#include <stc/clist.h> // clist_int: singly linked list
#define i_key int
@@ -369,10 +369,10 @@ or define your own, e.g.:
#define i_tag ix
#include <stc/cset.h> // cset_ix
-#define i_val int
+#define i_key int
#include <stc/cvec.h> // cvec_int
-#define i_val Point
+#define i_key Point
#define i_tag pnt
#include <stc/clist.h> // clist_pnt
```
@@ -383,8 +383,8 @@ Each templated type requires one `#include`, even if it's the same container bas
The template parameters are given by a `#define i_xxxx` statement, where *xxxx* is the parameter name.
The list of template parameters:
-- `i_key` *Type* - Element key type for map/set only. **[required]**.
-- `i_val` *Type* - Element value type. **[required for]** cmap/csmap, it is the mapped value type.
+- `i_key` *Type* - Element key type. **[required]**. Note: `i_val` *may* be used instead for non-maps (not recommended).
+- `i_val` *Type* - Element value type. **[required for]** cmap/csmap as the mapped value type.
- `i_cmp` *Func* - Three-way comparison of two *i_keyraw*\* or *i_valraw*\* - **[required for]** non-integral *i_keyraw* elements unless *i_opt* is defined with *c_no_cmp*.
- `i_hash` *Func* - Hash function taking *i_keyraw*\* - defaults to *c_default_hash*. **[required for]** ***cmap/cset*** with non-POD *i_keyraw* elements.
- `i_eq` *Func* - Equality comparison of two *i_keyraw*\* - defaults to *!i_cmp*. Companion with *i_hash*.
@@ -458,7 +458,7 @@ and non-emplace methods:
#define i_implement // define in ONE file to implement longer functions in cstr
#include <stc/cstr.h>
-#define i_val_str // special macro to enable container of cstr
+#define i_key_str // special macro to enable container of cstr
#include <stc/cvec.h> // vector of string (cstr)
...
cvec_str vec = {0};
@@ -518,7 +518,7 @@ last example on the **cmap** page demonstrates how to specify a map with non-tri
Define `i_type` instead of `i_tag`:
```c
#define i_type MyVec
-#define i_val int
+#define i_key int
#include <stc/cvec.h>
myvec vec = MyVec_init();
@@ -543,7 +543,7 @@ typedef struct Dataset {
// Implementation
#define i_is_forward // flag that the container was forward declared.
-#define i_val struct Point
+#define i_key struct Point
#define i_tag pnt
#include <stc/cstack.h>
```
@@ -617,8 +617,8 @@ STC is generally very memory efficient. Memory usage for the different container
- coroutines: much improved with some new API and added features.
- cspan: Support for column-major (fortran order) multidim spans and transposed views.
- Removed default comparison for clist, cvec and cdeq (as with cstack and cqueue).
- - Using i_val_str, i_valclass, i_valboxed still expects comparisons defined.
- - Define i_native_cmp to enable built-in i_val types comparisons (<, ==).
+ - Using i_key_str, i_keyclass, i_keyboxed still expects comparisons defined.
+ - Define i_native_cmp to enable built-in i_key types comparisons (<, ==).
- cstr and csview are now shared linked by default. Static linking by defining i_static.
- New cdeq and cqueue implementation(s), using circular buffer.
- Renamed i_extern => i_import.
diff --git a/docs/carc_api.md b/docs/carc_api.md
index 22e6bac2..254f868a 100644
--- a/docs/carc_api.md
+++ b/docs/carc_api.md
@@ -6,14 +6,14 @@ deallocated when the last remaining **carc** owning the object is destroyed with
The object is destroyed using *carc_X_drop()*. A **carc** may also own no objects, in which
case it is called empty. The *carc_X_cmp()*, *carc_X_drop()* methods are defined based on
-the `i_cmp` and `i_valdrop` macros specified. Use *carc_X_clone(p)* when sharing ownership of
+the `i_cmp` and `i_keydrop` macros specified. Use *carc_X_clone(p)* when sharing ownership of
the pointed-to object.
All **carc** functions can be called by multiple threads on different instances of **carc** without
additional synchronization even if these instances are copies and share ownership of the same object.
**carc** uses thread-safe atomic reference counting, through the *carc_X_clone()* and *carc_X_drop()* methods.
-When declaring a container with shared pointers, define `i_valboxed` with the carc type, see example.
+When declaring a container with shared pointers, define `i_keyboxed` with the carc type, see example.
See similar c++ class [std::shared_ptr](https://en.cppreference.com/w/cpp/memory/shared_ptr) for a functional reference, or Rust [std::sync::Arc](https://doc.rust-lang.org/std/sync/struct.Arc.html) / [std::rc::Rc](https://doc.rust-lang.org/std/rc/struct.Rc.html).
@@ -21,14 +21,14 @@ See similar c++ class [std::shared_ptr](https://en.cppreference.com/w/cpp/memory
```c
#define i_type // full typename of the carc
-#define i_val // value: REQUIRED
+#define i_key // element type: REQUIRED
-#define i_valraw // convertion "raw" type - defaults to i_val
-#define i_valto // convertion func i_val* => i_valraw: REQUIRED IF i_valraw defined.
-#define i_valfrom // convertion func i_valraw => i_val
+#define i_keyraw // convertion "raw" type - defaults to i_key
+#define i_keyto // convertion func i_key* => i_keyraw: REQUIRED IF i_keyraw defined.
+#define i_keyfrom // convertion func i_keyraw => i_key
#define i_opt c_no_atomic // Non-atomic reference counting, like Rust Rc.
-#define i_tag // alternative typename: carc_{i_tag}. i_tag defaults to i_val
+#define i_tag // alternative typename: carc_{i_tag}. i_tag defaults to i_key
#include <stc/carc.h>
```
`X` should be replaced by the value of `i_tag` in all of the following documentation.
@@ -36,9 +36,9 @@ See similar c++ class [std::shared_ptr](https://en.cppreference.com/w/cpp/memory
## Methods
```c
carc_X carc_X_init(); // empty shared pointer
-carc_X carc_X_from(i_valraw raw); // create an carc from raw type (available if i_valraw defined by user).
-carc_X carc_X_from_ptr(i_val* p); // create an carc from raw pointer. Takes ownership of p.
-carc_X carc_X_make(i_val val); // create an carc from constructed val object. Faster than from_ptr().
+carc_X carc_X_from(i_keyraw raw); // create an carc from raw type (available if i_keyraw defined by user).
+carc_X carc_X_from_ptr(i_key* p); // create an carc from raw pointer. Takes ownership of p.
+carc_X carc_X_make(i_key key); // create an carc from constructed key object. Faster than from_ptr().
carc_X carc_X_clone(carc_X other); // return other with increased use count
carc_X carc_X_move(carc_X* self); // transfer ownership to receiver; self becomes NULL
@@ -49,7 +49,7 @@ void carc_X_drop(carc_X* self); // destruct (decr
long carc_X_use_count(const carc_X* self);
void carc_X_reset(carc_X* self);
-void carc_X_reset_to(carc_X* self, i_val* p); // assign new carc from ptr. Takes ownership of p.
+void carc_X_reset_to(carc_X* self, i_key* p); // assign new carc from ptr. Takes ownership of p.
uint64_t carc_X_hash(const carc_X* x); // hash value
int carc_X_cmp(const carc_X* x, const carc_X* y); // compares pointer addresses if no `i_cmp` is specified.
@@ -58,9 +58,9 @@ bool carc_X_eq(const carc_X* x, const carc_X* y); // carc_X_cmp() =
// functions on pointed to objects.
-uint64_t carc_X_value_hash(const i_val* x);
-int carc_X_value_cmp(const i_val* x, const i_val* y);
-bool carc_X_value_eq(const i_val* x, const i_val* y);
+uint64_t carc_X_value_hash(const i_key* x);
+int carc_X_value_cmp(const i_key* x, const i_key* y);
+bool carc_X_value_eq(const i_key* x, const i_key* y);
```
## Types and constants
@@ -69,8 +69,8 @@ bool carc_X_value_eq(const i_val* x, const i_val* y);
|:------------------|:--------------------------------------------------|:-----------------------|
| `carc_null` | `{0}` | Init nullptr const |
| `carc_X` | `struct { carc_X_value* get; long* use_count; }` | The carc type |
-| `carc_X_value` | `i_val` | The carc element type |
-| `carc_X_raw` | `i_valraw` | Convertion type |
+| `carc_X_value` | `i_key` | The carc element type |
+| `carc_X_raw` | `i_keyraw` | Convertion type |
## Example
@@ -89,12 +89,12 @@ bool carc_X_value_eq(const i_val* x, const i_val* y);
#include <stc/csmap.h>
#define i_type Arc // (atomic) ref. counted pointer
-#define i_val Map
-#define i_valdrop(p) (printf("drop Arc:\n"), Map_drop(p))
+#define i_key Map
+#define i_keydrop(p) (printf("drop Arc:\n"), Map_drop(p))
#include <stc/carc.h>
#define i_type Stack
-#define i_valboxed Arc // Note: use i_valboxed for carc or cbox value types
+#define i_keyboxed Arc // Note: use i_keyboxed for carc or cbox value types
#include <stc/cstack.h>
int main()
diff --git a/docs/cbox_api.md b/docs/cbox_api.md
index 9151f56d..83d59521 100644
--- a/docs/cbox_api.md
+++ b/docs/cbox_api.md
@@ -2,11 +2,11 @@
**cbox** is a smart pointer to a heap allocated value of type X. A **cbox** can
be empty. The *cbox_X_cmp()*, *cbox_X_drop()* methods are defined based on the `i_cmp`
-and `i_valdrop` macros specified. Use *cbox_X_clone(p)* to make a deep copy, which uses the
-`i_valclone` macro if defined.
+and `i_keydrop` macros specified. Use *cbox_X_clone(p)* to make a deep copy, which uses the
+`i_keyclone` macro if defined.
-When declaring a container of **cbox** values, define `i_valboxed` with the
-cbox type instead of defining `i_val`. This will auto-set `i_valdrop`, `i_valclone`, and `i_cmp` using
+When declaring a container of **cbox** values, define `i_keyboxed` with the
+cbox type instead of defining `i_key`. This will auto-set `i_keydrop`, `i_keyclone`, and `i_cmp` using
functions defined by the specified **cbox**.
See similar c++ class [std::unique_ptr](https://en.cppreference.com/w/cpp/memory/unique_ptr) for a functional reference, or Rust [std::boxed::Box](https://doc.rust-lang.org/std/boxed/struct.Box.html)
@@ -15,29 +15,29 @@ See similar c++ class [std::unique_ptr](https://en.cppreference.com/w/cpp/memory
```c
#define i_type // full typename of the cbox
-#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_valdrop // destroy value func - defaults to empty destruct
-#define i_valclone // REQUIRED if i_valdrop is defined, unless 'i_opt c_no_clone' is defined.
+#define i_key // element type: REQUIRED
+#define i_cmp // three-way compare two i_key* : REQUIRED IF i_key is a non-integral type
+#define i_keydrop // destroy element func - defaults to empty destruct
+#define i_keyclone // REQUIRED if i_keydrop is defined, unless 'i_opt c_no_clone' is defined.
-#define i_valraw // convertion type (lookup): default to {i_val}
-#define i_valto // convertion func i_val* => i_valraw: REQUIRED IF i_valraw defined.
-#define i_valfrom // from-raw func.
+#define i_keyraw // convertion type (lookup): default to {i_key}
+#define i_keyto // convertion func i_key* => i_keyraw: REQUIRED IF i_keyraw defined.
+#define i_keyfrom // from-raw func.
-#define i_valclass // alt. to i_val: REQUIRES that {i_val}_clone, {i_val}_drop, {i_valraw}_cmp exist.
-#define i_tag // alternative typename: cbox_{i_tag}. i_tag defaults to i_val
+#define i_keyclass // alt. to i_key: REQUIRES that {i_key}_clone, {i_key}_drop, {i_keyraw}_cmp exist.
+#define i_tag // alternative typename: cbox_{i_tag}. i_tag defaults to i_key
#include <stc/cbox.h>
```
`X` should be replaced by the value of `i_tag` in all of the following documentation.
-Define `i_opt` with `c_no_cmp` if comparison between i_val's is not needed/available. Will then
+Define `i_opt` with `c_no_cmp` if comparison between i_key's is not needed/available. Will then
compare the pointer addresses when used. Additionally, `c_no_clone` or `i_is_fwd` may be defined.
## Methods
```c
cbox_X cbox_X_init(); // return an empty cbox
-cbox_X cbox_X_from(i_valraw raw); // create a cbox from raw type. Avail if i_valraw user defined.
-cbox_X cbox_X_from_ptr(i_val* ptr); // create a cbox from a pointer. Takes ownership of ptr.
-cbox_X cbox_X_make(i_val val); // create a cbox from unowned val object.
+cbox_X cbox_X_from(i_keyraw raw); // create a cbox from raw type. Avail if i_keyraw user defined.
+cbox_X cbox_X_from_ptr(i_key* ptr); // create a cbox from a pointer. Takes ownership of ptr.
+cbox_X cbox_X_make(i_key val); // create a cbox from unowned val object.
cbox_X cbox_X_clone(cbox_X other); // return deep copied clone
cbox_X cbox_X_move(cbox_X* self); // transfer ownership to receiving cbox returned. self becomes NULL.
@@ -46,7 +46,7 @@ void cbox_X_assign(cbox_X* self, cbox_X* moved); // transfer owners
void cbox_X_drop(cbox_X* self); // destruct the contained object and free its heap memory.
void cbox_X_reset(cbox_X* self);
-void cbox_X_reset_to(cbox_X* self, i_val* p); // assign new cbox from ptr. Takes ownership of p.
+void cbox_X_reset_to(cbox_X* self, i_key* p); // assign new cbox from ptr. Takes ownership of p.
uint64_t cbox_X_hash(const cbox_X* x); // hash value
int cbox_X_cmp(const cbox_X* x, const cbox_X* y); // compares pointer addresses if no `i_cmp` is specified.
@@ -55,9 +55,9 @@ bool cbox_X_eq(const cbox_X* x, const cbox_X* y); // cbox_X_cmp() ==
// functions on pointed to objects.
-uint64_t cbox_X_value_hash(const i_val* x);
-int cbox_X_value_cmp(const i_val* x, const i_val* y);
-bool cbox_X_value_eq(const i_val* x, const i_val* y);
+uint64_t cbox_X_value_hash(const i_key* x);
+int cbox_X_value_cmp(const i_key* x, const i_key* y);
+bool cbox_X_value_eq(const i_key* x, const i_key* y);
```
## Types and constants
@@ -66,7 +66,7 @@ bool cbox_X_value_eq(const i_val* x, const i_val* y);
|:-------------------|:--------------------------------|:------------------------|
| `cbox_null` | `{0}` | Init nullptr const |
| `cbox_X` | `struct { cbox_X_value* get; }` | The cbox type |
-| `cbox_X_value` | `i_val` | The cbox element type |
+| `cbox_X_value` | `i_key` | The cbox element type |
## Example
@@ -77,9 +77,9 @@ void int_drop(int* x) {
}
#define i_type IBox
-#define i_val int
-#define i_valdrop int_drop // optional func, just to display elements destroyed
-#define i_valclone(x) x // must specified when i_valdrop is defined.
+#define i_key int
+#define i_keydrop int_drop // optional func, just to display elements destroyed
+#define i_keyclone(x) x // must specified when i_keydrop is defined.
#include <stc/cbox.h>
#define i_type ISet
@@ -87,7 +87,7 @@ void int_drop(int* x) {
#include <stc/csset.h> // ISet : std::set<std::unique_ptr<int>>
#define i_type IVec
-#define i_valboxed IBox // NB: use i_valboxed instead of i_val
+#define i_keyboxed IBox // NB: use i_keyboxed instead of i_key
#include <stc/cvec.h> // IVec : std::vector<std::unique_ptr<int>>
int main()
diff --git a/docs/ccommon_api.md b/docs/ccommon_api.md
index 7569bb5b..52ad88e4 100644
--- a/docs/ccommon_api.md
+++ b/docs/ccommon_api.md
@@ -162,7 +162,7 @@ Note that `c_flt_take()` and `c_flt_takewhile()` breaks the loop on false.
Make any container from an initializer list:
```c
-#define i_val_str // owned cstr string value type
+#define i_key_str // owned cstr string value type
#include <stc/cset.h>
#define i_key int
@@ -210,7 +210,7 @@ You may customize `i_tag` and the comparison function `i_cmp` or `i_less`.
There is a [benchmark/test file here](../misc/benchmarks/various/csort_bench.c).
```c
-#define i_val int
+#define i_key int
#include <stc/algo/sort.h>
#include <stdio.h>
@@ -224,7 +224,7 @@ Containers with random access may also be sorted. Even sorting cdeq/cqueue (with
possible and very fast. Note that `i_more` must be defined to retain specified template parameters for use by sort:
```c
#define i_type MyDeq
-#define i_val int
+#define i_key int
#define i_more
#include <stc/cdeq.h> // deque
#include <stc/algo/sort.h>
@@ -273,7 +273,7 @@ int* ip = c_const_cast(int*, cs); // issues a warning!
### Predefined template parameter functions
-**crawstr** - Non-owned `const char*` "class" element type: `#define i_valclass crawstr`
+**crawstr** - Non-owned `const char*` "class" element type: `#define i_keyclass crawstr`
```c
typedef const char* crawstr;
int crawstr_cmp(const crawstr* x, const crawstr* y);
@@ -485,7 +485,7 @@ return ok;
#define i_implement
#include <stc/cstr.h>
-#define i_val_str
+#define i_key_str
#include <stc/cvec.h>
// receiver should check errno variable
diff --git a/docs/cdeq_api.md b/docs/cdeq_api.md
index 5a00d69a..292b0933 100644
--- a/docs/cdeq_api.md
+++ b/docs/cdeq_api.md
@@ -11,16 +11,16 @@ See the c++ class [std::deque](https://en.cppreference.com/w/cpp/container/deque
```c
#define i_type // full typename of the container
-#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_valdrop // destroy value func - defaults to empty destruct
-#define i_valclone // REQUIRED IF i_valdrop defined
+#define i_key // value: REQUIRED
+#define i_cmp // three-way compare two i_keyraw* : REQUIRED IF i_keyraw is a non-integral type
+#define i_keydrop // destroy value func - defaults to empty destruct
+#define i_keyclone // REQUIRED IF i_keydrop defined
-#define i_valraw // convertion "raw" type - defaults to i_val
-#define i_valfrom // convertion func i_valraw => i_val
-#define i_valto // convertion func i_val* => i_valraw
+#define i_keyraw // convertion "raw" type - defaults to i_key
+#define i_keyfrom // convertion func i_keyraw => i_key
+#define i_keyto // convertion func i_key* => i_keyraw
-#define i_tag // alternative typename: cdeq_{i_tag}. i_tag defaults to i_val
+#define i_tag // alternative typename: cdeq_{i_tag}. i_tag defaults to i_key
#include <stc/cdeq.h>
```
`X` should be replaced by the value of `i_tag` in all of the following documentation.
@@ -44,30 +44,30 @@ intptr_t cdeq_X_capacity(const cdeq_X* self);
const cdeq_X_value* cdeq_X_at(const cdeq_X* self, intptr_t idx);
cdeq_X_value* cdeq_X_at_mut(cdeq_X* self, intptr_t idx);
-const cdeq_X_value* cdeq_X_get(const cdeq_X* self, i_valraw raw); // return NULL if not found
-cdeq_X_value* cdeq_X_get_mut(cdeq_X* self, i_valraw raw); // mutable get
-cdeq_X_iter cdeq_X_find(const cdeq_X* self, i_valraw raw);
-cdeq_X_iter cdeq_X_find_in(cdeq_X_iter i1, cdeq_X_iter i2, i_valraw raw); // return cvec_X_end() if not found
+const cdeq_X_value* cdeq_X_get(const cdeq_X* self, i_keyraw raw); // return NULL if not found
+cdeq_X_value* cdeq_X_get_mut(cdeq_X* self, i_keyraw raw); // mutable get
+cdeq_X_iter cdeq_X_find(const cdeq_X* self, i_keyraw raw);
+cdeq_X_iter cdeq_X_find_in(cdeq_X_iter i1, cdeq_X_iter i2, i_keyraw raw); // return cvec_X_end() if not found
cdeq_X_value* cdeq_X_front(const cdeq_X* self);
cdeq_X_value* cdeq_X_back(const cdeq_X* self);
-cdeq_X_value* cdeq_X_push_front(cdeq_X* self, i_val value);
-cdeq_X_value* cdeq_X_emplace_front(cdeq_X* self, i_valraw raw);
+cdeq_X_value* cdeq_X_push_front(cdeq_X* self, i_key value);
+cdeq_X_value* cdeq_X_emplace_front(cdeq_X* self, i_keyraw raw);
void cdeq_X_pop_front(cdeq_X* self);
-cdeq_X_value* cdeq_X_push_back(cdeq_X* self, i_val value);
-cdeq_X_value* cdeq_X_push(cdeq_X* self, i_val value); // alias for push_back()
-cdeq_X_value* cdeq_X_emplace_back(cdeq_X* self, i_valraw raw);
-cdeq_X_value* cdeq_X_emplace(cdeq_X* self, i_valraw raw); // alias for emplace_back()
+cdeq_X_value* cdeq_X_push_back(cdeq_X* self, i_key value);
+cdeq_X_value* cdeq_X_push(cdeq_X* self, i_key value); // alias for push_back()
+cdeq_X_value* cdeq_X_emplace_back(cdeq_X* self, i_keyraw raw);
+cdeq_X_value* cdeq_X_emplace(cdeq_X* self, i_keyraw raw); // alias for emplace_back()
void cdeq_X_pop_back(cdeq_X* self);
-cdeq_X_iter cdeq_X_insert_n(cdeq_X* self, intptr_t idx, const i_val[] arr, intptr_t n); // move values
-cdeq_X_iter cdeq_X_insert_at(cdeq_X* self, cdeq_X_iter it, i_val value); // move value
+cdeq_X_iter cdeq_X_insert_n(cdeq_X* self, intptr_t idx, const i_key[] arr, intptr_t n); // move values
+cdeq_X_iter cdeq_X_insert_at(cdeq_X* self, cdeq_X_iter it, i_key value); // move value
cdeq_X_iter cdeq_X_insert_uninit(cdeq_X* self, intptr_t idx, intptr_t n); // uninitialized data
// copy values:
-cdeq_X_iter cdeq_X_emplace_n(cdeq_X* self, intptr_t idx, const i_valraw[] arr, intptr_t n);
-cdeq_X_iter cdeq_X_emplace_at(cdeq_X* self, cdeq_X_iter it, i_valraw raw);
+cdeq_X_iter cdeq_X_emplace_n(cdeq_X* self, intptr_t idx, const i_keyraw[] arr, intptr_t n);
+cdeq_X_iter cdeq_X_emplace_at(cdeq_X* self, cdeq_X_iter it, i_keyraw raw);
void cdeq_X_erase_n(cdeq_X* self, intptr_t idx, intptr_t n);
cdeq_X_iter cdeq_X_erase_at(cdeq_X* self, cdeq_X_iter it);
@@ -88,14 +88,14 @@ void cdeq_X_value_drop(cdeq_X_value* pval);
| Type name | Type definition | Used to represent... |
|:-------------------|:------------------------------------|:-----------------------|
-| `cdeq_X` | `struct { cdeq_X_value* data; }` | The cdeq type |
-| `cdeq_X_value` | `i_val` | The cdeq value type |
-| `cdeq_X_raw` | `i_valraw` | The raw value type |
-| `cdeq_X_iter` | `struct { cdeq_X_value* ref; }` | The iterator type |
+| `cdeq_X` | `struct { cdeq_X_value* data; }` | The cdeq type |
+| `cdeq_X_value` | `i_key` | The cdeq value type |
+| `cdeq_X_raw` | `i_keyraw` | The raw value type |
+| `cdeq_X_iter` | `struct { cdeq_X_value* ref; }` | The iterator type |
## Examples
```c
-#define i_val int
+#define i_key int
#define i_tag i
#include <stc/cdeq.h>
diff --git a/docs/clist_api.md b/docs/clist_api.md
index 51b7af6a..023cca41 100644
--- a/docs/clist_api.md
+++ b/docs/clist_api.md
@@ -22,16 +22,16 @@ See the c++ class [std::list](https://en.cppreference.com/w/cpp/container/list)
## Header file and declaration
```c
-#define i_type // container type name (default: clist_{i_val})
-#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_valdrop // destroy value func - defaults to empty destruct
-#define i_valclone // REQUIRED IF i_valdrop defined
-
-#define i_valraw // convertion "raw" type (default: {i_val})
-#define i_valto // convertion func i_val* => i_valraw
-#define i_valfrom // convertion func i_valraw => i_val
-#define i_tag // alternative typename: cpque_{i_tag}. i_tag defaults to i_val
+#define i_type // container type name (default: clist_{i_key})
+#define i_key // value: REQUIRED
+#define i_cmp // three-way compare two i_keyraw* : REQUIRED IF i_keyraw is a non-integral type
+#define i_keydrop // destroy value func - defaults to empty destruct
+#define i_keyclone // REQUIRED IF i_keydrop defined
+
+#define i_keyraw // convertion "raw" type (default: {i_key})
+#define i_keyto // convertion func i_key* => i_keyraw
+#define i_keyfrom // convertion func i_keyraw => i_key
+#define i_tag // alternative typename: cpque_{i_tag}. i_tag defaults to i_key
#include <stc/clist.h>
```
@@ -53,31 +53,31 @@ intptr_t clist_X_count(const clist_X* list);
clist_X_value* clist_X_back(const clist_X* self);
clist_X_value* clist_X_front(const clist_X* self);
-void clist_X_push_back(clist_X* self, i_val value); // note: no pop_back()
-void clist_X_push_front(clist_X* self, i_val value);
-void clist_X_push(clist_X* self, i_val value); // alias for push_back()
+void clist_X_push_back(clist_X* self, i_key value); // note: no pop_back()
+void clist_X_push_front(clist_X* self, i_key value);
+void clist_X_push(clist_X* self, i_key value); // alias for push_back()
-void clist_X_emplace_back(clist_X* self, i_valraw raw);
-void clist_X_emplace_front(clist_X* self, i_valraw raw);
-void clist_X_emplace(clist_X* self, i_valraw raw); // alias for emplace_back()
+void clist_X_emplace_back(clist_X* self, i_keyraw raw);
+void clist_X_emplace_front(clist_X* self, i_keyraw raw);
+void clist_X_emplace(clist_X* self, i_keyraw raw); // alias for emplace_back()
-clist_X_iter clist_X_insert_at(clist_X* self, clist_X_iter it, i_val value); // return iter to new elem
-clist_X_iter clist_X_emplace_at(clist_X* self, clist_X_iter it, i_valraw raw);
+clist_X_iter clist_X_insert_at(clist_X* self, clist_X_iter it, i_key value); // return iter to new elem
+clist_X_iter clist_X_emplace_at(clist_X* self, clist_X_iter it, i_keyraw raw);
void clist_X_pop_front(clist_X* self);
clist_X_iter clist_X_erase_at(clist_X* self, clist_X_iter it); // return iter after it
clist_X_iter clist_X_erase_range(clist_X* self, clist_X_iter it1, clist_X_iter it2);
-intptr_t clist_X_remove(clist_X* self, i_valraw raw); // removes all matches
+intptr_t clist_X_remove(clist_X* self, i_keyraw raw); // removes all matches
clist_X clist_X_split_off(clist_X* self, clist_X_iter i1, clist_X_iter i2); // split off [i1, i2)
clist_X_iter clist_X_splice(clist_X* self, clist_X_iter it, clist_X* other); // return updated valid it
clist_X_iter clist_X_splice_range(clist_X* self, clist_X_iter it, // return updated valid it
clist_X* other, clist_X_iter it1, clist_X_iter it2);
-clist_X_iter clist_X_find(const clist_X* self, i_valraw raw);
-clist_X_iter clist_X_find_in(clist_X_iter it1, clist_X_iter it2, i_valraw raw);
-const i_val* clist_X_get(const clist_X* self, i_valraw raw);
-i_val* clist_X_get_mut(clist_X* self, i_valraw raw);
+clist_X_iter clist_X_find(const clist_X* self, i_keyraw raw);
+clist_X_iter clist_X_find_in(clist_X_iter it1, clist_X_iter it2, i_keyraw raw);
+const i_key* clist_X_get(const clist_X* self, i_keyraw raw);
+i_key* clist_X_get_mut(clist_X* self, i_keyraw raw);
void clist_X_reverse(clist_X* self);
void clist_X_sort(clist_X* self);
@@ -108,8 +108,8 @@ void clist_X_value_drop(clist_X_value* pval);
|:--------------------|:------------------------------------|:-----------------------------------------|
| `clist_X` | `struct { clist_X_node* last; }` | The clist type |
| `clist_X_node` | `struct { clist_X_node* next; clist_X_value value; }` | The clist node type |
-| `clist_X_value` | `i_val` | The clist element type |
-| `clist_X_raw` | `i_valraw` | clist raw value type |
+| `clist_X_value` | `i_key` | The clist element type |
+| `clist_X_raw` | `i_keyraw` | clist raw value type |
| `clist_X_iter` | `struct { clist_value *ref; ... }` | clist iterator |
## Example
@@ -117,7 +117,7 @@ void clist_X_value_drop(clist_X_value* pval);
Interleave *push_front()* / *push_back()* then *sort()*:
```c
#define i_type DList
-#define i_val double
+#define i_key double
#include <stc/clist.h>
#include <stdio.h>
@@ -154,7 +154,7 @@ Use of *erase_at()* and *erase_range()*:
```c
// erasing from clist
#define i_tag i
-#define i_val int
+#define i_key int
#include <stc/clist.h>
#include <stdio.h>
@@ -189,7 +189,7 @@ mylist contains: 10 30
Splice `[30, 40]` from *L2* into *L1* before `3`:
```c
#define i_tag i
-#define i_val int
+#define i_key int
#include <stc/clist.h>
#include <stdio.h>
diff --git a/docs/cpque_api.md b/docs/cpque_api.md
index 962ee162..ca94e367 100644
--- a/docs/cpque_api.md
+++ b/docs/cpque_api.md
@@ -8,17 +8,17 @@ See the c++ class [std::priority_queue](https://en.cppreference.com/w/cpp/contai
## Header file and declaration
```c
-#define i_type // define type name of the container (default cpque_{i_val})
-#define i_val // value: REQUIRED
-#define i_less // compare two i_val* : REQUIRED IF i_val/i_valraw is a non-integral type
-#define i_valdrop // destroy value func - defaults to empty destruct
-#define i_valclone // REQUIRED IF i_valdrop defined
+#define i_type // define type name of the container (default cpque_{i_key})
+#define i_key // value: REQUIRED
+#define i_less // compare two i_key* : REQUIRED IF i_key/i_keyraw is a non-integral type
+#define i_keydrop // destroy value func - defaults to empty destruct
+#define i_keyclone // REQUIRED IF i_keydrop defined
-#define i_valraw // convertion type
-#define i_valfrom // convertion func i_valraw => i_val
-#define i_valto // convertion func i_val* => i_valraw.
+#define i_keyraw // convertion type
+#define i_keyfrom // convertion func i_keyraw => i_key
+#define i_keyto // convertion func i_key* => i_keyraw.
-#define i_tag // alternative typename: cpque_{i_tag}. i_tag defaults to i_val
+#define i_tag // alternative typename: cpque_{i_tag}. i_tag defaults to i_key
#include <stc/cpque.h>
```
`X` should be replaced by the value of `i_tag` in all of the following documentation.
@@ -28,7 +28,7 @@ See the c++ class [std::priority_queue](https://en.cppreference.com/w/cpp/contai
```c
cpque_X cpque_X_init(void); // create empty pri-queue.
cpque_X cpque_X_with_capacity(intptr_t cap);
-cpque_X cpque_X_with_size(intptr_t size, i_val null);
+cpque_X cpque_X_with_size(intptr_t size, i_key null);
cpque_X cpque_X_clone(cpque_X pq);
void cpque_X_clear(cpque_X* self);
@@ -39,16 +39,16 @@ void cpque_X_drop(cpque_X* self); // destructor
intptr_t cpque_X_size(const cpque_X* self);
bool cpque_X_empty(const cpque_X* self);
-i_val* cpque_X_top(const cpque_X* self);
+i_key* cpque_X_top(const cpque_X* self);
void cpque_X_make_heap(cpque_X* self); // heapify the vector.
-void cpque_X_push(cpque_X* self, i_val value);
-void cpque_X_emplace(cpque_X* self, i_valraw raw); // converts from raw
+void cpque_X_push(cpque_X* self, i_key value);
+void cpque_X_emplace(cpque_X* self, i_keyraw raw); // converts from raw
void cpque_X_pop(cpque_X* self);
void cpque_X_erase_at(cpque_X* self, intptr_t idx);
-i_val cpque_X_value_clone(i_val value);
+i_key cpque_X_value_clone(i_key value);
```
## Types
@@ -56,14 +56,14 @@ i_val cpque_X_value_clone(i_val value);
| Type name | Type definition | Used to represent... |
|:-------------------|:--------------------------------------|:------------------------|
| `cpque_X` | `struct {cpque_X_value* data; ...}` | The cpque type |
-| `cpque_X_value` | `i_val` | The cpque element type |
+| `cpque_X_value` | `i_key` | The cpque element type |
## Example
```c
#include <stc/crand.h>
#include <stdio.h>
-#define i_val int64_t
+#define i_key int64_t
#define i_cmp -c_default_cmp // min-heap
#define i_tag i
#include <stc/cpque.h>
diff --git a/docs/cqueue_api.md b/docs/cqueue_api.md
index f5df86d6..bce62833 100644
--- a/docs/cqueue_api.md
+++ b/docs/cqueue_api.md
@@ -7,16 +7,16 @@ See the c++ class [std::queue](https://en.cppreference.com/w/cpp/container/queue
## Header file and declaration
```c
-#define i_type // container type name (default: cset_{i_key})
-#define i_val // value: REQUIRED
-#define i_valdrop // destroy value func - defaults to empty destruct
-#define i_valclone // REQUIRED IF i_valdrop defined
+#define i_type // container type name (default: cqueue_{i_key})
+#define i_key // value: REQUIRED
+#define i_keydrop // destroy value func - defaults to empty destruct
+#define i_keyclone // REQUIRED IF i_keydrop defined
-#define i_valraw // convertion "raw" type - defaults to i_val
-#define i_valfrom // convertion func i_valraw => i_val
-#define i_valto // convertion func i_val* => i_valraw
+#define i_keyraw // convertion "raw" type - defaults to i_key
+#define i_keyfrom // convertion func i_keyraw => i_key
+#define i_keyto // convertion func i_key* => i_keyraw
-#define i_tag // alternative typename: cqueue_{i_tag}. i_tag defaults to i_val
+#define i_tag // alternative typename: cqueue_{i_tag}. i_tag defaults to i_key
#include <stc/cqueue.h>
```
`X` should be replaced by the value of `i_tag` in all of the following documentation.
@@ -42,8 +42,8 @@ bool cqueue_X_empty(const cqueue_X* self);
cqueue_X_value* cqueue_X_front(const cqueue_X* self);
cqueue_X_value* cqueue_X_back(const cqueue_X* self);
-cqueue_X_value* cqueue_X_push(cqueue_X* self, i_val value);
-cqueue_X_value* cqueue_X_emplace(cqueue_X* self, i_valraw raw);
+cqueue_X_value* cqueue_X_push(cqueue_X* self, i_key value);
+cqueue_X_value* cqueue_X_emplace(cqueue_X* self, i_keyraw raw);
void cqueue_X_pop(cqueue_X* self);
cqueue_X_iter cqueue_X_begin(const cqueue_X* self);
@@ -52,7 +52,7 @@ void cqueue_X_next(cqueue_X_iter* it);
cqueue_X_iter cqueue_X_advance(cqueue_X_iter it, intptr_t n);
bool cqueue_X_eq(const cqueue_X* c1, const cqueue_X* c2); // require i_eq/i_cmp/i_less.
-i_val cqueue_X_value_clone(i_val value);
+i_key cqueue_X_value_clone(i_key value);
cqueue_X_raw cqueue_X_value_toraw(const cqueue_X_value* pval);
void cqueue_X_value_drop(cqueue_X_value* pval);
```
@@ -62,13 +62,13 @@ void cqueue_X_value_drop(cqueue_X_value* pval);
| Type name | Type definition | Used to represent... |
|:--------------------|:---------------------|:-------------------------|
| `cqueue_X` | `cdeq_X` | The cqueue type |
-| `cqueue_X_value` | `i_val` | The cqueue element type |
-| `cqueue_X_raw` | `i_valraw` | cqueue raw value type |
+| `cqueue_X_value` | `i_key` | The cqueue element type |
+| `cqueue_X_raw` | `i_keyraw` | cqueue raw value type |
| `cqueue_X_iter` | `cdeq_X_iter` | cqueue iterator |
## Examples
```c
-#define i_val int
+#define i_key int
#define i_tag i
#include <stc/cqueue.h>
diff --git a/docs/cset_api.md b/docs/cset_api.md
index ecf87e5b..7bce3136 100644
--- a/docs/cset_api.md
+++ b/docs/cset_api.md
@@ -18,7 +18,7 @@ A **cset** is an associative container that contains a set of unique objects of
#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_tag // alternative typename: cmap_{i_tag}. i_tag defaults to i_val
+#define i_tag // alternative typename: cmap_{i_tag}. i_tag defaults to i_key
#define i_expandby // default 1. If 2, table expand 2x (else 1.5x)
#include <stc/cset.h>
```
diff --git a/docs/cspan_api.md b/docs/cspan_api.md
index 4262b1ef..1aeeb4f7 100644
--- a/docs/cspan_api.md
+++ b/docs/cspan_api.md
@@ -47,8 +47,11 @@ SpanTypeN_iter SpanType_begin(const SpanTypeN* self);
SpanTypeN_iter SpanType_end(const SpanTypeN* self);
void SpanType_next(SpanTypeN_iter* it);
-SpanTypeN cspan_md(char order, ValueType* data, d1, d2, ...); // make a multi-dim cspan. order: 'C' or 'F' (Fortran)
- // transpose the md span (inverse axes). no changes to the underlying array.
+SpanTypeN cspan_md(ValueType* data, d1, d2, ...); // make a multi-dim cspan, row-major order.
+SpanTypeN cspan_md_left(ValueType* data, d1, d2, ...); // column-major ordered cspan (layout left).
+SpanTypeN cspan_md_ordered(char order, ValueType* data, d1, d2, ...); // order='C': row-major, 'F' (Fortran): column-major.
+
+ // transpose a md span (inverse axes). no changes to the underlying array.
void cspan_transpose(const SpanTypeN* self);
// create a sub md span of lower rank. Like e.g. cspan_slice(Span2, &ms4, {x}, {y}, {c_ALL}, {c_ALL});
diff --git a/docs/csset_api.md b/docs/csset_api.md
index 5695ecf6..d086b660 100644
--- a/docs/csset_api.md
+++ b/docs/csset_api.md
@@ -18,7 +18,7 @@ See the c++ class [std::set](https://en.cppreference.com/w/cpp/container/set) fo
#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_tag // alternative typename: csset_{i_tag}. i_tag defaults to i_val
+#define i_tag // alternative typename: csset_{i_tag}. 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 9cb7b42b..51889d7f 100644
--- a/docs/cstack_api.md
+++ b/docs/cstack_api.md
@@ -9,15 +9,15 @@ See the c++ class [std::stack](https://en.cppreference.com/w/cpp/container/stack
```c
#define i_type // full typename of the container
-#define i_val // value: REQUIRED
-#define i_valdrop // destroy value func - defaults to empty destruct
-#define i_valclone // REQUIRED IF i_valdrop defined
+#define i_key // value: REQUIRED
+#define i_keydrop // destroy value func - defaults to empty destruct
+#define i_keyclone // REQUIRED IF i_keydrop defined
-#define i_valraw // convertion "raw" type - defaults to i_val
-#define i_valfrom // convertion func i_valraw => i_val
-#define i_valto // convertion func i_val* => i_valraw
+#define i_keyraw // convertion "raw" type - defaults to i_key
+#define i_keyfrom // convertion func i_keyraw => i_key
+#define i_keyto // convertion func i_key* => i_keyraw
-#define i_tag // alternative typename: cstack_{i_tag}. i_tag defaults to i_val
+#define i_tag // alternative typename: cstack_{i_tag}. i_tag defaults to i_key
#include <stc/cstack.h>
```
`X` should be replaced by the value of `i_tag` in all of the following documentation.
@@ -27,13 +27,13 @@ See the c++ class [std::stack](https://en.cppreference.com/w/cpp/container/stack
```c
cstack_X cstack_X_init(void);
cstack_X cstack_X_with_capacity(intptr_t cap);
-cstack_X cstack_X_with_size(intptr_t size, i_val fill);
+cstack_X cstack_X_with_size(intptr_t size, i_key fill);
cstack_X cstack_X_clone(cstack_X st);
void cstack_X_clear(cstack_X* self);
bool cstack_X_reserve(cstack_X* self, intptr_t n);
void cstack_X_shrink_to_fit(cstack_X* self);
-i_val* cstack_X_append_uninit(cstack_X* self, intptr_t n);
+i_key* cstack_X_append_uninit(cstack_X* self, intptr_t n);
void cstack_X_copy(cstack_X* self, const cstack_X* other);
void cstack_X_drop(cstack_X* self); // destructor
@@ -41,12 +41,12 @@ intptr_t cstack_X_size(const cstack_X* self);
intptr_t cstack_X_capacity(const cstack_X* self);
bool cstack_X_empty(const cstack_X* self);
-i_val* cstack_X_top(const cstack_X* self);
-const i_val* cstack_X_at(const cstack_X* self, intptr_t idx);
-i_val* cstack_X_at_mut(cstack_X* self, intptr_t idx);
+i_key* cstack_X_top(const cstack_X* self);
+const i_key* cstack_X_at(const cstack_X* self, intptr_t idx);
+i_key* cstack_X_at_mut(cstack_X* self, intptr_t idx);
-i_val* cstack_X_push(cstack_X* self, i_val value);
-i_val* cstack_X_emplace(cstack_X* self, i_valraw raw);
+i_key* cstack_X_push(cstack_X* self, i_key value);
+i_key* cstack_X_emplace(cstack_X* self, i_keyraw raw);
void cstack_X_pop(cstack_X* self);
@@ -55,8 +55,8 @@ cstack_X_iter cstack_X_end(const cstack_X* self);
void cstack_X_next(cstack_X_iter* it);
bool cstack_X_eq(const cstack_X* c1, const cstack_X* c2); // require i_eq/i_cmp/i_less.
-i_val cstack_X_value_clone(i_val value);
-i_valraw cstack_X_value_toraw(const cvec_X_value* pval);
+i_key cstack_X_value_clone(i_key value);
+i_keyraw cstack_X_value_toraw(const cvec_X_value* pval);
void cstack_X_value_drop(cvec_X_value* pval);
```
@@ -65,14 +65,14 @@ void cstack_X_value_drop(cvec_X_value* pval);
| Type name | Type definition | Used to represent... |
|:--------------------|:-------------------------------------|:----------------------------|
| `cstack_X` | `struct { cstack_value *data; ... }` | The cstack type |
-| `cstack_X_value` | `i_val` | The cstack element type |
-| `cstack_X_raw` | `i_valraw` | cstack raw value type |
+| `cstack_X_value` | `i_key` | The cstack element type |
+| `cstack_X_raw` | `i_keyraw` | cstack raw value type |
| `cstack_X_iter` | `struct { cstack_value *ref; }` | cstack iterator |
## Example
```c
#define i_type IStack
-#define i_val int
+#define i_key int
#include <stc/cstack.h>
#include <stdio.h>
diff --git a/docs/csview_api.md b/docs/csview_api.md
index a02b007a..33df6a64 100644
--- a/docs/csview_api.md
+++ b/docs/csview_api.md
@@ -185,7 +185,7 @@ void print_split(csview input, const char* sep)
}
#define i_implement
#include <stc/cstr.h>
-#define i_val_str
+#define i_key_str
#include <stc/cstack.h>
cstack_str string_split(csview input, const char* sep)
diff --git a/docs/cvec_api.md b/docs/cvec_api.md
index d19f4bae..ce85e446 100644
--- a/docs/cvec_api.md
+++ b/docs/cvec_api.md
@@ -13,16 +13,16 @@ See the c++ class [std::vector](https://en.cppreference.com/w/cpp/container/vect
```c
#define i_type // full typename of the container
-#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_valdrop // destroy value func - defaults to empty destruct
-#define i_valclone // REQUIRED IF i_valdrop defined
+#define i_key // value: REQUIRED
+#define i_cmp // three-way compare two i_keyraw* : REQUIRED IF i_keyraw is a non-integral type
+#define i_keydrop // destroy value func - defaults to empty destruct
+#define i_keyclone // REQUIRED IF i_keydrop defined
-#define i_valraw // convertion "raw" type - defaults to i_val
-#define i_valfrom // convertion func i_valraw => i_val
-#define i_valto // convertion func i_val* => i_valraw
+#define i_keyraw // convertion "raw" type - defaults to i_key
+#define i_keyfrom // convertion func i_keyraw => i_key
+#define i_keyto // convertion func i_key* => i_keyraw
-#define i_tag // alternative typename: cvec_{i_tag}. i_tag defaults to i_val
+#define i_tag // alternative typename: cvec_{i_tag}. i_tag defaults to i_key
#include <stc/cvec.h>
```
`X` should be replaced by the value of `i_tag` in all of the following documentation.
@@ -31,15 +31,15 @@ See the c++ class [std::vector](https://en.cppreference.com/w/cpp/container/vect
```c
cvec_X cvec_X_init(void);
-cvec_X cvec_X_with_size(intptr_t size, i_val null);
+cvec_X cvec_X_with_size(intptr_t size, i_key null);
cvec_X cvec_X_with_capacity(intptr_t size);
cvec_X cvec_X_clone(cvec_X vec);
void cvec_X_clear(cvec_X* self);
void cvec_X_copy(cvec_X* self, const cvec_X* other);
-cvec_X_iter cvec_X_copy_n(cvec_X* self, intptr_t idx, const i_val* arr, intptr_t n);
+cvec_X_iter cvec_X_copy_n(cvec_X* self, intptr_t idx, const i_key* arr, intptr_t n);
bool cvec_X_reserve(cvec_X* self, intptr_t cap);
-bool cvec_X_resize(cvec_X* self, intptr_t size, i_val null);
+bool cvec_X_resize(cvec_X* self, intptr_t size, i_key null);
void cvec_X_shrink_to_fit(cvec_X* self);
void cvec_X_drop(cvec_X* self); // destructor
@@ -48,34 +48,34 @@ intptr_t cvec_X_size(const cvec_X* self);
intptr_t cvec_X_capacity(const cvec_X* self);
const cvec_X_value* cvec_X_at(const cvec_X* self, intptr_t idx);
-const cvec_X_value* cvec_X_get(const cvec_X* self, i_valraw raw); // return NULL if not found
+const cvec_X_value* cvec_X_get(const cvec_X* self, i_keyraw raw); // return NULL if not found
cvec_X_value* cvec_X_at_mut(cvec_X* self, intptr_t idx); // return mutable at idx
-cvec_X_value* cvec_X_get_mut(cvec_X* self, i_valraw raw); // find mutable value
-cvec_X_iter cvec_X_find(const cvec_X* self, i_valraw raw);
-cvec_X_iter cvec_X_find_in(cvec_X_iter i1, cvec_X_iter i2, i_valraw raw); // return cvec_X_end() if not found
+cvec_X_value* cvec_X_get_mut(cvec_X* self, i_keyraw raw); // find mutable value
+cvec_X_iter cvec_X_find(const cvec_X* self, i_keyraw raw);
+cvec_X_iter cvec_X_find_in(cvec_X_iter i1, cvec_X_iter i2, i_keyraw raw); // return cvec_X_end() if not found
// On sorted vectors:
-cvec_X_iter cvec_X_binary_search(const cvec_X* self, i_valraw raw); // at elem == raw, else end
-cvec_X_iter cvec_X_lower_bound(const cvec_X* self, i_valraw raw); // at first elem >= raw, else end
+cvec_X_iter cvec_X_binary_search(const cvec_X* self, i_keyraw raw); // at elem == raw, else end
+cvec_X_iter cvec_X_lower_bound(const cvec_X* self, i_keyraw raw); // at first elem >= raw, else end
cvec_X_iter cvec_X_binary_search_in(cvec_X_iter i1, cvec_X_iter i2,
- i_valraw raw, cvec_X_iter* lower_bound);
+ i_keyraw raw, cvec_X_iter* lower_bound);
cvec_X_value* cvec_X_front(const cvec_X* self);
cvec_X_value* cvec_X_back(const cvec_X* self);
-cvec_X_value* cvec_X_push(cvec_X* self, i_val value);
-cvec_X_value* cvec_X_emplace(cvec_X* self, i_valraw raw);
-cvec_X_value* cvec_X_push_back(cvec_X* self, i_val value); // alias for push
-cvec_X_value* cvec_X_emplace_back(cvec_X* self, i_valraw raw); // alias for emplace
+cvec_X_value* cvec_X_push(cvec_X* self, i_key value);
+cvec_X_value* cvec_X_emplace(cvec_X* self, i_keyraw raw);
+cvec_X_value* cvec_X_push_back(cvec_X* self, i_key value); // alias for push
+cvec_X_value* cvec_X_emplace_back(cvec_X* self, i_keyraw raw); // alias for emplace
void cvec_X_pop(cvec_X* self);
void cvec_X_pop_back(cvec_X* self); // alias for pop
-cvec_X_iter cvec_X_insert_n(cvec_X* self, intptr_t idx, const i_val arr[], intptr_t n); // move values
-cvec_X_iter cvec_X_insert_at(cvec_X* self, cvec_X_iter it, i_val value); // move value
+cvec_X_iter cvec_X_insert_n(cvec_X* self, intptr_t idx, const i_key arr[], intptr_t n); // move values
+cvec_X_iter cvec_X_insert_at(cvec_X* self, cvec_X_iter it, i_key value); // move value
cvec_X_iter cvec_X_insert_uninit(cvec_X* self, intptr_t idx, intptr_t n); // return iter at idx
-cvec_X_iter cvec_X_emplace_n(cvec_X* self, intptr_t idx, const i_valraw raw[], intptr_t n);
-cvec_X_iter cvec_X_emplace_at(cvec_X* self, cvec_X_iter it, i_valraw raw);
+cvec_X_iter cvec_X_emplace_n(cvec_X* self, intptr_t idx, const i_keyraw raw[], intptr_t n);
+cvec_X_iter cvec_X_emplace_at(cvec_X* self, cvec_X_iter it, i_keyraw raw);
cvec_X_iter cvec_X_erase_n(cvec_X* self, intptr_t idx, intptr_t n);
cvec_X_iter cvec_X_erase_at(cvec_X* self, cvec_X_iter it);
@@ -83,7 +83,7 @@ cvec_X_iter cvec_X_erase_range(cvec_X* self, cvec_X_iter it1, cvec_X_ite
void cvec_X_sort(cvec_X* self);
void cvec_X_sort_range(cvec_X_iter i1, cvec_X_iter i2,
- int(*cmp)(const i_val*, const i_val*));
+ int(*cmp)(const i_key*, const i_key*));
cvec_X_iter cvec_X_begin(const cvec_X* self);
cvec_X_iter cvec_X_end(const cvec_X* self);
@@ -101,13 +101,13 @@ cvec_X_raw cvec_X_value_drop(cvec_X_value* pval);
| Type name | Type definition | Used to represent... |
|:-------------------|:----------------------------------|:-----------------------|
| `cvec_X` | `struct { cvec_X_value* data; }` | The cvec type |
-| `cvec_X_value` | `i_val` | The cvec value type |
-| `cvec_X_raw` | `i_valraw` | The raw value type |
+| `cvec_X_value` | `i_key` | The cvec value type |
+| `cvec_X_raw` | `i_keyraw` | The raw value type |
| `cvec_X_iter` | `struct { cvec_X_value* ref; }` | The iterator type |
## Examples
```c
-#define i_val int
+#define i_key int
#include <stc/cvec.h>
#include <stdio.h>
@@ -150,7 +150,7 @@ sorted: 5 7 8 13 16 25
#define i_implement
#include <stc/cstr.h>
-#define i_val_str
+#define i_key_str
#include <stc/cvec.h>
int main() {
@@ -206,7 +206,7 @@ User User_clone(User user) {
// Declare a managed, clonable vector of users.
#define i_type UVec
-#define i_valclass User // User is a "class" as it has _cmp, _clone and _drop functions.
+#define i_keyclass User // User is a "class" as it has _cmp, _clone and _drop functions.
#include <stc/cvec.h>
int main(void) {
diff --git a/include/stc/algo/sort.h b/include/stc/algo/sort.h
index 8365ccc5..01e7d521 100644
--- a/include/stc/algo/sort.h
+++ b/include/stc/algo/sort.h
@@ -22,13 +22,13 @@
*/
/* Generic Quicksort in C, performs as fast as c++ std::sort().
template params:
-#define i_val - value type [required]
+#define i_key - value type [required]
#define i_less - less function. default: *x < *y
-#define i_type name - define {{name}}_sort_n(), else {{i_val}}array_sort_n().
+#define i_type name - define {{name}}_sort_n(), else {{i_key}}array_sort_n().
// ex1:
#include <stdio.h>
-#define i_val int
+#define i_key int
#include <stc/algo/sort.h>
int main() {
@@ -42,7 +42,7 @@ int main() {
}
// ex2:
-#define i_val int
+#define i_key int
#define i_type IDeq
#define i_more // retain input template params to be reused by sort.h
#include <stc/cdeq.h>
@@ -62,13 +62,16 @@ int main() {
*/
#include "../ccommon.h"
+#if !defined i_key && defined i_val
+ #define i_key i_val
+#endif
#ifndef i_type
#define i_at(arr, idx) (&arr[idx])
#ifndef i_tag
- #define i_tag i_val
+ #define i_tag i_key
#endif
#define i_type c_PASTE(i_tag, array)
- typedef i_val i_type;
+ typedef i_key i_type;
#endif
#ifndef i_at
#define i_at(arr, idx) _cx_MEMB(_at_mut)(arr, idx)
@@ -78,7 +81,7 @@ int main() {
static inline void _cx_MEMB(_insertsort_ij)(_cx_Self* arr, intptr_t lo, intptr_t hi) {
for (intptr_t j = lo, i = lo + 1; i <= hi; j = i, ++i) {
- i_val key = *i_at(arr, i);
+ i_key key = *i_at(arr, i);
while (j >= 0 && (i_less((&key), i_at(arr, j)))) {
*i_at(arr, j + 1) = *i_at(arr, j);
--j;
@@ -90,14 +93,14 @@ static inline void _cx_MEMB(_insertsort_ij)(_cx_Self* arr, intptr_t lo, intptr_t
static inline void _cx_MEMB(_sort_ij)(_cx_Self* arr, intptr_t lo, intptr_t hi) {
intptr_t i = lo, j;
while (lo < hi) {
- i_val pivot = *i_at(arr, lo + (hi - lo)*7/16);
+ i_key pivot = *i_at(arr, lo + (hi - lo)*7/16);
j = hi;
while (i <= j) {
while (i_less(i_at(arr, i), (&pivot))) ++i;
while (i_less((&pivot), i_at(arr, j))) --j;
if (i <= j) {
- c_swap(i_val, i_at(arr, i), i_at(arr, j));
+ c_swap(i_key, i_at(arr, i), i_at(arr, j));
++i; --j;
}
}
diff --git a/include/stc/cbits.h b/include/stc/cbits.h
index 9463c82c..66bc6354 100644
--- a/include/stc/cbits.h
+++ b/include/stc/cbits.h
@@ -90,7 +90,7 @@ STC_INLINE _llong _cbits_count(const uint64_t* set, const _llong sz) {
STC_INLINE char* _cbits_to_str(const uint64_t* set, const _llong sz,
char* out, _llong start, _llong stop) {
if (stop > sz) stop = sz;
- assert(start <= stop);
+ c_assert(start <= stop);
c_memset(out, '0', stop - start);
for (_llong i = start; i < stop; ++i)
@@ -122,7 +122,7 @@ STC_INLINE bool _cbits_disjoint(const uint64_t* set, const uint64_t* other, cons
#if !defined i_capacity // DYNAMIC SIZE BITARRAY
-#define _i_assert(x) assert(x)
+#define _i_assert(x) c_assert(x)
#define i_type cbits
typedef struct { uint64_t *data64; _llong _size; } i_type;
@@ -216,13 +216,13 @@ STC_INLINE void _i_memb(_set_all)(i_type *self, const bool value);
STC_INLINE void _i_memb(_set_pattern)(i_type *self, const uint64_t pattern);
STC_INLINE i_type _i_memb(_with_size)(const _llong size, const bool value) {
- assert(size <= i_capacity);
+ c_assert(size <= i_capacity);
i_type set; _i_memb(_set_all)(&set, value);
return set;
}
STC_INLINE i_type _i_memb(_with_pattern)(const _llong size, const uint64_t pattern) {
- assert(size <= i_capacity);
+ c_assert(size <= i_capacity);
i_type set; _i_memb(_set_pattern)(&set, pattern);
return set;
}
diff --git a/include/stc/ccommon.h b/include/stc/ccommon.h
index d6da8734..efbebdc3 100644
--- a/include/stc/ccommon.h
+++ b/include/stc/ccommon.h
@@ -34,11 +34,6 @@ typedef long long _llong;
#define c_NPOS INTPTR_MAX
#define c_ZI PRIiPTR
#define c_ZU PRIuPTR
-#if defined STC_NDEBUG || defined NDEBUG
- #define c_ASSERT(expr) (void)(0)
-#else
- #define c_ASSERT(expr) assert(expr)
-#endif
#if defined(_MSC_VER)
#pragma warning(disable: 4116 4996) // unnamed type definition in parentheses
@@ -80,7 +75,14 @@ typedef long long _llong;
#define c_free(p) free(p)
#define c_delete(T, ptr) do { T *_tp = ptr; T##_drop(_tp); free(_tp); } while (0)
-#define c_static_assert(b) ((int)(0*sizeof(int[(b) ? 1 : -1])))
+#define c_static_assert(...) c_MACRO_OVERLOAD(c_static_assert, __VA_ARGS__)
+#define c_static_assert_1(b) ((int)(0*sizeof(int[(b) ? 1 : -1])))
+#define c_static_assert_2(b, m) c_static_assert_1(b)
+#if defined STC_NDEBUG || defined NDEBUG
+ #define c_assert(expr) ((void)0)
+#else
+ #define c_assert(expr) assert(expr)
+#endif
#define c_container_of(p, C, m) ((C*)((char*)(1 ? (p) : &((C*)0)->m) - offsetof(C, m)))
#define c_const_cast(T, p) ((T)(p) + 0*sizeof((T)0 == (p)))
#define c_swap(T, xp, yp) do { T *_xp = xp, *_yp = yp, \
diff --git a/include/stc/cdeq.h b/include/stc/cdeq.h
index bac40f90..056ef005 100644
--- a/include/stc/cdeq.h
+++ b/include/stc/cdeq.h
@@ -51,13 +51,13 @@ _cx_MEMB(_push_back)(_cx_Self* self, _cx_value val)
STC_INLINE void
_cx_MEMB(_pop_back)(_cx_Self* self) {
- assert(!_cx_MEMB(_empty)(self));
+ c_assert(!_cx_MEMB(_empty)(self));
self->end = (self->end - 1) & self->capmask;
i_keydrop((self->data + self->end));
}
STC_INLINE _cx_value _cx_MEMB(_pull_back)(_cx_Self* self) { // move back out of deq
- assert(!_cx_MEMB(_empty)(self));
+ c_assert(!_cx_MEMB(_empty)(self));
self->end = (self->end - 1) & self->capmask;
return self->data[self->end];
}
diff --git a/include/stc/clist.h b/include/stc/clist.h
index 38358d73..9cc1bb39 100644
--- a/include/stc/clist.h
+++ b/include/stc/clist.h
@@ -145,7 +145,7 @@ STC_INLINE void _cx_MEMB(_clear)(_cx_Self* self) { _cx_MEMB(_drop)(self)
STC_INLINE _cx_value* _cx_MEMB(_push)(_cx_Self* self, i_key value)
{ return _cx_MEMB(_push_back)(self, value); }
STC_INLINE void _cx_MEMB(_pop_front)(_cx_Self* self)
- { assert(!_cx_MEMB(_empty)(self)); _cx_MEMB(_erase_after_node)(self, self->last); }
+ { c_assert(!_cx_MEMB(_empty)(self)); _cx_MEMB(_erase_after_node)(self, self->last); }
STC_INLINE _cx_value* _cx_MEMB(_front)(const _cx_Self* self) { return &self->last->next->value; }
STC_INLINE _cx_value* _cx_MEMB(_back)(const _cx_Self* self) { return &self->last->value; }
STC_INLINE _cx_raw _cx_MEMB(_value_toraw)(const _cx_value* pval) { return i_keyto(pval); }
diff --git a/include/stc/cmap.h b/include/stc/cmap.h
index 21e7b933..513a8b93 100644
--- a/include/stc/cmap.h
+++ b/include/stc/cmap.h
@@ -117,7 +117,7 @@ STC_INLINE bool _cx_MEMB(_contains)(const _cx_Self* self, _cx_keyraw rke
STC_INLINE const _cx_mapped*
_cx_MEMB(_at)(const _cx_Self* self, _cx_keyraw rkey) {
chash_bucket b = _cx_MEMB(_bucket_)(self, &rkey);
- assert(b.found);
+ c_assert(b.found);
return &self->data[b.idx].second;
}
STC_INLINE _cx_mapped*
diff --git a/include/stc/cpque.h b/include/stc/cpque.h
index cfe027cc..ca51eeff 100644
--- a/include/stc/cpque.h
+++ b/include/stc/cpque.h
@@ -89,7 +89,7 @@ STC_INLINE const _cx_value* _cx_MEMB(_top)(const _cx_Self* self)
{ return &self->data[0]; }
STC_INLINE void _cx_MEMB(_pop)(_cx_Self* self)
- { assert(!_cx_MEMB(_empty)(self)); _cx_MEMB(_erase_at)(self, 0); }
+ { c_assert(!_cx_MEMB(_empty)(self)); _cx_MEMB(_erase_at)(self, 0); }
#if !defined i_no_clone
STC_API _cx_Self _cx_MEMB(_clone)(_cx_Self q);
diff --git a/include/stc/cqueue.h b/include/stc/cqueue.h
index e9f1b877..5d38ca89 100644
--- a/include/stc/cqueue.h
+++ b/include/stc/cqueue.h
@@ -88,13 +88,13 @@ STC_INLINE _cx_value* _cx_MEMB(_back)(const _cx_Self* self)
{ return self->data + ((self->end - 1) & self->capmask); }
STC_INLINE void _cx_MEMB(_pop)(_cx_Self* self) { // pop_front
- assert(!_cx_MEMB(_empty)(self));
+ c_assert(!_cx_MEMB(_empty)(self));
i_keydrop((self->data + self->start));
self->start = (self->start + 1) & self->capmask;
}
STC_INLINE _cx_value _cx_MEMB(_pull)(_cx_Self* self) { // move front out of queue
- assert(!_cx_MEMB(_empty)(self));
+ c_assert(!_cx_MEMB(_empty)(self));
intptr_t s = self->start;
self->start = (s + 1) & self->capmask;
return self->data[s];
diff --git a/include/stc/cspan.h b/include/stc/cspan.h
index 89986d6f..4d091395 100644
--- a/include/stc/cspan.h
+++ b/include/stc/cspan.h
@@ -84,7 +84,7 @@ int demo2() {
const int rank, const int32_t a[][2]) { \
Self s = {.data=v}; int outrank; \
s.data += _cspan_slice(s.shape, s.stride.d, &outrank, shape, stri, rank, a); \
- c_ASSERT(outrank == RANK); \
+ c_assert(outrank == RANK); \
return s; \
} \
STC_INLINE Self##_iter Self##_begin(const Self* self) { \
@@ -145,7 +145,6 @@ using_cspan_tuple(7); using_cspan_tuple(8);
#define cspan_subspan3(self, offset, count) \
{.data=cspan_at(self, offset, 0, 0), .shape={count, (self)->shape[1], (self)->shape[2]}, .stride=(self)->stride}
-
// cspan_submd(): Reduce rank (N <= 4) Optimized, same as e.g. cspan_slice(Span2, &ms4, {x}, {y}, {c_ALL}, {c_ALL});
#define cspan_submd2(OutSpan, self, ...) _cspan_submdN(OutSpan, 2, self, __VA_ARGS__)
#define cspan_submd3(OutSpan, self, ...) _cspan_submdN(OutSpan, 3, self, __VA_ARGS__)
@@ -172,23 +171,22 @@ using_cspan_tuple(7); using_cspan_tuple(8);
#define _cspan_submd4_5(ok, self, x, y, z) \
{.data=cspan_at(self, x, y, z, 0) + ok, .shape={(self)->shape[3]}, .stride={.d={(self)->stride.d[3]}}}
-#define cspan_md(array, ...) cspan_md_order('C', array, __VA_ARGS__)
-#define cspan_md_left(array, ...) cspan_md_order('F', array, __VA_ARGS__)
-#define cspan_md_order(order, array, ...) \
+#define cspan_md(array, ...) cspan_md_ordered('C', array, __VA_ARGS__)
+#define cspan_md_left(array, ...) cspan_md_ordered('F', array, __VA_ARGS__)
+#define cspan_md_ordered(order, array, ...) \
{.data=array, .shape={__VA_ARGS__}, \
.stride=*(c_PASTE(cspan_tuple, c_NUMARGS(__VA_ARGS__))*)_cspan_shape2stride(order, ((int32_t[]){__VA_ARGS__}), c_NUMARGS(__VA_ARGS__))}
#define cspan_transpose(self) \
_cspan_transpose((self)->shape, (self)->stride.d, cspan_rank(self))
-
// General slicing function;
#define cspan_slice(OutSpan, parent, ...) \
OutSpan##_slice_((parent)->data, (parent)->shape, (parent)->stride.d, cspan_rank(parent) + \
c_static_assert(cspan_rank(parent) == sizeof((int32_t[][2]){__VA_ARGS__})/sizeof(int32_t[2])), \
(const int32_t[][2]){__VA_ARGS__})
-// ----------- private definitions ------------
+/* ------------------- PRIVAT DEFINITIONS ------------------- */
// cspan_index() helpers:
#define cspan_idx_1 cspan_idx_3
@@ -215,19 +213,19 @@ STC_INLINE void _cspan_transpose(int32_t shape[], int32_t stride[], int rank) {
}
STC_INLINE intptr_t _cspan_idx1(const int32_t shape[1], const cspan_tuple1 stri, int32_t x)
- { c_ASSERT(c_LTu(x, shape[0])); return x; }
+ { c_assert(c_LTu(x, shape[0])); return (intptr_t)stri.d[0]*x; }
STC_INLINE intptr_t _cspan_idx2(const int32_t shape[2], const cspan_tuple2 stri, int32_t x, int32_t y)
- { c_ASSERT(c_LTu(x, shape[0]) && c_LTu(y, shape[1])); return (intptr_t)stri.d[0]*x + stri.d[1]*y; }
+ { c_assert(c_LTu(x, shape[0]) && c_LTu(y, shape[1])); return (intptr_t)stri.d[0]*x + stri.d[1]*y; }
STC_INLINE intptr_t _cspan_idx3(const int32_t shape[3], const cspan_tuple3 stri, int32_t x, int32_t y, int32_t z) {
- c_ASSERT(c_LTu(x, shape[0]) && c_LTu(y, shape[1]) && c_LTu(z, shape[2]));
+ c_assert(c_LTu(x, shape[0]) && c_LTu(y, shape[1]) && c_LTu(z, shape[2]));
return (intptr_t)stri.d[0]*x + stri.d[1]*y + stri.d[2]*z;
}
STC_INLINE intptr_t _cspan_idxN(int rank, const int32_t shape[], const int32_t stride[], const int32_t a[]) {
intptr_t off = 0;
while (rank--) {
- c_ASSERT(c_LTu(a[rank], shape[rank]));
+ c_assert(c_LTu(a[rank], shape[rank]));
off += stride[rank]*a[rank];
}
return off;
@@ -239,6 +237,8 @@ STC_API intptr_t _cspan_next2(int32_t pos[], const int32_t shape[], const int32_
#define _cspan_next4 _cspan_next2
#define _cspan_next5 _cspan_next2
#define _cspan_next6 _cspan_next2
+#define _cspan_next7 _cspan_next2
+#define _cspan_next8 _cspan_next2
STC_API intptr_t _cspan_slice(int32_t oshape[], int32_t ostride[], int* orank,
const int32_t shape[], const int32_t stride[],
@@ -247,7 +247,7 @@ STC_API intptr_t _cspan_slice(int32_t oshape[], int32_t ostride[], int* orank,
STC_API int32_t* _cspan_shape2stride(char order, int32_t shape[], int rank);
#endif // STC_CSPAN_H_INCLUDED
-/* -------------------------- IMPLEMENTATION ------------------------- */
+/* --------------------- IMPLEMENTATION --------------------- */
#if defined(i_implement) || defined(i_static)
STC_DEF int32_t* _cspan_shape2stride(char order, int32_t shape[], int rank) {
@@ -283,13 +283,13 @@ STC_DEF intptr_t _cspan_slice(int32_t oshape[], int32_t ostride[], int* orank,
for (; i < rank; ++i) {
off += stride[i]*a[i][0];
switch (a[i][1]) {
- case 0: c_ASSERT(c_LTu(a[i][0], shape[i])); continue;
+ case 0: c_assert(c_LTu(a[i][0], shape[i])); continue;
case -1: end = shape[i]; break;
default: end = a[i][1];
}
oshape[oi] = end - a[i][0];
ostride[oi] = stride[i];
- c_ASSERT(c_LTu(0, oshape[oi]) & !c_LTu(shape[i], end));
+ c_assert(c_LTu(0, oshape[oi]) & !c_LTu(shape[i], end));
++oi;
}
*orank = oi;
diff --git a/include/stc/cstack.h b/include/stc/cstack.h
index 24ec2d5f..f8640ed1 100644
--- a/include/stc/cstack.h
+++ b/include/stc/cstack.h
@@ -129,10 +129,10 @@ STC_INLINE _cx_value* _cx_MEMB(_push)(_cx_Self* self, _cx_value val) {
}
STC_INLINE void _cx_MEMB(_pop)(_cx_Self* self)
- { assert(self->_len); _cx_value* p = &self->data[--self->_len]; i_keydrop(p); }
+ { c_assert(self->_len); _cx_value* p = &self->data[--self->_len]; i_keydrop(p); }
STC_INLINE _cx_value _cx_MEMB(_pull)(_cx_Self* self)
- { assert(self->_len); return self->data[--self->_len]; }
+ { c_assert(self->_len); return self->data[--self->_len]; }
STC_INLINE void _cx_MEMB(_put_n)(_cx_Self* self, const _cx_raw* raw, intptr_t n)
{ while (n--) _cx_MEMB(_push)(self, i_keyfrom(*raw++)); }
@@ -141,9 +141,9 @@ STC_INLINE _cx_Self _cx_MEMB(_from_n)(const _cx_raw* raw, intptr_t n)
{ _cx_Self cx = {0}; _cx_MEMB(_put_n)(&cx, raw, n); return cx; }
STC_INLINE const _cx_value* _cx_MEMB(_at)(const _cx_Self* self, intptr_t idx)
- { assert(idx < self->_len); return self->data + idx; }
+ { c_assert(idx < self->_len); return self->data + idx; }
STC_INLINE _cx_value* _cx_MEMB(_at_mut)(_cx_Self* self, intptr_t idx)
- { assert(idx < self->_len); return self->data + idx; }
+ { c_assert(idx < self->_len); return self->data + idx; }
#if !defined i_no_emplace
STC_INLINE _cx_value* _cx_MEMB(_emplace)(_cx_Self* self, _cx_raw raw)
diff --git a/include/stc/cvec.h b/include/stc/cvec.h
index e1d34365..9b95306e 100644
--- a/include/stc/cvec.h
+++ b/include/stc/cvec.h
@@ -133,9 +133,9 @@ STC_INLINE _cx_value* _cx_MEMB(_front)(const _cx_Self* self) { return self->da
STC_INLINE _cx_value* _cx_MEMB(_back)(const _cx_Self* self)
{ return self->data + self->_len - 1; }
STC_INLINE void _cx_MEMB(_pop)(_cx_Self* self)
- { assert(self->_len); _cx_value* p = &self->data[--self->_len]; i_keydrop(p); }
+ { c_assert(self->_len); _cx_value* p = &self->data[--self->_len]; i_keydrop(p); }
STC_INLINE _cx_value _cx_MEMB(_pull)(_cx_Self* self)
- { assert(self->_len); return self->data[--self->_len]; }
+ { c_assert(self->_len); return self->data[--self->_len]; }
STC_INLINE _cx_value* _cx_MEMB(_push_back)(_cx_Self* self, i_key value)
{ return _cx_MEMB(_push)(self, value); }
STC_INLINE void _cx_MEMB(_pop_back)(_cx_Self* self) { _cx_MEMB(_pop)(self); }
@@ -182,11 +182,11 @@ _cx_MEMB(_erase_range)(_cx_Self* self, _cx_iter i1, _cx_iter i2) {
STC_INLINE const _cx_value*
_cx_MEMB(_at)(const _cx_Self* self, const intptr_t idx) {
- assert(idx < self->_len); return self->data + idx;
+ c_assert(idx < self->_len); return self->data + idx;
}
STC_INLINE _cx_value*
_cx_MEMB(_at_mut)(_cx_Self* self, const intptr_t idx) {
- assert(idx < self->_len); return self->data + idx;
+ c_assert(idx < self->_len); return self->data + idx;
}
diff --git a/include/stc/extend.h b/include/stc/extend.h
index c0a00ff8..52d59414 100644
--- a/include/stc/extend.h
+++ b/include/stc/extend.h
@@ -43,8 +43,10 @@
#define _i_val i_val
#endif
-#ifdef _i_key
+#if defined _i_key && defined _i_val
c_PASTE(forward_, i_base)(i_type, _i_key, _i_val);
+#elif defined _i_key
+ c_PASTE(forward_, i_base)(i_type, _i_key);
#else
c_PASTE(forward_, i_base)(i_type, _i_val);
#endif
diff --git a/misc/benchmarks/various/csort_bench.c b/misc/benchmarks/various/csort_bench.c
index d434693f..f6b7f1db 100644
--- a/misc/benchmarks/various/csort_bench.c
+++ b/misc/benchmarks/various/csort_bench.c
@@ -7,7 +7,7 @@
#endif
#define NDEBUG
#define i_type Ints
-#define i_val int
+#define i_key int
#define i_more
#include <stc/cvec.h>
#include <stc/algo/sort.h>
diff --git a/misc/examples/arc_containers.c b/misc/examples/arc_containers.c
index b05bbea6..524758e7 100644
--- a/misc/examples/arc_containers.c
+++ b/misc/examples/arc_containers.c
@@ -10,18 +10,18 @@
#include <stc/csmap.h>
#define i_type Arc // (atomic) ref. counted type
-#define i_val Map
-#define i_valdrop(p) (printf("drop Arc:\n"), Map_drop(p))
+#define i_key Map
+#define i_keydrop(p) (printf("drop Arc:\n"), Map_drop(p))
// no need for atomic ref. count in single thread:
#define i_opt c_no_atomic
#include <stc/carc.h>
#define i_type Stack
-#define i_valboxed Arc // define i_valboxed for carc/cbox value (not i_val)
+#define i_keyboxed Arc // define i_keyboxed for carc/cbox value (not i_key)
#include <stc/cvec.h>
#define i_type List
-#define i_valboxed Arc // as above
+#define i_keyboxed Arc // as above
#include <stc/clist.h>
int main()
diff --git a/misc/examples/arc_demo.c b/misc/examples/arc_demo.c
index 4cda1c8b..547e1737 100644
--- a/misc/examples/arc_demo.c
+++ b/misc/examples/arc_demo.c
@@ -6,18 +6,18 @@ void int_drop(int* x) {
}
// carc implements its own clone method using reference counting,
-// so 'i_valclone' is not required to be defined (ignored).
+// so 'i_keyclone' is not required to be defined (ignored).
#define i_type Arc // set type name to be defined (instead of 'carc_int')
-#define i_val int
-#define i_valdrop int_drop // optional, just to display the elements destroyed
+#define i_key int
+#define i_keydrop int_drop // optional, just to display the elements destroyed
#define i_native_cmp // use int comparison (x < y, x == y).
#include <stc/carc.h> // Arc
#define i_keyboxed Arc // note: use i_keyboxed instead of i_key for carc/cbox elements
#include <stc/csset.h> // csset_Arc (like: std::set<std::shared_ptr<int>>)
-#define i_valboxed Arc // note: as above.
+#define i_keyboxed Arc // note: as above.
#include <stc/cvec.h> // cvec_Arc (like: std::vector<std::shared_ptr<int>>)
int main()
diff --git a/misc/examples/arcvec_erase.c b/misc/examples/arcvec_erase.c
index 0b9252d9..f409258b 100644
--- a/misc/examples/arcvec_erase.c
+++ b/misc/examples/arcvec_erase.c
@@ -3,13 +3,13 @@
void show_drop(int* x) { printf("drop: %d\n", *x); }
#define i_type Arc
-#define i_val int
-#define i_valdrop show_drop
+#define i_key int
+#define i_keydrop show_drop
#define i_native_cmp // enable sort/search for int type
#include <stc/carc.h> // Shared pointer to int
#define i_type Vec
-#define i_valboxed Arc
+#define i_keyboxed Arc
#include <stc/cvec.h> // Vec: cvec<Arc>
diff --git a/misc/examples/astar.c b/misc/examples/astar.c
index 1b3876aa..44cdefee 100644
--- a/misc/examples/astar.c
+++ b/misc/examples/astar.c
@@ -57,11 +57,11 @@ point_key_cmp(const point* a, const point* b)
return (i == j) ? 0 : (i < j) ? -1 : 1;
}
-#define i_val point
+#define i_key point
#define i_cmp point_cmp_priority
#include <stc/cpque.h>
-#define i_val point
+#define i_key point
#define i_opt c_no_cmp
#include <stc/cdeq.h>
diff --git a/misc/examples/box.c b/misc/examples/box.c
index a9131afa..3f55e15d 100644
--- a/misc/examples/box.c
+++ b/misc/examples/box.c
@@ -29,11 +29,11 @@ void Person_drop(Person* p) {
}
#define i_type PBox
-#define i_valclass Person // "class" binds _cmp, _clone, _drop functions.
+#define i_keyclass Person // "class" binds _cmp, _clone, _drop functions.
#include <stc/cbox.h>
#define i_type Persons
-#define i_valboxed PBox // "arcbox" informs that PBox is a smart pointer.
+#define i_keyboxed PBox // "arcbox" informs that PBox is a smart pointer.
#include <stc/csset.h>
int main()
diff --git a/misc/examples/box2.c b/misc/examples/box2.c
index d3762462..5ac706d4 100644
--- a/misc/examples/box2.c
+++ b/misc/examples/box2.c
@@ -14,15 +14,15 @@ typedef struct {
Point bottom_right;
} Rectangle;
-#define i_val Point
+#define i_key Point
#include <stc/cbox.h> // cbox_Point
-#define i_val Rectangle
+#define i_key Rectangle
#include <stc/cbox.h> // cbox_Rectangle
// Box in box:
#define i_type BoxBoxPoint
-#define i_valboxed cbox_Point // NB: use i_valboxed when value is a cbox or carc!
+#define i_keyboxed cbox_Point // NB: use i_keyboxed when value is a cbox or carc!
#define i_no_cmp
#include <stc/cbox.h> // BoxBoxPoint
diff --git a/misc/examples/cointerleave.c b/misc/examples/cointerleave.c
index 61562a5f..c3c5926a 100644
--- a/misc/examples/cointerleave.c
+++ b/misc/examples/cointerleave.c
@@ -2,7 +2,7 @@
#include <stdio.h>
#include <stc/calgo.h>
#define i_type IVec
-#define i_val int
+#define i_key int
#include <stc/cvec.h>
struct GenValue {
diff --git a/misc/examples/complex.c b/misc/examples/complex.c
index b5ea847a..405afef3 100644
--- a/misc/examples/complex.c
+++ b/misc/examples/complex.c
@@ -9,11 +9,11 @@
#include <stc/cstr.h>
#define i_type FloatStack
-#define i_val float
+#define i_key float
#include <stc/cstack.h>
#define i_type StackList
-#define i_valclass FloatStack // "class" picks up _clone, _drop, _cmp
+#define i_keyclass FloatStack // "class" picks up _clone, _drop, _cmp
#define i_opt c_no_cmp // exclude FloatStack_cmp(): not defined
#include <stc/clist.h>
diff --git a/misc/examples/convert.c b/misc/examples/convert.c
index 318f09b8..3b9dc3ec 100644
--- a/misc/examples/convert.c
+++ b/misc/examples/convert.c
@@ -6,10 +6,10 @@
#define i_val_str
#include <stc/cmap.h>
-#define i_val_str
+#define i_key_str
#include <stc/cvec.h>
-#define i_val_str
+#define i_key_str
#include <stc/clist.h>
int main()
diff --git a/misc/examples/csmap_find.c b/misc/examples/csmap_find.c
index 645828a3..b535e9ad 100644
--- a/misc/examples/csmap_find.c
+++ b/misc/examples/csmap_find.c
@@ -8,7 +8,7 @@
#define i_tag istr
#include <stc/csmap.h>
-#define i_val csmap_istr_raw
+#define i_key csmap_istr_raw
#define i_tag istr
#include <stc/cvec.h>
diff --git a/misc/examples/csmap_insert.c b/misc/examples/csmap_insert.c
index 18a88ec3..df638c22 100644
--- a/misc/examples/csmap_insert.c
+++ b/misc/examples/csmap_insert.c
@@ -12,7 +12,7 @@
#define i_tag istr // Map of int => cstr
#include <stc/csmap.h>
-#define i_val csmap_ii_raw
+#define i_key csmap_ii_raw
#define i_opt c_no_cmp
#define i_tag ii
#include <stc/cvec.h>
diff --git a/misc/examples/demos.c b/misc/examples/demos.c
index b2f50ebf..2e91b20c 100644
--- a/misc/examples/demos.c
+++ b/misc/examples/demos.c
@@ -28,7 +28,7 @@ void stringdemo1()
cstr_drop(&cs);
}
-#define i_val int64_t
+#define i_key int64_t
#define i_tag ix
#include <stc/cvec.h>
@@ -52,7 +52,7 @@ void vectordemo1()
cvec_ix_drop(&bignums);
}
-#define i_val_str
+#define i_key_str
#include <stc/cvec.h>
void vectordemo2()
@@ -72,7 +72,7 @@ void vectordemo2()
cvec_str_drop(&names);
}
-#define i_val int
+#define i_key int
#define i_tag ix
#define i_native_cmp
#include <stc/clist.h>
diff --git a/misc/examples/forfilter.c b/misc/examples/forfilter.c
index 7e3c4c9c..f3c008b3 100644
--- a/misc/examples/forfilter.c
+++ b/misc/examples/forfilter.c
@@ -7,7 +7,7 @@
#include <stc/algo/crange.h>
#define i_type IVec
-#define i_val int
+#define i_key int
#include <stc/cstack.h>
// filters and transforms:
@@ -83,7 +83,7 @@ fn main() {
}
*/
#define i_type SVec
-#define i_valclass csview
+#define i_keyclass csview
#include <stc/cstack.h>
void demo3(void)
diff --git a/misc/examples/forloops.c b/misc/examples/forloops.c
index 337cfaa1..99b12871 100644
--- a/misc/examples/forloops.c
+++ b/misc/examples/forloops.c
@@ -2,7 +2,7 @@
#include <stc/algo/filter.h>
#define i_type IVec
-#define i_val int
+#define i_key int
#include <stc/cstack.h>
#define i_type IMap
diff --git a/misc/examples/functor.c b/misc/examples/functor.c
index a233a874..ea409a56 100644
--- a/misc/examples/functor.c
+++ b/misc/examples/functor.c
@@ -6,7 +6,7 @@
#define i_type IPQue
#define i_base cpque
-#define i_val int
+#define i_key int
#define i_extend bool(*less)(const int*, const int*);
#define i_less(x, y) c_extend()->less(x, y)
// Note: i_less: c_extend() accessible for cpque types
diff --git a/misc/examples/inits.c b/misc/examples/inits.c
index a3a6c4d2..53a49f1f 100644
--- a/misc/examples/inits.c
+++ b/misc/examples/inits.c
@@ -18,17 +18,17 @@ inline static int ipair_cmp(const ipair_t* a, const ipair_t* b) {
}
-#define i_val ipair_t
+#define i_key ipair_t
#define i_cmp ipair_cmp
#define i_tag ip
#include <stc/cvec.h>
-#define i_val ipair_t
+#define i_key ipair_t
#define i_cmp ipair_cmp
#define i_tag ip
#include <stc/clist.h>
-#define i_val float
+#define i_key float
#define i_tag f
#include <stc/cpque.h>
diff --git a/misc/examples/intrusive.c b/misc/examples/intrusive.c
index e3939f4e..1e3f7b83 100644
--- a/misc/examples/intrusive.c
+++ b/misc/examples/intrusive.c
@@ -3,7 +3,7 @@
#include <stdio.h>
#define i_type List
-#define i_val int
+#define i_key int
#define i_native_cmp
#include <stc/clist.h>
diff --git a/misc/examples/list.c b/misc/examples/list.c
index 08fe837f..a0045db9 100644
--- a/misc/examples/list.c
+++ b/misc/examples/list.c
@@ -4,7 +4,7 @@
#include <stc/crand.h>
#define i_type DList
-#define i_val double
+#define i_key double
#define i_native_cmp
#include <stc/clist.h>
diff --git a/misc/examples/list_erase.c b/misc/examples/list_erase.c
index 17adf11f..357dd75b 100644
--- a/misc/examples/list_erase.c
+++ b/misc/examples/list_erase.c
@@ -2,7 +2,7 @@
#include <stdio.h>
#define i_type IList
-#define i_val int
+#define i_key int
#include <stc/clist.h>
int main ()
diff --git a/misc/examples/list_splice.c b/misc/examples/list_splice.c
index e457694d..25c2a42d 100644
--- a/misc/examples/list_splice.c
+++ b/misc/examples/list_splice.c
@@ -1,6 +1,6 @@
#include <stdio.h>
-#define i_val int
+#define i_key int
#define i_tag i
#include <stc/clist.h>
diff --git a/misc/examples/lower_bound.c b/misc/examples/lower_bound.c
index 5b395e45..ee32f49b 100644
--- a/misc/examples/lower_bound.c
+++ b/misc/examples/lower_bound.c
@@ -1,10 +1,10 @@
#include <stdio.h>
-#define i_val int
+#define i_key int
#define i_native_cmp
#include <stc/cvec.h>
-#define i_val int
+#define i_key int
#include <stc/csset.h>
int main()
diff --git a/misc/examples/mmap.c b/misc/examples/mmap.c
index 63312e04..fd00499c 100644
--- a/misc/examples/mmap.c
+++ b/misc/examples/mmap.c
@@ -4,7 +4,7 @@
// Multimap entries
#define i_implement
#include <stc/cstr.h>
-#define i_val_str
+#define i_key_str
#include <stc/clist.h>
// Map of int => clist_str.
diff --git a/misc/examples/multimap.c b/misc/examples/multimap.c
index dc4a1ee0..a89b251b 100644
--- a/misc/examples/multimap.c
+++ b/misc/examples/multimap.c
@@ -40,7 +40,7 @@ OlympicLoc OlympicLoc_clone(OlympicLoc loc);
void OlympicLoc_drop(OlympicLoc* self);
// Create a clist<OlympicLoc>, can be sorted by year.
-#define i_valclass OlympicLoc // binds _cmp, _clone and _drop.
+#define i_keyclass OlympicLoc // binds _cmp, _clone and _drop.
#define i_tag OL
#include <stc/clist.h>
diff --git a/misc/examples/music_arc.c b/misc/examples/music_arc.c
index 4efc35c8..49008523 100644
--- a/misc/examples/music_arc.c
+++ b/misc/examples/music_arc.c
@@ -22,13 +22,13 @@ void Song_drop(Song* s) {
// Define the shared pointer:
#define i_type SongArc
-#define i_valclass Song
+#define i_keyclass Song
#define i_no_hash // no hash fn for Song, fallback hash pointer to Song.
#include <stc/carc.h>
// ... and a vector of them
#define i_type SongVec
-#define i_valboxed SongArc // use i_valboxed on carc / cbox (instead of i_val)
+#define i_keyboxed SongArc // use i_keyboxed on carc / cbox (instead of i_key)
#include <stc/cvec.h>
void example3()
diff --git a/misc/examples/new_list.c b/misc/examples/new_list.c
index 5ffdaca2..ee250b2b 100644
--- a/misc/examples/new_list.c
+++ b/misc/examples/new_list.c
@@ -9,7 +9,7 @@ typedef struct {
clist_pnt pntlist;
} MyStruct;
-#define i_val int
+#define i_key int
#define i_tag i32
#define i_is_forward
#include <stc/clist.h>
@@ -20,20 +20,20 @@ int point_cmp(const Point* a, const Point* b) {
return c ? c : a->y - b->y;
}
-#define i_val Point
+#define i_key Point
#define i_cmp point_cmp
#define i_is_forward
#define i_tag pnt
#include <stc/clist.h>
-#define i_val float
+#define i_key float
#define i_native_cmp // use < and == operators for comparison
#include <stc/clist.h>
void MyStruct_drop(MyStruct* s);
#define i_type MyList
-#define i_val MyStruct
-#define i_valdrop MyStruct_drop // define drop function
+#define i_key MyStruct
+#define i_keydrop MyStruct_drop // define drop function
#define i_no_clone // must explicitely exclude or define cloning support because of drop.
#include <stc/clist.h>
diff --git a/misc/examples/new_pque.c b/misc/examples/new_pque.c
index dc2ecf12..3df39e0e 100644
--- a/misc/examples/new_pque.c
+++ b/misc/examples/new_pque.c
@@ -3,7 +3,7 @@
typedef struct Point { int x, y; } Point;
#define i_type PointQ
-#define i_val Point
+#define i_key Point
#define i_less(a, b) a->x < b->x || (a->x == b->x && a->y < b->y)
#include <stc/cpque.h>
diff --git a/misc/examples/new_queue.c b/misc/examples/new_queue.c
index b784bc18..104871bf 100644
--- a/misc/examples/new_queue.c
+++ b/misc/examples/new_queue.c
@@ -10,14 +10,14 @@ int point_cmp(const Point* a, const Point* b) {
int c = c_default_cmp(&a->x, &b->x);
return c ? c : c_default_cmp(&a->y, &b->y);
}
-#define i_val Point
+#define i_key Point
#define i_cmp point_cmp
#define i_is_forward
#define i_tag pnt
#include <stc/cqueue.h>
#define i_type IQ
-#define i_val int
+#define i_key int
#include <stc/cqueue.h>
int main() {
diff --git a/misc/examples/new_sptr.c b/misc/examples/new_sptr.c
index 2eff41a5..7fef5d1f 100644
--- a/misc/examples/new_sptr.c
+++ b/misc/examples/new_sptr.c
@@ -9,21 +9,21 @@ int Person_cmp(const Person* a, const Person* b);
uint64_t Person_hash(const Person* p);
#define i_type PersonArc
-#define i_valclass Person // "class" assume _clone, _drop, _cmp, _hash is defined.
+#define i_keyclass Person // "class" assume _clone, _drop, _cmp, _hash is defined.
#include <stc/carc.h>
#define i_type IPtr
-#define i_val int
-#define i_valdrop(x) printf("drop: %d\n", *x)
+#define i_key int
+#define i_keydrop(x) printf("drop: %d\n", *x)
#define i_native_cmp
#include <stc/carc.h>
#define i_type IPStack
-#define i_valboxed IPtr
+#define i_keyboxed IPtr
#include <stc/cstack.h>
#define i_type PASet
-#define i_valboxed PersonArc
+#define i_keyboxed PersonArc
#include <stc/cset.h>
diff --git a/misc/examples/new_vec.c b/misc/examples/new_vec.c
index 6329b185..6d928cfc 100644
--- a/misc/examples/new_vec.c
+++ b/misc/examples/new_vec.c
@@ -9,14 +9,14 @@ typedef struct MyStruct {
cvec_pnt pntvec;
} MyStruct;
-#define i_val int
+#define i_key int
#define i_tag i32
#define i_is_forward
#include <stc/cvec.h>
typedef struct Point { int x, y; } Point;
-#define i_val Point
+#define i_key Point
#define i_tag pnt
#define i_less(a, b) a->x < b->x || (a->x == b->x && a->y < b->y)
#define i_eq(a, b) a->x == b->x && a->y == b->y
diff --git a/misc/examples/person_arc.c b/misc/examples/person_arc.c
index 3614c02d..c78b541c 100644
--- a/misc/examples/person_arc.c
+++ b/misc/examples/person_arc.c
@@ -31,12 +31,12 @@ void Person_drop(Person* p) {
}
#define i_type PSPtr
-#define i_valclass Person // ensure Person_drop
+#define i_keyclass Person // ensure Person_drop
#define i_cmp Person_cmp // specify object cmp, instead of ptr cmp for arc.
#include <stc/carc.h>
#define i_type Persons
-#define i_valboxed PSPtr // binds PSPtr_cmp, PSPtr_drop...
+#define i_keyboxed PSPtr // binds PSPtr_cmp, PSPtr_drop...
#include <stc/cvec.h>
diff --git a/misc/examples/printspan.c b/misc/examples/printspan.c
index 7564bd88..5084536a 100644
--- a/misc/examples/printspan.c
+++ b/misc/examples/printspan.c
@@ -3,14 +3,14 @@
#include <stdio.h>
#define i_implement
#include <stc/cstr.h>
-#define i_val int
+#define i_key int
#include <stc/cvec.h>
-#define i_val int
+#define i_key int
#include <stc/cstack.h>
-#define i_val_str
+#define i_key_str
#include <stc/csset.h>
-#include <stc/cspan.h>
+#include <stc/cspan.h>
using_cspan(intspan, int, 1);
void printMe(intspan container) {
diff --git a/misc/examples/priority.c b/misc/examples/priority.c
index 95dd3183..148e8fc5 100644
--- a/misc/examples/priority.c
+++ b/misc/examples/priority.c
@@ -3,7 +3,7 @@
#include <time.h>
#include <stc/crand.h>
-#define i_val int64_t
+#define i_key int64_t
#define i_cmp -c_default_cmp // min-heap (increasing values)
#define i_tag i
#include <stc/cpque.h>
diff --git a/misc/examples/queue.c b/misc/examples/queue.c
index 83c18d09..3154f115 100644
--- a/misc/examples/queue.c
+++ b/misc/examples/queue.c
@@ -1,7 +1,7 @@
#include <stc/crand.h>
#include <stdio.h>
-#define i_val int
+#define i_key int
#define i_tag i
#include <stc/cqueue.h>
diff --git a/misc/examples/rawptr_elements.c b/misc/examples/rawptr_elements.c
index 8dd52aee..9c394d8e 100644
--- a/misc/examples/rawptr_elements.c
+++ b/misc/examples/rawptr_elements.c
@@ -16,7 +16,7 @@
// Alternatively, using cbox:
#define i_type IBox
-#define i_val long
+#define i_key long
#include <stc/cbox.h> // unique_ptr<long> alike.
// cmap of cstr => IBox
diff --git a/misc/examples/read.c b/misc/examples/read.c
index 3c1cadf6..c25cd740 100644
--- a/misc/examples/read.c
+++ b/misc/examples/read.c
@@ -1,7 +1,7 @@
#define i_implement
#include <stc/cstr.h>
#include <stc/algo/raii.h>
-#define i_val_str
+#define i_key_str
#include <stc/cvec.h>
#include <errno.h>
diff --git a/misc/examples/regex_match.c b/misc/examples/regex_match.c
index 310e0797..88d3747b 100644
--- a/misc/examples/regex_match.c
+++ b/misc/examples/regex_match.c
@@ -3,7 +3,7 @@
#define i_implement
#include <stc/csview.h>
-#define i_val float
+#define i_key float
#include <stc/cstack.h>
int main()
diff --git a/misc/examples/scheduler.c b/misc/examples/scheduler.c
index c1168850..d812ff42 100644
--- a/misc/examples/scheduler.c
+++ b/misc/examples/scheduler.c
@@ -9,7 +9,7 @@ struct Task {
};
#define i_type Scheduler
-#define i_val struct Task
+#define i_key struct Task
#include <stc/cqueue.h>
static bool schedule(Scheduler* sched)
diff --git a/misc/examples/shape.c b/misc/examples/shape.c
index 1d9fe5c5..bd4bdd5a 100644
--- a/misc/examples/shape.c
+++ b/misc/examples/shape.c
@@ -76,7 +76,7 @@ struct ShapeAPI Triangle_api = {
// ============================================================
#define i_type PointVec
-#define i_val Point
+#define i_key Point
#include <stc/cstack.h>
typedef struct {
@@ -122,8 +122,8 @@ struct ShapeAPI Polygon_api = {
// ============================================================
#define i_type Shapes
-#define i_val Shape*
-#define i_valdrop(x) Shape_delete(*x)
+#define i_key Shape*
+#define i_keydrop(x) Shape_delete(*x)
#define i_no_clone
#include <stc/cstack.h>
diff --git a/misc/examples/stack.c b/misc/examples/stack.c
index c817e1ae..96bab24b 100644
--- a/misc/examples/stack.c
+++ b/misc/examples/stack.c
@@ -3,11 +3,11 @@
#define i_tag i
#define i_capacity 100
-#define i_val int
+#define i_key int
#include <stc/cstack.h>
#define i_tag c
-#define i_val char
+#define i_key char
#include <stc/cstack.h>
int main() {
diff --git a/misc/tests/cspan_test.c b/misc/tests/cspan_test.c
index 6834dce1..aa055ea6 100644
--- a/misc/tests/cspan_test.c
+++ b/misc/tests/cspan_test.c
@@ -44,7 +44,7 @@ CTEST(cspan, slice) {
ASSERT_EQ(45, sum2);
}
-#define i_val int
+#define i_key int
#include <stc/cstack.h>
CTEST(cspan, slice2) {
@@ -75,7 +75,7 @@ CTEST(cspan, slice2) {
#define i_type Tiles
-#define i_val intspan3
+#define i_key intspan3
#include <stc/cstack.h>
CTEST_FIXTURE(cspan_cube) {