summaryrefslogtreecommitdiffhomepage
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/arc_demo.c2
-rw-r--r--examples/birthday.c4
-rw-r--r--examples/bits.c12
-rw-r--r--examples/bits2.c6
-rw-r--r--examples/books.c2
-rw-r--r--examples/convert.c2
-rw-r--r--examples/cpque.c6
-rw-r--r--examples/forfilter.c4
-rw-r--r--examples/gauss1.c2
-rw-r--r--examples/gauss2.c2
-rw-r--r--examples/inits.c2
-rw-r--r--examples/list.c2
-rw-r--r--examples/prime.c4
-rw-r--r--examples/priority.c6
-rw-r--r--examples/queue.c4
-rw-r--r--examples/random.c6
-rw-r--r--examples/regex2.c6
-rw-r--r--examples/stack.c4
18 files changed, 38 insertions, 38 deletions
diff --git a/examples/arc_demo.c b/examples/arc_demo.c
index 688fe72f..345432b6 100644
--- a/examples/arc_demo.c
+++ b/examples/arc_demo.c
@@ -25,7 +25,7 @@ int main()
c_auto (csset_Arc, set) // declare and init set, call csset_Arc_drop() at scope exit
{
const int years[] = {2021, 2012, 2022, 2015};
- c_forrange (i, c_arraylen(years))
+ c_forloop (i, c_arraylen(years))
cvec_Arc_push_back(&vec, Arc_make(years[i]));
printf("vec:");
diff --git a/examples/birthday.c b/examples/birthday.c
index e09d84f1..8b23f7ab 100644
--- a/examples/birthday.c
+++ b/examples/birthday.c
@@ -21,7 +21,7 @@ static void test_repeats(void)
c_auto (cmap_ic, m)
{
cmap_ic_reserve(&m, N);
- c_forrange (i, N) {
+ c_forloop (i, N) {
uint64_t k = stc64_rand(&rng) & mask;
int v = cmap_ic_insert(&m, k, 0).ref->second += 1;
if (v > 1) printf("repeated value %" PRIuMAX " (%d) at 2^%d\n", k, v, (int) log2((double) i));
@@ -42,7 +42,7 @@ void test_distribution(void)
const size_t N = 1ull << BITS ;
c_auto (cmap_x, map) {
- c_forrange (N) {
+ c_forloop (N) {
uint64_t k = stc64_rand(&rng);
cmap_x_insert(&map, k & 0xf, 0).ref->second += 1;
}
diff --git a/examples/bits.c b/examples/bits.c
index c6e70517..c89ad7d3 100644
--- a/examples/bits.c
+++ b/examples/bits.c
@@ -17,7 +17,7 @@ int main()
printf(" str: %s\n", cbits_to_str(&set, str, 0, -1));
printf("%4" PRIuMAX ": ", cbits_size(&set));
- c_forrange (i, cbits_size(&set))
+ c_forloop (i, cbits_size(&set))
printf("%d", cbits_test(&set, i));
puts("");
@@ -27,12 +27,12 @@ int main()
cbits_resize(&set, 102, true);
cbits_set_value(&set, 99, false);
printf("%4" PRIuMAX ": ", cbits_size(&set));
- c_forrange (i, cbits_size(&set))
+ c_forloop (i, cbits_size(&set))
printf("%d", cbits_test(&set, i));
puts("\nIterate:");
printf("%4" PRIuMAX ": ", cbits_size(&set));
- c_forrange (i, cbits_size(&set))
+ c_forloop (i, cbits_size(&set))
printf("%d", cbits_test(&set, i));
puts("");
@@ -42,19 +42,19 @@ int main()
cbits_set(&s2, 17);
cbits_set(&s2, 18);
printf(" new: ");
- c_forrange (i, cbits_size(&s2))
+ c_forloop (i, cbits_size(&s2))
printf("%d", cbits_test(&s2, i));
puts("");
printf(" xor: ");
cbits_xor(&set, &s2);
- c_forrange (i, cbits_size(&set))
+ c_forloop (i, cbits_size(&set))
printf("%d", cbits_test(&set, i));
puts("");
cbits_set_all(&set, false);
printf("%4" PRIuMAX ": ", cbits_size(&set));
- c_forrange (i, cbits_size(&set))
+ c_forloop (i, cbits_size(&set))
printf("%d", cbits_test(&set, i));
puts("");
}
diff --git a/examples/bits2.c b/examples/bits2.c
index 3f3085b6..0161376b 100644
--- a/examples/bits2.c
+++ b/examples/bits2.c
@@ -24,19 +24,19 @@ int main()
Bits_reset(&s2, 66);
Bits_reset(&s2, 67);
printf(" s2: ");
- c_forrange (i, Bits_size(&s2))
+ c_forloop (i, Bits_size(&s2))
printf("%d", Bits_test(&s2, i));
puts("");
printf("xor: ");
Bits_xor(&s1, &s2);
- c_forrange (i, Bits_size(&s1))
+ c_forloop (i, Bits_size(&s1))
printf("%d", Bits_test(&s1, i));
puts("");
printf("all: ");
Bits_set_pattern(&s1, 0x3333333333333333);
- c_forrange (i, Bits_size(&s1))
+ c_forloop (i, Bits_size(&s1))
printf("%d", Bits_test(&s1, i));
puts("");
}
diff --git a/examples/books.c b/examples/books.c
index fb9e4564..eed19540 100644
--- a/examples/books.c
+++ b/examples/books.c
@@ -41,7 +41,7 @@ int main()
// Look up the values associated with some keys.
const char* to_find[] = {"Pride and Prejudice", "Alice's Adventure in Wonderland"};
- c_forrange (i, c_arraylen(to_find)) {
+ c_forloop (i, c_arraylen(to_find)) {
const cmap_str_value* b;
if ((b = cmap_str_get(&book_reviews, to_find[i])))
printf("%s: %s\n", cstr_str(&b->first), cstr_str(&b->second));
diff --git a/examples/convert.c b/examples/convert.c
index 74f4f865..a8260564 100644
--- a/examples/convert.c
+++ b/examples/convert.c
@@ -37,7 +37,7 @@ int main()
cvec_str_emplace_back(&keys, cstr_str(&i.ref->first));
cvec_str_emplace_back(&values, cstr_str(&i.ref->second));
}
- c_forrange (i, cvec_str_size(&keys))
+ c_forloop (i, cvec_str_size(&keys))
printf(" %s: %s\n", cstr_str(keys.data + i), cstr_str(values.data + i));
puts("\nCOPY VEC TO LIST:");
diff --git a/examples/cpque.c b/examples/cpque.c
index 5866f17b..183f83c1 100644
--- a/examples/cpque.c
+++ b/examples/cpque.c
@@ -31,15 +31,15 @@ int main()
c_auto (ipque, q, q2, q3) // init() and defered drop()
{
less_fn = int_less;
- c_forrange (i, n) ipque_push(&q, data[i]);
+ c_forloop (i, n) ipque_push(&q, data[i]);
print_queue(q);
less_fn = int_greater;
- c_forrange (i, n) ipque_push(&q2, data[i]);
+ c_forloop (i, n) ipque_push(&q2, data[i]);
print_queue(q2);
less_fn = int_lambda;
- c_forrange (i, n) ipque_push(&q3, data[i]);
+ c_forloop (i, n) ipque_push(&q3, data[i]);
print_queue(q3);
}
}
diff --git a/examples/forfilter.c b/examples/forfilter.c
index 29128836..3ac7821b 100644
--- a/examples/forfilter.c
+++ b/examples/forfilter.c
@@ -59,7 +59,7 @@ fn main() {
void demo2(void)
{
c_auto (IVec, vector) {
- crange rv = crange_from(1);
+ crange rv = crange_make(1, INTMAX_MAX);
c_forfilter (x, crange, rv,
flt_odd(x)
, c_flt_take(x, 5))
@@ -121,7 +121,7 @@ void demo5(void)
#define flt_even(i) ((*i.ref & 1) == 0)
#define flt_mid_decade(i) ((*i.ref % 10) != 0)
puts("demo5:");
- crange r1 = crange_from(1963);
+ crange r1 = crange_make(1963, INTMAX_MAX);
c_forfilter (i, crange, r1,
c_flt_drop(i,15)
&& c_flt_dropwhile(i, flt_mid_decade(i))
diff --git a/examples/gauss1.c b/examples/gauss1.c
index da6d73f4..81d57852 100644
--- a/examples/gauss1.c
+++ b/examples/gauss1.c
@@ -32,7 +32,7 @@ int main()
c_auto (cvec_ii, histvec)
c_auto (cmap_ii, histmap)
{
- c_forrange (N) {
+ c_forloop (N) {
int index = (int) round( stc64_normalf(&rng, &dist) );
cmap_ii_insert(&histmap, index, 0).ref->second += 1;
}
diff --git a/examples/gauss2.c b/examples/gauss2.c
index 2e07c5a5..6bbd7fb3 100644
--- a/examples/gauss2.c
+++ b/examples/gauss2.c
@@ -25,7 +25,7 @@ int main()
// Create and init histogram map with defered destruct
c_auto (csmap_int, mhist)
{
- c_forrange (N) {
+ c_forloop (N) {
int index = (int) round( stc64_normalf(&rng, &dist) );
csmap_int_insert(&mhist, index, 0).ref->second += 1;
}
diff --git a/examples/inits.c b/examples/inits.c
index ab6cdce9..875406e1 100644
--- a/examples/inits.c
+++ b/examples/inits.c
@@ -40,7 +40,7 @@ int main(void)
const float nums[] = {4.0f, 2.0f, 5.0f, 3.0f, 1.0f};
// PRIORITY QUEUE
- c_forrange (i, c_arraylen(nums))
+ c_forloop (i, c_arraylen(nums))
cpque_f_push(&floats, nums[i]);
puts("\npop and show high priorites first:");
diff --git a/examples/list.c b/examples/list.c
index e94a9f18..42be81f3 100644
--- a/examples/list.c
+++ b/examples/list.c
@@ -17,7 +17,7 @@ int main() {
stc64_t rng = stc64_new(1234);
stc64_uniformf_t dist = stc64_uniformf_new(100.0f, n);
int m = 0;
- c_forrange (n)
+ c_forloop (n)
clist_fx_push_back(&list, stc64_uniformf(&rng, &dist)), ++m;
double sum = 0.0;
printf("sumarize %d:\n", m);
diff --git a/examples/prime.c b/examples/prime.c
index d2a95af5..12d33a9e 100644
--- a/examples/prime.c
+++ b/examples/prime.c
@@ -39,9 +39,9 @@ int main(void)
puts("");
int k = 20;
- c_forrange (i, intptr_t, n-1, 1, -2) {
+ c_forloop (i, n-1, 1, -2) {
if (k == 0) break;
- else if (cbits_test(&primes, i>>1)) printf("%" PRIdMAX "\n", i), k--;
+ else if (cbits_test(&primes, i>>1)) printf("%lld\n", i), k--;
}
puts("");
}
diff --git a/examples/priority.c b/examples/priority.c
index d801c118..452ed9d4 100644
--- a/examples/priority.c
+++ b/examples/priority.c
@@ -16,18 +16,18 @@ int main() {
{
// Push ten million random numbers to priority queue
printf("Push %" PRIuMAX " numbers\n", N);
- c_forrange (N)
+ c_forloop (N)
cpque_i_push(&heap, stc64_uniform(&rng, &dist));
// push some negative numbers too.
c_forlist (i, int, {-231, -32, -873, -4, -343})
cpque_i_push(&heap, *i.ref);
- c_forrange (N)
+ c_forloop (N)
cpque_i_push(&heap, stc64_uniform(&rng, &dist));
puts("Extract the hundred smallest.");
- c_forrange (100) {
+ c_forloop (100) {
printf("%" PRIdMAX " ", *cpque_i_top(&heap));
cpque_i_pop(&heap);
}
diff --git a/examples/queue.c b/examples/queue.c
index cc6f8302..7be25367 100644
--- a/examples/queue.c
+++ b/examples/queue.c
@@ -14,12 +14,12 @@ int main() {
c_auto (cqueue_i, queue)
{
// Push ten million random numbers onto the queue.
- c_forrange (n)
+ c_forloop (n)
cqueue_i_push(&queue, stc64_uniform(&rng, &dist));
// Push or pop on the queue ten million times
printf("%d\n", n);
- c_forrange (n) { // forrange uses initial n only.
+ c_forloop (n) { // forrange uses initial n only.
int r = stc64_uniform(&rng, &dist);
if (r & 1)
++n, cqueue_i_push(&queue, r);
diff --git a/examples/random.c b/examples/random.c
index 30751a6c..99001a1a 100644
--- a/examples/random.c
+++ b/examples/random.c
@@ -14,7 +14,7 @@ int main()
printf("Compare speed of full and unbiased ranged random numbers...\n");
sum = 0;
before = clock();
- c_forrange (N) {
+ c_forloop (N) {
sum += (uint32_t) stc64_rand(&rng);
}
diff = clock() - before;
@@ -24,7 +24,7 @@ int main()
rng = stc64_new(seed);
sum = 0;
before = clock();
- c_forrange (N) {
+ c_forloop (N) {
sum += stc64_uniform(&rng, &dist1); // unbiased
}
diff = clock() - before;
@@ -33,7 +33,7 @@ int main()
sum = 0;
rng = stc64_new(seed);
before = clock();
- c_forrange (N) {
+ c_forloop (N) {
sum += stc64_rand(&rng) % (range + 1); // biased
}
diff = clock() - before;
diff --git a/examples/regex2.c b/examples/regex2.c
index 28291915..d3a22f5a 100644
--- a/examples/regex2.c
+++ b/examples/regex2.c
@@ -15,7 +15,7 @@ int main()
};
c_with (cregex re = cregex_init(), cregex_drop(&re))
- c_forrange (i, c_arraylen(s))
+ c_forloop (i, c_arraylen(s))
{
int res = cregex_compile(&re, s[i].pattern, 0);
if (res < 0) {
@@ -25,8 +25,8 @@ int main()
printf("input: %s\n", s[i].input);
c_formatch (j, &re, s[i].input) {
- c_forrange (k, cregex_captures(&re))
- printf(" submatch %d: %.*s\n", (int)k, c_ARGsv(j.match[k]));
+ c_forloop (k, cregex_captures(&re))
+ printf(" submatch %lld: %.*s\n", k, c_ARGsv(j.match[k]));
puts("");
}
}
diff --git a/examples/stack.c b/examples/stack.c
index 580b6428..fad2093b 100644
--- a/examples/stack.c
+++ b/examples/stack.c
@@ -14,12 +14,12 @@ int main() {
c_auto (cstack_i, stack)
c_auto (cstack_c, chars)
{
- c_forrange (i, int, 101)
+ c_forloop (i, 101)
cstack_i_push(&stack, i*i);
printf("%d\n", *cstack_i_top(&stack));
- c_forrange (i, int, 90)
+ c_forloop (i, 90)
cstack_i_pop(&stack);
c_foreach (i, cstack_i, stack)