summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2021-09-11 22:58:58 +0200
committerTyge Løvset <[email protected]>2021-09-11 22:58:58 +0200
commita2aa14cc91ccbd42cd1188c6fac6126a38d0de77 (patch)
tree843baa1eba7abae70b54326ca898607eedbc5e76
parent658019e1e53ad1ccbca5c623b7199c445eab8b86 (diff)
downloadSTC-modified-a2aa14cc91ccbd42cd1188c6fac6126a38d0de77.tar.gz
STC-modified-a2aa14cc91ccbd42cd1188c6fac6126a38d0de77.zip
Fixed docs for newstyle.
-rw-r--r--README.md6
-rw-r--r--benchmarks/others/clist_v1.h2
-rw-r--r--benchmarks/others/csmap_v1.h2
-rw-r--r--docs/ccommon_api.md14
-rw-r--r--docs/clist_api.md23
-rw-r--r--docs/cmap_api.md2
-rw-r--r--docs/cpque_api.md20
-rw-r--r--docs/cqueue_api.md49
-rw-r--r--docs/crandom_api.md10
-rw-r--r--docs/csmap_api.md4
-rw-r--r--docs/csptr_api.md14
-rw-r--r--docs/cstack_api.md5
-rw-r--r--docs/csview_api.md55
-rw-r--r--examples/queue.c16
-rw-r--r--include/stc/csset.h5
15 files changed, 77 insertions, 150 deletions
diff --git a/README.md b/README.md
index 1c73a8ff..599762ef 100644
--- a/README.md
+++ b/README.md
@@ -17,13 +17,13 @@ multimap/set variants. However, there is an example how to create a multimap in
- [***cdeq*** - **std::deque** alike type](docs/cdeq_api.md)
- [***clist*** - **std::forward_list** alike type](docs/clist_api.md)
- [***cmap*** - **std::unordered_map** alike type](docs/cmap_api.md)
-- [***cpque*** - **std::priority_queue** alike (adapter) type](docs/cpque_api.md)
+- [***cpque*** - **std::priority_queue** alike type](docs/cpque_api.md)
- [***csptr*** - **std::shared_ptr** alike support](docs/csptr_api.md)
-- [***cqueue*** - **std::queue** alike (adapter) type](docs/cqueue_api.md)
+- [***cqueue*** - **std::queue** alike type](docs/cqueue_api.md)
- [***cset*** - **std::unordered_set** alike type](docs/cset_api.md)
- [***csmap*** - **std::map** sorted map alike type](docs/csmap_api.md)
- [***csset*** - **std::set** sorted set alike type](docs/csset_api.md)
-- [***cstack*** - **std::stack** alike (adapter) type](docs/cstack_api.md)
+- [***cstack*** - **std::stack** alike type](docs/cstack_api.md)
- [***cstr*** - **std::string** alike type](docs/cstr_api.md)
- [***csview*** - **std::string_view** alike type](docs/csview_api.md)
- [***cvec*** - **std::vector** alike type](docs/cvec_api.md)
diff --git a/benchmarks/others/clist_v1.h b/benchmarks/others/clist_v1.h
index 0dd8feef..7b5fe7e6 100644
--- a/benchmarks/others/clist_v1.h
+++ b/benchmarks/others/clist_v1.h
@@ -173,7 +173,7 @@ STC_API size_t _clist_count(const clist_VOID* self);
} \
\
STC_INLINE CX##_iter_t \
- CX##_fwd(CX##_iter_t it, size_t n) { \
+ CX##_advance(CX##_iter_t it, size_t n) { \
while (n-- && it.ref) CX##_next(&it); return it; \
} \
\
diff --git a/benchmarks/others/csmap_v1.h b/benchmarks/others/csmap_v1.h
index 69f3f06d..76071e24 100644
--- a/benchmarks/others/csmap_v1.h
+++ b/benchmarks/others/csmap_v1.h
@@ -287,7 +287,7 @@ int main(void) {
} \
\
STC_INLINE CX##_iter_t \
- CX##_fwd(CX##_iter_t it, size_t n) { \
+ CX##_advance(CX##_iter_t it, size_t n) { \
while (n-- && it.ref) CX##_next(&it); \
return it; \
} \
diff --git a/docs/ccommon_api.md b/docs/ccommon_api.md
index 0eb11f82..dc274869 100644
--- a/docs/ccommon_api.md
+++ b/docs/ccommon_api.md
@@ -38,7 +38,9 @@ c_forauto (cstr, s1, s2)
printf("%s %s\n", s1.str, s2.str);
}
-using_cvec(i32, int32_t);
+#define i_tag i32
+#define i_val int32_t
+#include <stc/cvec.h>
...
cvec_i32 vec;
c_forscope (vec = cvec_i32_init(), cvec_i32_del(&vec))
@@ -59,9 +61,9 @@ c_fordefer (cstr_del(&s1), cstr_del(&s2))
```c
#include <errno.h>
#include <stc/cstr.h>
-#include <stc/cvec.h>
-using_cvec_str();
+#define i_val_str
+#include <stc/cvec.h>
// receiver should check errno variable
cvec_str readFile(const char* name)
@@ -91,9 +93,11 @@ int main()
| `c_foreach (it, ctype, it1, it2)` | Iterate the range [it1, it2) |
```c
-using_csset(x, int);
+#define i_tag x
+#define i_key int
+#include <stc/csset.h>
...
-c_var (csset_x, set, {23, 3, 7, 5, 12});
+c_emplace(csset_x, set, {23, 3, 7, 5, 12});
c_foreach (i, csset_x, set)
printf(" %d", *i.ref);
// 3 5 7 12 23
diff --git a/docs/clist_api.md b/docs/clist_api.md
index 9d50b7ec..b4f1d750 100644
--- a/docs/clist_api.md
+++ b/docs/clist_api.md
@@ -13,8 +13,8 @@ and *clist_X_sort()* which is **O**(*n* log(*n*)).
***Iterator invalidation***: Adding, removing and moving the elements within the list, or across several lists
will invalidate other iterators currently refering to these elements and their immediate succesive elements.
However, an iterator to a succesive element can both be dereferenced and advanced. After advancing, it is
-in a fully valid state. This implies that if `clist_X_insert(&L, clist_X_fwd(it,1), x)` and
-`clist_X_erase_at(&L, clist_X_fwd(it,1))` are used consistently, only iterators to erased elements are invalidated.
+in a fully valid state. This implies that if `clist_X_insert(&L, clist_X_advance(it,1), x)` and
+`clist_X_erase_at(&L, clist_X_advance(it,1))` are used consistently, only iterators to erased elements are invalidated.
See the c++ class [std::list](https://en.cppreference.com/w/cpp/container/list) for similar API and
[std::forward_list](https://en.cppreference.com/w/cpp/container/forward_list) for a functional description.
@@ -77,7 +77,7 @@ void clist_X_sort(clist_X* self);
clist_X_iter_t clist_X_begin(const clist_X* self);
clist_X_iter_t clist_X_end(const clist_X* self);
void clist_X_next(clist_X_iter_t* it);
-clist_X_iter_t clist_X_fwd(clist_X_iter it, size_t n); // return it n elements ahead. End allowed.
+clist_X_iter_t clist_X_advance(clist_X_iter it, size_t n); // return it n elements ahead. End allowed.
clist_X_rawvalue_t clist_X_value_toraw(clist_X_value_t* pval);
clist_X_value_t clist_X_value_clone(clist_X_value_t val);
@@ -175,16 +175,19 @@ Splice `[30, 40]` from *L2* into *L1* before `3`:
#include <stdio.h>
int main() {
- c_var (clist_i, L1, {1, 2, 3, 4, 5});
- c_var (clist_i, L2, {10, 20, 30, 40, 50});
+ c_forauto (clist_i, L1, L2)
+ {
+ c_emplace(clist_i, L1, {1, 2, 3, 4, 5});
+ c_emplace(clist_i, L2, {10, 20, 30, 40, 50});
- clist_i_iter_t i = clist_i_fwd(clist_i_begin(&L1), 2);
- clist_i_iter_t j1 = clist_i_fwd(clist_i_begin(&L2), 2), j2 = clist_i_fwd(j1, 2);
+ clist_i_iter_t i = clist_i_advance(clist_i_begin(&L1), 2);
+ clist_i_iter_t j1 = clist_i_advance(clist_i_begin(&L2), 2), j2 = clist_i_advance(j1, 2);
- clist_i_splice_range(&L1, i, &L2, j1, j2);
+ clist_i_splice_range(&L1, i, &L2, j1, j2);
- c_foreach (i, clist_i, L1) printf(" %d", *i.ref); puts("");
- c_foreach (i, clist_i, L2) printf(" %d", *i.ref); puts("");
+ c_foreach (i, clist_i, L1) printf(" %d", *i.ref); puts("");
+ c_foreach (i, clist_i, L2) printf(" %d", *i.ref); puts("");
+ }
}
```
Output:
diff --git a/docs/cmap_api.md b/docs/cmap_api.md
index 32ae2d1f..28ffc872 100644
--- a/docs/cmap_api.md
+++ b/docs/cmap_api.md
@@ -146,7 +146,7 @@ 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.
+This example uses a cmap with cstr as mapped value.
```c
#include <stc/cstr.h>
diff --git a/docs/cpque_api.md b/docs/cpque_api.md
index 8349a4b6..dba3fe3a 100644
--- a/docs/cpque_api.md
+++ b/docs/cpque_api.md
@@ -8,18 +8,16 @@ See the c++ class [std::priority_queue](https://en.cppreference.com/w/cpp/contai
## 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/cpque.h>
-
-using_cpque(X, ctype); // uses valueCompare from ctype
-using_cpque(X, ctype, valueCompare);
```
-The macro `using_cpque()` must be instantiated in the global scope. **cpque** uses normally **cvec_X**
-or **cdeq_X** as underlying implementation, specified as `ctype`. The *valueCompare* can be specified
-to control the order in the priority queue.
-
-By default, the function *`ctype`_value_compare(x, y)* from the underlying vector type is used for
-comparing values (priorities). `X` is a type tag name and will affect the names of all cpque types and methods.
-When declaring `using_cpque(i, cvec_i)`, `X` should be replaced by `i` in the following documentation.
+`X` should be replaced by the value of i_tag in all of the following documentation.
## Methods
@@ -70,7 +68,7 @@ int main()
stc64_uniform_t dist = stc64_uniform_init(0, N * 10);
// Declare heap, with defered del()
- c_forvar (cpque_i heap = cpque_i_init(), cpque_i_del(&heap))
+ c_forauto (cpque_i, heap)
{
// Push ten million random numbers to priority queue, plus some negative ones.
c_forrange (N)
diff --git a/docs/cqueue_api.md b/docs/cqueue_api.md
index dac51564..eb1450a3 100644
--- a/docs/cqueue_api.md
+++ b/docs/cqueue_api.md
@@ -1,20 +1,23 @@
# STC [cqueue](../include/stc/cqueue.h): Queue
![Queue](pics/queue.jpg)
-The **cqueue** is container adapter that gives the programmer the functionality of a queue - specifically, a FIFO (first-in, first-out) data structure. The class template acts as a wrapper to the underlying container - only a specific set of functions is provided. The queue pushes the elements on the back of the underlying container and pops them from the front.
+The **cqueue** is container that gives the programmer the functionality of a queue - specifically, a FIFO (first-in, first-out) data structure. The queue pushes the elements on the back of the underlying container and pops them from the front.
See the c++ class [std::queue](https://en.cppreference.com/w/cpp/container/queue) for a functional reference.
## Header file and declaration
```c
-#include <stc/cqueue.h> /* includes default underlying implementation header cdeq.h */
-
-using_cqueue(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/cqueue.h>
```
-The macro `using_cqueue()` must be instantiated in the global scope. **cqueue** uses normally
-a **cdeq_X** or **clist_X** type as underlying implementation, given as `ctype`. See example below for usage.
-`X` is a type tag name and will affect the names of all cqueue types and methods. E.g. declaring
-`using_cqueue(i, clist_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
@@ -80,33 +83,3 @@ Output:
```
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
```
-### Example 2
-Use clist as underlying cqueue implementation.
-```c
-#include <stc/cqueue.h>
-#include <stc/clist.h>
-#include <stdio.h>
-
-using_clist(i, int);
-using_cqueue(i, clist_i);
-
-int main() {
- cqueue_i Q = cqueue_i_init();
-
- // push() and pop() a few.
- c_forrange (i, 20)
- cqueue_i_push(&Q, i);
-
- c_forrange (5)
- cqueue_i_pop(&Q);
-
- c_foreach (i, cqueue_i, Q)
- printf(" %d", *i.ref);
-
- cqueue_i_del(&Q);
-}
-```
-Output:
-```
-5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
-```
diff --git a/docs/crandom_api.md b/docs/crandom_api.md
index 4093204e..6398e197 100644
--- a/docs/crandom_api.md
+++ b/docs/crandom_api.md
@@ -69,15 +69,15 @@ double stc64_normalf(stc64_t* rng, stc64_normalf_t* dist);
## Example
```c
-#include <stdio.h>
#include <time.h>
-
#include <stc/crandom.h>
-#include <stc/csmap.h>
#include <stc/cstr.h>
// Declare int -> int sorted map. Uses typetag 'i' for ints.
-using_csmap(i, int, size_t);
+#define i_tag i
+#define i_key int
+#define i_val size_t
+#include <stc/csmap.h>
int main()
{
@@ -95,7 +95,7 @@ int main()
csmap_i mhist = csmap_i_init();
c_forrange (N) {
int index = (int) round( stc64_normalf(&rng, &dist) );
- ++ csmap_i_emplace(&mhist, index, 0).ref->second;
+ csmap_i_emplace(&mhist, index, 0).ref->second += 1;
}
// Print the gaussian bar chart
diff --git a/docs/csmap_api.md b/docs/csmap_api.md
index 6589417f..6fdd3857 100644
--- a/docs/csmap_api.md
+++ b/docs/csmap_api.md
@@ -61,7 +61,7 @@ csmap_X_iter_t csmap_X_erase_range(csmap_X* self, csmap_X_iter_t it1, csmap
csmap_X_iter_t csmap_X_begin(const csmap_X* self);
csmap_X_iter_t csmap_X_end(const csmap_X* self);
void csmap_X_next(csmap_X_iter_t* iter);
-csmap_X_iter_t csmap_X_fwd(csmap_X_iter_t it, size_t n);
+csmap_X_iter_t csmap_X_advance(csmap_X_iter_t it, size_t n);
csmap_X_value_t csmap_X_value_clone(csmap_X_value_t val);
csmap_X_rawvalue_t csmap_X_value_toraw(csmap_X_value_t* pval);
@@ -122,7 +122,7 @@ 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.
+This example uses a csmap with cstr as mapped value.
```c
#include <stc/cstr.h>
diff --git a/docs/csptr_api.md b/docs/csptr_api.md
index 10d3bb77..a7f37481 100644
--- a/docs/csptr_api.md
+++ b/docs/csptr_api.md
@@ -21,13 +21,16 @@ See the c++ classes [std::shared_ptr](https://en.cppreference.com/w/cpp/memory/s
## 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/csptr.h>
-
-using_csptr(X, Value);
-using_csptr(X, Value, valueCompare);
-using_csptr(X, Value, valueCompare, valueDel);
```
-The macro `using_csptr()` must be instantiated in the global scope. `X` is a type tag name and will affect the names of all csptr types and methods. E.g. declaring `using_csptr(v4, Vec4)`, `X` should be replaced by `v4` in all of the following documentation.
+`X` should be replaced by the value of i_tag in all of the following documentation.
## Methods
@@ -79,6 +82,7 @@ void Person_del(Person* p) {
c_del(cstr, &p->name, &p->last);
}
+
using_csptr(person, Person, c_no_compare, Person_del);
int main() {
diff --git a/docs/cstack_api.md b/docs/cstack_api.md
index 0bb5138b..b971811c 100644
--- a/docs/cstack_api.md
+++ b/docs/cstack_api.md
@@ -1,9 +1,9 @@
# STC [cstack](../include/stc/cstack.h): Stack
![Stack](pics/stack.jpg)
-The **cstack** is a container adapter that gives the programmer the functionality of a stack - specifically, a LIFO (last-in, first-out) data structure. The class template acts as a wrapper to the underlying container - only a specific set of functions is provided. The stack pushes and pops the element from the back of the underlying container, known as the top of the stack.
+The **cstack** is a container that gives the programmer the functionality of a stack - specifically, a LIFO (last-in, first-out) data structure. The stack pushes and pops the element from the back of the underlying container, known as the top of the stack.
-See the c++ class [std::stack](https://en.cppreference.com/w/cpp/container/stack) for a functional description.
+See the c++ class [std::stack](https://en.cppreference.com/w/cpp/container/stack) for a functional description.
## Header file and declaration
@@ -19,7 +19,6 @@ See the c++ class [std::stack](https://en.cppreference.com/w/cpp/container/stack
```
`X` should be replaced by the value of i_tag in all of the following documentation.
-
## Methods
```c
diff --git a/docs/csview_api.md b/docs/csview_api.md
index dfca37c5..905a6489 100644
--- a/docs/csview_api.md
+++ b/docs/csview_api.md
@@ -7,7 +7,7 @@ element of the sequence at position zero. The implementation holds two members:
**csview** is an efficient replacent for `const char*`. It never allocates memory, and therefore need not be destructed.
Its lifetime is limited by the source string storage. It keeps the length of the string, and does not call *strlen()*
when passing it around. It is faster when using`csview` as convertion type (raw) than `const char*` in associative
-containers with cstr keys. `using_cmap_strvkey()` may perform better than `using_cmap_strkey()`.
+containers with cstr keys.
Note: a **csview** may ***not be null-terminated***, and must therefore be printed like:
`printf("%.*s", csview_ARG(sv))`.
@@ -98,23 +98,6 @@ uint64_t csview_hash(const csview* x, ...);
| `csview_npos` | same as `cstr_npos` | |
| `csview_ARG(sv)` | printf argument | `printf("%.*s", csview_ARG(sv));` |
-## Associative cstr-containers with csview emplace/lookup API
-```
-using_csmap_strvkey(X, Mapped)
-using_csmap_strvkey(X, Mapped, mappedDel)
-using_csmap_strvkey(X, Mapped, mappedDel, mappedClone)
-using_csmap_strvkey(X, Mapped, mappedDel, mappedFromRaw, mappedToRaw, RawMapped)
-using_csmap_strv()
-using_csset_strv()
-
-using_cmap_strvkey(X, Mapped)
-using_cmap_strvkey(X, Mapped, mappedDel)
-using_cmap_strvkey(X, Mapped, mappedDel, mappedClone)
-using_cmap_strvkey(X, Mapped, mappedDel, mappedFromRaw, mappedToRaw, RawMapped)
-using_cmap_strv()
-using_cset_strv()
-```
-
## Example
```c
#include <stc/csview.h>
@@ -149,7 +132,6 @@ Splits strings into tokens. *print_split()* makes **no** memory allocations or *
and does not depend on null-terminated strings. *string_split()* function returns a vector of cstr.
```c
#include <stc/csview.h>
-#include <stc/cvec.h>
void print_split(csview str, csview sep)
{
@@ -162,7 +144,8 @@ void print_split(csview str, csview sep)
}
}
-using_cvec_str();
+#define i_val_str
+#include <stc/cvec.h>
cvec_str string_split(csview str, csview sep)
{
@@ -204,36 +187,4 @@ Output:
"string"
"now"
""
-```
-### Example 3
-cmap cstr => int with csview as convertion type
-```c
-#include <stc/csview.h>
-#include <stc/cvec.h>
-#include <stc/cmap.h>
-using_cmap_strvkey(si, int);
-
-int main()
-{
- csview text = c_sv("The length of this literal is evaluated at compile time and stored in csview text.");
- csview suffix = csview_substr(text, -12, cstr_npos); // from pos -12 to end
- printf("%.*s\n", csview_ARG(suffix));
-
- c_forauto (cmap_si, map)
- {
- cmap_si_emplace(&map, c_sv("hello"), 100);
- cmap_si_emplace(&map, c_sv("world"), 200);
- cmap_si_emplace(&map, c_sv("hello"), 300); // already in map, ignored
-
- // Efficient lookup: no string allocation or strlen() takes place:
- cmap_si_value_t* val = cmap_si_get(&map, c_sv("hello"));
- printf("%s: %d\n", val->first.str, val->second);
- }
-}
-```
-Output:
-```
-csview text.
-hello: 100
-```
diff --git a/examples/queue.c b/examples/queue.c
index 1e96b53a..dabb0a08 100644
--- a/examples/queue.c
+++ b/examples/queue.c
@@ -1,15 +1,9 @@
#include <stc/crandom.h>
-#include <stc/cqueue.h>
#include <stdio.h>
-#if 1
-using_cdeq(i, int);
-using_cqueue(i, cdeq_i);
-#else
-#include <stc/clist.h>
-using_clist(i, int);
-using_cqueue(i, clist_i);
-#endif
+#define i_tag i
+#define i_val int
+#include <stc/cqueue.h>
int main() {
int n = 100000000;
@@ -17,7 +11,7 @@ int main() {
stc64_t rng = stc64_init(1234);
dist = stc64_uniform_init(0, n);
- c_forvar (cqueue_i queue = cqueue_i_init(), cqueue_i_del(&queue))
+ c_forauto (cqueue_i, queue)
{
// Push ten million random numbers onto the queue.
c_forrange (n)
@@ -25,7 +19,7 @@ int main() {
// Push or pop on the queue ten million times
printf("%d\n", n);
- c_forrange (n) { // range uses initial n only.
+ c_forrange (n) { // forrange uses initial n only.
int r = stc64_uniform(&rng, &dist);
if (r & 1)
++n, cqueue_i_push(&queue, r);
diff --git a/include/stc/csset.h b/include/stc/csset.h
index f2378095..44fbfa54 100644
--- a/include/stc/csset.h
+++ b/include/stc/csset.h
@@ -23,10 +23,11 @@
// Sorted set - implemented as an AA-tree (balanced binary tree).
/*
-#include <stc/csset.h>
#include <stdio.h>
-using_csset(i, int); // sorted set of int
+#define i_tag i
+#define i_key int
+#include <stc/csset.h> // sorted set of int
int main(void) {
csset_i s = csset_i_init();