summaryrefslogtreecommitdiffhomepage
path: root/docs
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2021-09-09 08:28:10 +0200
committerTyge Løvset <[email protected]>2021-09-09 08:28:10 +0200
commit52cb5b409447d5c5c3b799b64315dd48fdd445ef (patch)
treeef1a26d5d0265b84a37e36907a4674beb94448f0 /docs
parent180cc60feebea8126e1c2012092782b53e164648 (diff)
downloadSTC-modified-52cb5b409447d5c5c3b799b64315dd48fdd445ef.tar.gz
STC-modified-52cb5b409447d5c5c3b799b64315dd48fdd445ef.zip
Updated examples in docs.
Diffstat (limited to 'docs')
-rw-r--r--docs/cdeq_api.md28
-rw-r--r--docs/clist_api.md36
-rw-r--r--docs/cmap_api.md81
-rw-r--r--docs/cpque_api.md7
-rw-r--r--docs/cqueue_api.md6
-rw-r--r--docs/cset_api.md22
-rw-r--r--docs/csmap_api.md60
-rw-r--r--docs/csset_api.md22
-rw-r--r--docs/cstack_api.md22
-rw-r--r--docs/cvec_api.md39
10 files changed, 151 insertions, 172 deletions
diff --git a/docs/cdeq_api.md b/docs/cdeq_api.md
index 83c0f19f..a79b6d4c 100644
--- a/docs/cdeq_api.md
+++ b/docs/cdeq_api.md
@@ -8,23 +8,16 @@ See the c++ class [std::deque](https://en.cppreference.com/w/cpp/container/deque
## Header file and declaration
```c
+#define i_tag
+#define i_val // required
+#define i_cmp // required if i_val is a struct
+#define i_valdel
+#define i_valfrom
+#define i_valto
+#define i_valraw
#include <stc/cdeq.h>
-
-using_cdeq(X, Value);
-using_cdeq(X, Value, valueCompare);
-using_cdeq(X, Value, valueCompare, valueDel, valueClone = c_no_clone);
-using_cdeq(X, Value, valueCompareRaw, valueDel, valueFromRaw, valueToRaw, RawValue);
-
-using_cdeq_str();
-```
-The macro `using_cdeq()` must be instantiated in the global scope. `X` is a type tag name and
-will affect the names of all cdeq types and methods. E.g. declaring `using_cdeq(i, int);`, `X` should
-be replaced by `i` in all of the following documentation.
-
-`using_cdeq_str()` is a shorthand for:
-```
-using_cdeq(str, cstr, c_rawstr_compare, cstr_del, cstr_from, cstr_str, const char*)
```
+`X` should be replaced by the value of i_tag in all of the following documentation.
## Methods
@@ -100,10 +93,11 @@ cdeq_X_value_t cdeq_X_value_clone(cdeq_X_value_t val);
## Examples
```c
+#define i_tag i
+#define i_val int
#include <stc/cdeq.h>
-#include <stdio.h>
-using_cdeq(i, int);
+#include <stdio.h>
int main() {
cdeq_i q = cdeq_i_init();
diff --git a/docs/clist_api.md b/docs/clist_api.md
index b57662ca..9d50b7ec 100644
--- a/docs/clist_api.md
+++ b/docs/clist_api.md
@@ -22,22 +22,18 @@ See the c++ class [std::list](https://en.cppreference.com/w/cpp/container/list)
## Header file and declaration
```c
+#define i_tag
+#define i_val // required
+#define i_cmp // required if i_val is a struct
+#define i_valdel
+#define i_valfrom
+#define i_valto
+#define i_valraw
#include <stc/clist.h>
-
-using_clist(X, Value);
-using_clist(X, Value, valueCompare);
-using_clist(X, Value, valueCompare, valueDel, valueClone = c_no_clone);
-using_clist(X, Value, valueCompareRaw, valueDel, valueFromRaw, valueToRaw, RawValue);
-
-using_clist_str()
-```
-The macro `using_clist()` must be instantiated in the global scope. `X` is a type tag name and
-will affect the names of all clist types and methods. E.g. declaring `using_clist(i, int);`, `X` should
-be replaced by `i` in all of the following documentation. `using_clist_str()` is a shorthand for
-```c
-using_clist(str, cstr, c_rawstr_compare, cstr_del, cstr_from, cstr_str, const char*)
```
+`X` should be replaced by the value of i_tag in all of the following documentation.
+
## Methods
```c
@@ -100,11 +96,11 @@ 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
#include <stc/clist.h>
#include <stdio.h>
-using_clist(d, double);
-
int main() {
c_var (clist_d, list, {
10.0, 20.0, 30.0, 40.0, 50.0, 60.0, 70.0, 80.0, 90.0
@@ -138,10 +134,11 @@ sorted: 1 2 3 4 5 6 7 8 9 10 20 30 40 50 60 70 80 90
Use of *erase_at()* and *erase_range()*:
```c
// erasing from clist
+#define i_tag i
+#define i_val int
#include <stc/clist.h>
-#include <stdio.h>
-using_clist(i, int);
+#include <stdio.h>
int main ()
{
@@ -171,10 +168,11 @@ mylist contains: 10 30
Splice `[30, 40]` from *L2* into *L1* before `3`:
```c
+#define i_tag i
+#define i_val int
#include <stc/clist.h>
-#include <stdio.h>
-using_clist(i, int);
+#include <stdio.h>
int main() {
c_var (clist_i, L1, {1, 2, 3, 4, 5});
diff --git a/docs/cmap_api.md b/docs/cmap_api.md
index 59afa5ab..eda16e58 100644
--- a/docs/cmap_api.md
+++ b/docs/cmap_api.md
@@ -17,31 +17,16 @@ See the c++ class [std::unordered_map](https://en.cppreference.com/w/cpp/contain
## Header file and declaration
```c
+#define i_tag
+#define i_val // required
+#define i_cmp // required if i_val is a struct
+#define i_valdel
+#define i_valfrom
+#define i_valto
+#define i_valraw
#include <stc/cmap.h>
-
-using_cmap(X, Key, Mapped);
-using_cmap(X, Key, Mapped, keyEquals, keyHash);
-using_cmap(X, Key, Mapped, keyEquals, keyHash, mappedDel, mappedClone = c_no_clone);
-using_cmap(X, Key, Mapped, keyEquals, keyHash, mappedDel, mappedFromRaw, mappedToRaw, RawMapped);
-using_cmap(X, Key, Mapped, keyEqualsRaw, keyHashRaw, mappedDel, mappedFromRaw, mappedToRaw, RawMapped,
- keyDel, keyFromRaw, keyToRaw, RawKey);
-using_cmap_keydef(X, Key, Mapped, keyEquals, keyHash, keyDel, keyClone);
-using_cmap_keydef(X, Key, Mapped, keyEqualsRaw, keyHashRaw, keyDel, keyFromRaw, keyToRaw, RawKey);
-
-using_cmap_strkey(X, Mapped); // using_cmap(X, cstr, Mapped, ...)
-using_cmap_strkey(X, Mapped, mappedDel, mappedClone = c_no_clone);
-using_cmap_strkey(X, Mapped, mappedDel, mappedFromRaw, mappedToRaw, RawMapped);
-
-using_cmap_strval(X, Key); // using_cmap(X, Key, cstr, ...)
-using_cmap_strval(X, Key, keyEquals, keyHash);
-using_cmap_strval(X, Key, keyEquals, keyHash, keyDel, keyClone = c_no_clone);
-using_cmap_strval(X, Key, keyEqualsRaw, keyHashRaw, keyDel, keyFromRaw, keyToRaw, RawKey);
-
-using_cmap_str() // using_cmap(str, cstr, cstr, ...)
```
-The `using_cmap()` macro family must be instantiated in the global scope. `X` is a type tag name and
-will affect the names of all cmap types and methods. E.g. declaring `using_cmap(ii, int, int);`, `X` should
-be replaced by `ii` in all of the following documentation. Argument `flag` is `c_true` by default.
+`X` should be replaced by the value of i_tag in all of the following documentation.
## Methods
@@ -116,10 +101,10 @@ void c_default_del(Type* val); // doe
## Examples
```c
-#include <stc/cmap.h>
#include <stc/cstr.h>
-using_cmap_str();
+#define i_key_str
+#include <stc/cmap.h>
int main()
{
@@ -159,11 +144,12 @@ The HEX of color BLACK is:[#000000]
### Example 2
This example uses a cmap with cstr as mapped value, by the `using_cmap_strval(id, int)` macro.
```c
-#include <stc/cmap.h>
#include <stc/cstr.h>
-/* cmap<int, cstr>: */
-using_cmap_strval(id, int);
+#define i_tag id
+#define i_key int
+#define i_val_str
+#include <stc/cmap.h>
int main()
{
@@ -197,13 +183,14 @@ Output:
### Example 3
Demonstrate cmap with plain-old-data key type Vec3i and int as mapped type: cmap<Vec3i, int>.
```c
-#include <stc/cmap.h>
#include <stdio.h>
-
typedef struct { int x, y, z; } Vec3i;
-using_cmap(vi, Vec3i, int, c_memcmp_equals, // bitwise equals
- c_default_hash); // bytewise hash
+#define i_tag vi
+#define i_key Vec3i
+#define i_val int
+#define i_cmp c_memcmp_equals // bitwise equals, uses c_default_hash
+#include <stc/cmap.h>
int main()
{
@@ -231,11 +218,13 @@ Output:
### Example 4
Inverse: demonstrate cmap with mapped POD type Vec3i: cmap<int, Vec3i>:
```c
-#include <stc/cmap.h>
#include <stdio.h>
-
typedef struct { int x, y, z; } Vec3i;
-using_cmap(iv, int, Vec3i);
+
+#define i_tag iv
+#define i_key int
+#define i_val Vec3i
+#include <stc/cmap.h>
int main()
{
@@ -262,7 +251,6 @@ Output:
### Example 5
Advanced 1: Key type is struct.
```c
-#include <stc/cmap.h>
#include <stc/cstr.h>
typedef struct {
@@ -282,7 +270,13 @@ static void Viking_del(Viking* v) {
c_del(cstr, &v->name, &v->country);
}
-using_cmap_keydef(vk, Viking, int, Viking_equals, Viking_hash, Viking_del, c_no_clone);
+#define i_tag vk
+#define i_key Viking
+#define i_val int
+#define i_valdel Viking_del
+#define i_equ Viking_equals
+#define i_hash Viking_hash
+#include <stc/cmap.h>
int main()
{
@@ -317,7 +311,6 @@ Harald of Iceland has 12 hp
Advanced 2: In example 5 we needed to construct a lookup key which allocated strings, and then had to free it after. In this example we use
rawtype feature to make it even simpler to use. Note that we must use the emplace() methods to add "raw" type entries (otherwise compile error):
```c
-#include <stc/cmap.h>
#include <stc/cstr.h>
typedef struct {
@@ -347,8 +340,16 @@ static uint32_t RViking_hash(const RViking* r, int ignored) {
static Viking Viking_fromR(RViking r) {return (Viking){cstr_from(r.name), cstr_from(r.country)};}
static RViking Viking_toR(const Viking* v) {return (RViking){v->name.str, v->country.str};}
-using_cmap_keydef(vk, Viking, int, RViking_equals, RViking_hash, Viking_del,
- Viking_fromR, Viking_toR, RViking);
+#define i_tag vk
+#define i_key Viking
+#define i_val int
+#define i_valdel Viking_del
+#define i_valraw RViking
+#define i_equ RViking_equals
+#define i_hash RViking_hash
+#define i_keyfrom Viking_fromR
+#define i_keyto Viking_toR
+#include <stc/cmap.h>
int main()
{
diff --git a/docs/cpque_api.md b/docs/cpque_api.md
index 441afc0a..8349a4b6 100644
--- a/docs/cpque_api.md
+++ b/docs/cpque_api.md
@@ -55,12 +55,13 @@ cpque_X_value_t cpque_X_value_clone(cpque_X_value_t val);
## Example
```c
-#include <stc/cpque.h>
#include <stc/crandom.h>
#include <stdio.h>
-using_cvec(i, int64_t);
-using_cpque(i, cvec_i, -c_default_compare); // min-heap
+#define i_tag i
+#define i_val int64_t
+#define i_cmp -c_default_compare // min-heap
+#include <stc/cpque.h>
int main()
{
diff --git a/docs/cqueue_api.md b/docs/cqueue_api.md
index 8bd9f15e..dac51564 100644
--- a/docs/cqueue_api.md
+++ b/docs/cqueue_api.md
@@ -54,11 +54,11 @@ cqueue_X_value_t cqueue_X_value_clone(cqueue_X_value_t val);
## Examples
```c
+#define i_tag i
+#define i_val int
#include <stc/cqueue.h>
-#include <stdio.h>
-using_cdeq(i, int);
-using_cqueue(i, cdeq_i);
+#include <stdio.h>
int main() {
cqueue_i Q = cqueue_i_init();
diff --git a/docs/cset_api.md b/docs/cset_api.md
index dc628750..fc12c5bd 100644
--- a/docs/cset_api.md
+++ b/docs/cset_api.md
@@ -7,18 +7,16 @@ A **cset** is an associative container that contains a set of unique objects of
## Header file and declaration
```c
+#define i_tag
+#define i_val // required
+#define i_cmp // required if i_val is a struct
+#define i_valdel
+#define i_valfrom
+#define i_valto
+#define i_valraw
#include <stc/cset.h>
-
-using_cset(X, Key);
-using_cset(X, Key, keyEquals, keyHash);
-using_cset(X, Key, keyEquals, keyHash, keyDel, keyClone = c_no_clone);
-using_cset(X, Key, keyEqualsRaw, keyHashRaw, keyDel, keyFromRaw, keyToRaw, RawKey, flag);
-
-using_cset_str(); // using_cset(str, cstr, c_rawstr_equals, c_rawstr_hash, cstr_del, ...)
```
-The macro `using_cset()` must be instantiated in the global scope. `X` is a type tag name and
-will affect the names of all cset types and methods. E.g. declaring `using_cset(i, int);`, `X` should
-be replaced by `i` in all of the following documentation.
+`X` should be replaced by the value of i_tag in all of the following documentation.
## Methods
@@ -72,10 +70,10 @@ cset_X_value_t cset_X_value_clone(cset_X_value_t val);
## Example
```c
-#include <stc/cset.h>
#include <stc/cstr.h>
-using_cset_str();
+#define i_key_str
+#include <stc/cset.h>
int main ()
{
diff --git a/docs/csmap_api.md b/docs/csmap_api.md
index dba4fecd..6589417f 100644
--- a/docs/csmap_api.md
+++ b/docs/csmap_api.md
@@ -15,31 +15,16 @@ See the c++ class [std::map](https://en.cppreference.com/w/cpp/container/map) fo
## Header file and declaration
```c
+#define i_tag
+#define i_val // required
+#define i_cmp // required if i_val is a struct
+#define i_valdel
+#define i_valfrom
+#define i_valto
+#define i_valraw
#include <stc/csmap.h>
-
-using_csmap(X, Key, Mapped);
-using_csmap(X, Key, Mapped, keyCompare);
-using_csmap(X, Key, Mapped, keyCompare, mappedDel, mappedClone = c_no_clone);
-using_csmap(X, Key, Mapped, keyCompare, mappedDel, mappedFromRaw, mappedToRaw, RawMapped);
-using_csmap(X, Key, Mapped, keyCompareRaw, mappedDel, mappedFromRaw, mappedToRaw, RawMapped,
- keyDel, keyFromRaw, keyToRaw, RawKey, flag);
-using_csmap_keydef(X, Key, Mapped, keyCompare, keyDel, keyClone);
-using_csmap_keydef(X, Key, Mapped, keyCompareRaw, keyDel, keyFromRaw, keyToRaw, RawKey, flag);
-
-using_csmap_strkey(X, Mapped); // using_csmap(X, cstr, Mapped, ...)
-using_csmap_strkey(X, Mapped, mappedDel, mappedClone);
-using_csmap_strkey(X, Mapped, mappedDel, mappedFromRaw, mappedToRaw, RawMapped, flag);
-
-using_csmap_strval(X, Key); // using_csmap(X, Key, cstr, ...)
-using_csmap_strval(X, Key, keyCompare);
-using_csmap_strval(X, Key, keyCompare, keyDel, keyClone);
-using_csmap_strval(X, Key, keyCompareRaw, keyDel, keyFromRaw, keyToRaw, RawKey, flag);
-
-using_csmap_str(); // using_csmap(str, cstr, cstr, ...)
```
-The `using_csmap()` macro family must be instantiated in the global scope. `X` is a type tag name and
-will affect the names of all csmap types and methods. E.g. declaring `using_csmap(ii, int, int);`, `X` should
-be replaced by `ii` in all of the following documentation. Argument `flag` is `c_true` by default.
+`X` should be replaced by the value of i_tag in all of the following documentation.
## Methods
@@ -97,10 +82,10 @@ csmap_X_rawvalue_t csmap_X_value_toraw(csmap_X_value_t* pval);
## Examples
```c
-#include <stc/csmap.h>
#include <stc/cstr.h>
-using_csmap_str();
+#define i_key_str
+#include <stc/csmap.h>
int main()
{
@@ -139,11 +124,12 @@ The HEX of color BLACK is:[#000000]
### Example 2
This example uses a csmap with cstr as mapped value, by the `using_csmap_strval(id, int)` macro.
```c
-#include <stc/csmap.h>
#include <stc/cstr.h>
-/* csmap<int, cstr>: */
-using_csmap_strval(id, int);
+#define i_tag id
+#define i_key int
+#define i_val_str
+#include <stc/csmap.h>
int main()
{
@@ -176,9 +162,6 @@ Output:
### Example 3
Demonstrate csmap with plain-old-data key type Vec3i and int as mapped type: csmap<Vec3i, int>.
```c
-#include <stc/csmap.h>
-#include <stdio.h>
-
typedef struct { int x, y, z; } Vec3i;
static int Vec3i_compare(const Vec3i* a, const Vec3i* b) {
@@ -188,7 +171,12 @@ static int Vec3i_compare(const Vec3i* a, const Vec3i* b) {
return (a->z > b->z) - (a->z < b->z);
}
-using_csmap(vi, Vec3i, int, Vec3i_compare);
+#define i_tag vi
+#define i_key Vec3i
+#define i_val int
+#define i_cmp Vec3i_compare // uses c_default_hash
+#include <stc/csmap.h>
+#include <stdio.h>
int main()
{
@@ -215,12 +203,14 @@ Output:
### Example 4
Inverse: demonstrate csmap with mapped POD type Vec3i: csmap<int, Vec3i>:
```c
+typedef struct { int x, y, z; } Vec3i;
+
+#define i_tag iv
+#define i_key int
+#define i_val Vec3i
#include <stc/csmap.h>
#include <stdio.h>
-typedef struct { int x, y, z; } Vec3i;
-using_csmap(iv, int, Vec3i);
-
int main()
{
c_forvar (csmap_iv vecs = csmap_iv_init(), csmap_iv_del(&vecs))
diff --git a/docs/csset_api.md b/docs/csset_api.md
index d308fefd..8bf83a17 100644
--- a/docs/csset_api.md
+++ b/docs/csset_api.md
@@ -8,18 +8,16 @@ See the c++ class [std::set](https://en.cppreference.com/w/cpp/container/set) fo
## Header file and declaration
```c
+#define i_tag
+#define i_val // required
+#define i_cmp // required if i_val is a struct
+#define i_valdel
+#define i_valfrom
+#define i_valto
+#define i_valraw
#include <stc/csset.h>
-
-using_csset(X, Key);
-using_csset(X, Key, keyCompare);
-using_csset(X, Key, keyCompare, keyDel, keyClone = c_no_clone);
-using_csset(X, Key, keyCompareRaw, keyDel, keyFromRaw, keyToRaw, RawKey, flag);
-
-using_csset_str(); // using_csset(str, cstr, cstr_del, cstr_from, cstr_str, const char*, c_true)
```
-The macro `using_csset()` must be instantiated in the global scope. `X` is a type tag name and
-will affect the names of all csset types and methods. E.g. declaring `using_csset(i, int);`, `X` should
-be replaced by `i` in all of the following documentation.
+`X` should be replaced by the value of i_tag in all of the following documentation.
## Methods
@@ -69,10 +67,10 @@ csset_X_value_t csset_X_value_clone(csset_X_value_t val);
## Example
```c
-#include <stc/csset.h>
#include <stc/cstr.h>
-using_csset_str();
+#define i_key_str
+#include <stc/csset.h>
int main ()
{
diff --git a/docs/cstack_api.md b/docs/cstack_api.md
index 3d9ecd4f..0bb5138b 100644
--- a/docs/cstack_api.md
+++ b/docs/cstack_api.md
@@ -8,14 +8,17 @@ See the c++ class [std::stack](https://en.cppreference.com/w/cpp/container/stack
## Header file and declaration
```c
-#include <stc/cstack.h> /* includes default underlying implementation header cvec.h */
-
-using_cstack(X, ctype)
+#define i_tag
+#define i_val // required
+#define i_cmp // required if i_val is a struct
+#define i_valdel
+#define i_valfrom
+#define i_valto
+#define i_valraw
+#include <stc/cstack.h>
```
-The macro `using_cstack()` must be instantiated in the global scope. **cstack** uses normally
-a **cvec_X** or **cdeq_X** type as underlying implementation, given as `ctype`. `X` is a type tag name and will
-affect the names of all cstack types and methods. E.g. declaring `using_cstack(i, cvec_i);`,
-`X` should be replaced by `i` in all of the following documentation.
+`X` should be replaced by the value of i_tag in all of the following documentation.
+
## Methods
@@ -54,12 +57,11 @@ cstack_X_value_t cstack_X_value_clone(cstack_X_value_t val);
## Example
```c
+#define i_tag i
+#define i_val int
#include <stc/cstack.h>
#include <stdio.h>
-using_cvec(i, int);
-using_cstack(i, cvec_i);
-
int main() {
cstack_i S = cstack_i_init();
diff --git a/docs/cvec_api.md b/docs/cvec_api.md
index 5a98b9ca..e04c0a8d 100644
--- a/docs/cvec_api.md
+++ b/docs/cvec_api.md
@@ -12,23 +12,16 @@ See the c++ class [std::vector](https://en.cppreference.com/w/cpp/container/vect
## Header file and declaration
```c
+#define i_tag
+#define i_val // required
+#define i_cmp // required if i_val is a struct
+#define i_valdel
+#define i_valfrom
+#define i_valto
+#define i_valraw
#include <stc/cvec.h>
-
-using_cvec(X, Value);
-using_cvec(X, Value, valueCompare);
-using_cvec(X, Value, valueCompare, valueDel, valueClone = c_no_clone);
-using_cvec(X, Value, valueCompareRaw, valueDel, valueFromRaw, valueToRaw, RawValue);
-
-using_cvec_str(); // using_cvec(str, cstr, ...)
-```
-The macro `using_cvec()` must be instantiated in the global scope. `X` is a type tag name and
-will affect the names of all cvec types and methods. E.g. declaring `using_cvec(i, int);`, `X` should
-be replaced by `i` in all of the following documentation.
-
-`using_cvec_str()` is a shorthand for:
-```
-using_cvec(str, cstr, c_rawstr_compare, cstr_del, cstr_from, cstr_str, const char*)
```
+`X` should be replaced by the value of i_tag in all of the following documentation.
## Methods
@@ -103,11 +96,11 @@ cvec_X_value_t cvec_X_value_clone(cvec_X_value_t val);
## Examples
```c
+#define i_tag i
+#define i_val int
#include <stc/cvec.h>
#include <stdio.h>
-using_cvec(i, int);
-
int main()
{
// Create a vector containing integers
@@ -143,10 +136,10 @@ sorted: 5 7 8 13 16 25
```
### Example 2
```c
-#include <stc/cvec.h>
#include <stc/cstr.h>
-using_cvec_str();
+#define i_val_str
+#include <stc/cvec.h>
int main() {
cvec_str names = cvec_str_init();
@@ -178,7 +171,6 @@ item: 2 elements so far
Container with elements of structs:
```c
#include <stc/cstr.h>
-#include <stc/cvec.h>
typedef struct {
cstr name; // dynamic string
@@ -198,7 +190,12 @@ User User_clone(User user) {
}
// declare a memory managed, clonable vector of users:
-using_cvec(u, User, User_compare, User_del, User_clone);
+#define i_tag u
+#define i_val User
+#define i_cmp User_compare
+#define i_valdel User_del
+#define i_valfrom User_clone
+#include <stc/cvec.h>
int main(void) {
cvec_u vec = cvec_u_init();