diff options
| author | Tyge Løvset <[email protected]> | 2021-02-04 13:06:27 +0100 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2021-02-04 13:06:27 +0100 |
| commit | 20dd32503b8f0c556984ecacae83e22d9ac8e73b (patch) | |
| tree | f1ac366f3182f7a2fefb4860152a153df397ee58 /docs | |
| parent | bb15765f34e22bc09eee029e19b8be01c49462a9 (diff) | |
| download | STC-modified-20dd32503b8f0c556984ecacae83e22d9ac8e73b.tar.gz STC-modified-20dd32503b8f0c556984ecacae83e22d9ac8e73b.zip | |
Changed return type it iter_t in csmap_X_find() and cmap_X_find() to be consistent.
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/ccommon_api.md | 50 | ||||
| -rw-r--r-- | docs/cmap_api.md | 4 | ||||
| -rw-r--r-- | docs/csmap_api.md | 4 |
3 files changed, 39 insertions, 19 deletions
diff --git a/docs/ccommon_api.md b/docs/ccommon_api.md index 596ba4ad..210c75ae 100644 --- a/docs/ccommon_api.md +++ b/docs/ccommon_api.md @@ -5,26 +5,27 @@ This describes the features the ccommon.h header file. ## Macros The following macros a completely safe to use, with no side-effects. -#### c_new, c_del -- Type* c_new (VType) -- Type* c_new (VType, size_t N) -- c_del (CType, CType* x1, ..., CType* xN) -#### c_malloc, c_calloc, c_realloc, c_free -Macros that can be overloaded by user to use a different allocator for the entire library +#### c_new, c_del -#### c_foreach -- c_foreach (it, CType, container) +| Usage | Meaning | +|:-------------------------------|:----------------------------------------| +| `c_new (type)` | `(type *) c_malloc(sizeof(type))` | +| `c_new (type, N)` | `(type *) c_malloc((N) * sizeof(type))` | +| `c_del (ctype, c1, ..., cN)` | `ctype_del(c1); ... ctype_del(cN)` | ```c -using_cvec(x, double); -... -cvec_x vec = cvec_x_init(); -double sum = 0; -c_foreach (i, cvec_x, vec) sum += *i.ref; +int* array = c_new (int, 100); +c_free(array); + +cstr a = cstr_from("Hello"), b = cstr_from("World"); +c_del(cstr, &a, &b); ``` +#### c_malloc, c_calloc, c_realloc, c_free +Memory allocator for the entire library. Macros can be overloaded by the user. + #### c_forrange -Declare an iterator and specify a range to iterate with a for loop. Like python's ***range()*** function: +Declare an iterator and specify a range to iterate with a for loop. Like python's ***for i in range()*** function: | Usage | Python equivalent | |:----------------------------------------------|:-------------------------------------| @@ -37,7 +38,7 @@ Declare an iterator and specify a range to iterate with a for loop. Like python' ```c c_forrange (5) printf("x"); // xxxxx -c_forrange (i, 5) printf(" %zu"); +c_forrange (i, 5) printf(" %zu", i); // 0 1 2 3 4 c_forrange (i, int, -3, 3) printf(" %d", i); // -3 -2 -1 0 1 2 @@ -45,6 +46,25 @@ c_forrange (i, int, 30, 0, -5) printf(" %d", i); // 30 25 20 15 10 5 ``` +#### c_foreach + +| Usage | Description | +|:----------------------------------------------|:--------------------------------| +| `c_foreach (it, ctype, container)` | `Iteratate all elements ` | +| `c_foreach (it, ctype, it1, it2)` | `Iterate the range [it1, it2)` | + +```c +using_csset(x, int); +... +c_init (csset_x, set, {23, 3, 7, 5, 12}); +double sum = 0; +c_foreach (i, csset_x, set) printf(" %d", *i.ref); +// 3 5 7 12 23 +csset_x_iter_t it = csset_x_find(&set, 7); +c_foreach (i, csset_x, it, csset_x_end(&set)) printf(" %d", *i.ref); +// 7 12 23 +``` + #### c_withbuffer #### c_withfile diff --git a/docs/cmap_api.md b/docs/cmap_api.md index 3fee4e66..4a39e3ae 100644 --- a/docs/cmap_api.md +++ b/docs/cmap_api.md @@ -79,7 +79,7 @@ size_t cmap_X_erase(cmap_X* self, RawKey rkey); void cmap_X_erase_entry(cmap_X* self, cmap_X_value_t* entry); cmap_X_iter_t cmap_X_erase_at(cmap_X* self, cmap_X_iter_t pos); -cmap_X_value_t* cmap_X_find(const cmap_X* self, RawKey rkey); // NULL if not found +cmap_X_iter_t cmap_X_find(const cmap_X* self, RawKey rkey); bool cmap_X_contains(const cmap_X* self, RawKey rkey); cmap_X_iter_t cmap_X_begin(cmap_X* self); @@ -316,7 +316,7 @@ int main() VikingRaw lookup = {"Einar", "Norway"}; - cmap_vk_value_t *e = cmap_vk_find(&vikings, lookup); + cmap_vk_value_t *e = cmap_vk_find(&vikings, lookup).ref; e->second += 3; // add 3 hp points to Einar cmap_vk_emplace(&vikings, lookup, 0).first->second += 5; // add 5 more to Einar diff --git a/docs/csmap_api.md b/docs/csmap_api.md index 92457d2c..2ebf08d8 100644 --- a/docs/csmap_api.md +++ b/docs/csmap_api.md @@ -68,8 +68,8 @@ csmap_X_mapped_t* csmap_X_at(const csmap_X* self, RawKey rkey); size_t csmap_X_erase(csmap_X* self, RawKey rkey); csmap_X_iter_t csmap_X_erase_at(csmap_X* self, csmap_X_iter_t pos); -csmap_X_value_t* csmap_X_find(const csmap_X* self, RawKey rkey); // NULL if not found -csmap_X_value_t* csmap_X_find_it(const csmap_X* self, RawKey rkey, csmap_X_iter_t* out); +csmap_X_iter_t csmap_X_find(const csmap_X* self, RawKey rkey); +csmap_X_value_t* csmap_X_find_it(const csmap_X* self, RawKey rkey, csmap_X_iter_t* out); // return NULL if not found bool csmap_X_contains(const csmap_X* self, RawKey rkey); csmap_X_iter_t csmap_X_begin(csmap_X* self); |
