diff options
| author | Tyge Løvset <[email protected]> | 2022-09-26 08:08:47 +0200 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2022-09-26 08:08:47 +0200 |
| commit | ca01dd726e2ed8f8b69f8ff08855e80f4eea7247 (patch) | |
| tree | 0ce1594c39d18a93212f066fd8c3c2477fc6f22b /docs | |
| parent | ad5be4349232bbba96c0974bc2693ec7331c4b12 (diff) | |
| download | STC-modified-ca01dd726e2ed8f8b69f8ff08855e80f4eea7247.tar.gz STC-modified-ca01dd726e2ed8f8b69f8ff08855e80f4eea7247.zip | |
DEPRECATED: c_forrange(): replaced with c_forloop(). This uses 'long long' as iter type, i.e. "%lld" printf format.
crange_from() renamed to crange_make().
More docs.
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/ccommon_api.md | 43 | ||||
| -rw-r--r-- | docs/clist_api.md | 2 | ||||
| -rw-r--r-- | docs/cpque_api.md | 6 | ||||
| -rw-r--r-- | docs/cqueue_api.md | 4 | ||||
| -rw-r--r-- | docs/crandom_api.md | 2 | ||||
| -rw-r--r-- | docs/cregex_api.md | 8 |
6 files changed, 32 insertions, 33 deletions
diff --git a/docs/ccommon_api.md b/docs/ccommon_api.md index 2d26fbe3..70033445 100644 --- a/docs/ccommon_api.md +++ b/docs/ccommon_api.md @@ -180,37 +180,36 @@ c_forlist (i, csmap_ii_raw, { {23,1}, {3,2}, {7,3}, {5,4}, {12,5} }) c_foreach (i, csmap_ii, map) printf(" %d", i.ref->first); -// out: 3 5 7 12 23 +// 3 5 7 12 23 csmap_ii_iter it = csmap_ii_find(&map, 7); c_foreach (i, csmap_ii, it, csmap_ii_end(&map)) printf(" %d", i.ref->first); -// out: 7 12 23 +// 7 12 23 c_forpair (id, count, csmap_ii, map) printf(" (%d %d)", *_.id, *_.count); -// out: (3 2) (5 4) (7 3) (12 5) (23 1) +// (3 2) (5 4) (7 3) (12 5) (23 1) ``` -### c_forrange -Abstaction for iterating sequence of numbers. Like python's ***for i in range()*** loop. +### c_forloop +Abstaction for iterating sequence of numbers. Like python's **for** *i* **in** *range()* loop. -| Usage | Python equivalent | -|:----------------------------------------------|:-------------------------------------| -| `c_forrange (stop)` | `for _ in range(stop):` | -| `c_forrange (i, stop) // IntType = size_t` | `for i in range(stop):` | -| `c_forrange (i, IntType, stop)` | `for i in range(stop):` | -| `c_forrange (i, IntType, start, stop)` | `for i in range(start, stop):` | -| `c_forrange (i, IntType, start, stop, step)` | `for i in range(start, stop, step):` | +| Usage | Python equivalent | +|:--------------------------------------------|:-------------------------------------| +| `c_forloop (stop)` | `for _ in range(stop):` | +| `c_forloop (i, stop) // i type = long long` | `for i in range(stop):` | +| `c_forloop (i, start, stop)` | `for i in range(start, stop):` | +| `c_forloop (i, start, stop, step)` | `for i in range(start, stop, step):` | ```c -c_forrange (5) printf("x"); +c_forloop (5) printf("x"); // xxxxx -c_forrange (i, 5) printf(" %" PRIuMAX "", i); +c_forloop (i, 5) printf(" %lld", i); // 0 1 2 3 4 -c_forrange (i, int, -3, 3) printf(" %d", i); +c_forloop (i, -3, 3) printf(" %lld", i); // -3 -2 -1 0 1 2 -c_forrange (i, int, 30, 0, -5) printf(" %d", i); +c_forloop (i, 30, 0, -5) printf(" %lld", i); // 30 25 20 15 10 5 ``` @@ -244,7 +243,7 @@ bool isPrime(int i) { int main() { c_auto (IVec, vec) { - c_forrange (i, 1000) IVec_push(&vec, 1000000 + i); + c_forloop (i, 1000) IVec_push(&vec, 1000000 + i); c_forfilter (i, IVec, vec, isOdd(*i.ref) @@ -261,12 +260,12 @@ int main() { Note that `c_flt_take()` is given as an optional argument, which makes the loop stop when it becomes false (for efficiency). Chaining it after `isPrime()` instead will give same result, but the full input is processed. ### crange -**crange** is a number sequence generator type. The **crange_value** type is `long long`. Below, *start*, *end*, *step* are type *crange_value*: +**crange** is a number sequence generator type. The **crange_value** type is `long long`. Below, *start*, *stop*, *step* are type *crange_value*: ```c crange crange_init(void); // will generate 0, 1, 2, ... -crange crange_from(start); // will generate start, start+1, ... -crange crange_from(start, end); // will generate start, start+1, ... end-1 -crange crange_from(start, end, step); // will generate start, start+step, ... upto-not-including end +crange crange_make(stop); // will generate 0, 1, ..., stop-1 +crange crange_make(start, stop); // will generate start, start+1, ... stop-1 +crange crange_make(start, stop, step); // will generate start, start+step, ... upto-not-including stop // note that step may be negative. crange_iter crange_begin(crange* self); crange_iter crange_end(crange* self); @@ -281,7 +280,7 @@ c_forfilter (i, crange, r1, // 2 3 5 7 11 13 17 19 23 29 31 // 2. The 11 first primes: -crange r2 = crange_from(3, INTMAX_MAX, 2); +crange r2 = crange_make(3, INTMAX_MAX, 2); printf("2"); c_forfilter (i, crange, r2, isPrime(*i.ref) diff --git a/docs/clist_api.md b/docs/clist_api.md index 9927087d..58afb64a 100644 --- a/docs/clist_api.md +++ b/docs/clist_api.md @@ -114,7 +114,7 @@ int main() { c_forlist (i, double, {10., 20., 30., 40., 50., 60., 70., 80., 90.}) DList_push_back(&list, *i.ref); - c_forrange (i, int, 1, 10) { + c_forloop (i, 1, 10) { if (i & 1) DList_push_front(&list, (double) i); else DList_push_back(&list, (double) i); } diff --git a/docs/cpque_api.md b/docs/cpque_api.md index 8b990be8..f3e36a3d 100644 --- a/docs/cpque_api.md +++ b/docs/cpque_api.md @@ -76,16 +76,16 @@ int main() c_auto (cpque_i, heap) { // Push ten million random numbers to priority queue. - c_forrange (N) + c_forloop (N) cpque_i_push(&heap, stc64_uniform(&rng, &dist)); // Add some negative ones. int nums[] = {-231, -32, -873, -4, -343}; - c_forrange (i, c_arraylen(nums)) + c_forloop (i, c_arraylen(nums)) cpque_i_push(&heap, nums[i]); // Extract and display the fifty smallest. - c_forrange (50) { + c_forloop (50) { printf("%" PRIdMAX " ", *cpque_i_top(&heap)); cpque_i_pop(&heap); } diff --git a/docs/cqueue_api.md b/docs/cqueue_api.md index a8be9e86..43f953b3 100644 --- a/docs/cqueue_api.md +++ b/docs/cqueue_api.md @@ -68,10 +68,10 @@ int main() { cqueue_i Q = cqueue_i_init(); // push() and pop() a few. - c_forrange (i, 20) + c_forloop (i, 20) cqueue_i_push(&Q, i); - c_forrange (5) + c_forloop (5) cqueue_i_pop(&Q); c_foreach (i, cqueue_i, Q) diff --git a/docs/crandom_api.md b/docs/crandom_api.md index 3e6ae8f0..d6180490 100644 --- a/docs/crandom_api.md +++ b/docs/crandom_api.md @@ -94,7 +94,7 @@ int main() // Create histogram map csmap_i mhist = csmap_i_init(); - c_forrange (N) { + c_forloop (N) { int index = (int) round( stc64_normalf(&rng, &dist) ); csmap_i_emplace(&mhist, index, 0).ref->second += 1; } diff --git a/docs/cregex_api.md b/docs/cregex_api.md index 2a0b22a8..66b97834 100644 --- a/docs/cregex_api.md +++ b/docs/cregex_api.md @@ -128,14 +128,14 @@ To iterate multiple matches in an input string, you may use ```c csview match[5] = {0}; while (cregex_find(&re, input, match, cre_m_next) == cre_success) - c_forrange (k, int, cregex_captures(&re)) - printf("submatch %d: %.*s\n", k, c_ARGsv(match[k])); + c_forloop (k, cregex_captures(&re)) + printf("submatch %lld: %.*s\n", k, c_ARGsv(match[k])); ``` There is also a safe macro which simplifies this: ```c c_formatch (it, &re, input) - c_forrange (k, int, cregex_captures(&re)) - printf("submatch %d: %.*s\n", k, c_ARGsv(it.match[k])); + c_forloop (k, cregex_captures(&re)) + printf("submatch %lld: %.*s\n", k, c_ARGsv(it.match[k])); ``` ## Using cregex in a project |
