summaryrefslogtreecommitdiffhomepage
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/bits.c44
-rw-r--r--examples/bits2.c24
-rw-r--r--examples/prime.c6
3 files changed, 37 insertions, 37 deletions
diff --git a/examples/bits.c b/examples/bits.c
index bd2a9f03..8888f73e 100644
--- a/examples/bits.c
+++ b/examples/bits.c
@@ -4,21 +4,21 @@
int main()
{
c_autovar (cbits set = cbits_with_size(23, true), cbits_drop(&set)) {
- printf("count %" PRIuMAX ", %" PRIuMAX "\n", cbits_count(set), cbits_size(set));
+ printf("count %" PRIuMAX ", %" PRIuMAX "\n", cbits_count(&set), cbits_size(&set));
cbits s1 = cbits_from("1110100110111");
char buf[256];
- cbits_to_str(s1, buf, 0, -1);
- printf("buf: %s: %" PRIuMAX "\n", buf, cbits_count(s1));
+ cbits_to_str(&s1, buf, 0, -1);
+ printf("buf: %s: %" PRIuMAX "\n", buf, cbits_count(&s1));
cbits_drop(&s1);
cbits_reset(&set, 9);
cbits_resize(&set, 43, false);
- c_autobuf (str, char, cbits_size(set) + 1)
- printf(" str: %s\n", cbits_to_str(set, str, 0, -1));
+ c_autobuf (str, char, cbits_size(&set) + 1)
+ printf(" str: %s\n", cbits_to_str(&set, str, 0, -1));
- printf("%4" PRIuMAX ": ", cbits_size(set));
- c_forrange (i, cbits_size(set))
- printf("%d", cbits_test(set, i));
+ printf("%4" PRIuMAX ": ", cbits_size(&set));
+ c_forrange (i, cbits_size(&set))
+ printf("%d", cbits_test(&set, i));
puts("");
cbits_set(&set, 28);
@@ -26,14 +26,14 @@ int main()
cbits_resize(&set, 93, false);
cbits_resize(&set, 102, true);
cbits_set_value(&set, 99, false);
- printf("%4" PRIuMAX ": ", cbits_size(set));
- c_forrange (i, cbits_size(set))
- printf("%d", cbits_test(set, i));
+ printf("%4" PRIuMAX ": ", cbits_size(&set));
+ c_forrange (i, cbits_size(&set))
+ printf("%d", cbits_test(&set, i));
puts("\nIterate:");
- printf("%4" PRIuMAX ": ", cbits_size(set));
- c_forrange (i, cbits_size(set))
- printf("%d", cbits_test(set, i));
+ printf("%4" PRIuMAX ": ", cbits_size(&set));
+ c_forrange (i, cbits_size(&set))
+ printf("%d", cbits_test(&set, i));
puts("");
c_autovar (cbits s2 = cbits_clone(set), cbits_drop(&s2)) {
@@ -42,20 +42,20 @@ int main()
cbits_set(&s2, 17);
cbits_set(&s2, 18);
printf(" new: ");
- c_forrange (i, cbits_size(s2))
- printf("%d", cbits_test(s2, i));
+ c_forrange (i, cbits_size(&s2))
+ printf("%d", cbits_test(&s2, i));
puts("");
printf(" xor: ");
- cbits_xor(&set, s2);
- c_forrange (i, cbits_size(set))
- printf("%d", cbits_test(set, i));
+ cbits_xor(&set, &s2);
+ c_forrange (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))
- printf("%d", cbits_test(set, i));
+ printf("%4" PRIuMAX ": ", cbits_size(&set));
+ c_forrange (i, cbits_size(&set))
+ printf("%d", cbits_test(&set, i));
puts("");
}
}
diff --git a/examples/bits2.c b/examples/bits2.c
index e9202efc..81e28d60 100644
--- a/examples/bits2.c
+++ b/examples/bits2.c
@@ -9,14 +9,14 @@ int main()
{
Bits s1 = Bits_from("1110100110111");
- printf("size %" PRIuMAX "\n", Bits_size(s1));
+ printf("size %" PRIuMAX "\n", Bits_size(&s1));
char buf[256];
- Bits_to_str(s1, buf, 0, -1);
- printf("buf: %s: count=%" PRIuMAX "\n", buf, Bits_count(s1));
+ Bits_to_str(&s1, buf, 0, -1);
+ printf("buf: %s: count=%" PRIuMAX "\n", buf, Bits_count(&s1));
Bits_reset(&s1, 8);
- c_autobuf (str, char, Bits_size(s1) + 1)
- printf(" s1: %s\n", Bits_to_str(s1, str, 0, -1));
+ c_autobuf (str, char, Bits_size(&s1) + 1)
+ printf(" s1: %s\n", Bits_to_str(&s1, str, 0, -1));
Bits s2 = Bits_clone(s1);
@@ -24,19 +24,19 @@ int main()
Bits_reset(&s2, 66);
Bits_reset(&s2, 67);
printf(" s2: ");
- c_forrange (i, Bits_size(s2))
- printf("%d", Bits_test(s2, i));
+ c_forrange (i, Bits_size(&s2))
+ printf("%d", Bits_test(&s2, i));
puts("");
printf("xor: ");
- Bits_xor(&s1, s2);
- c_forrange (i, Bits_size(s1))
- printf("%d", Bits_test(s1, i));
+ Bits_xor(&s1, &s2);
+ c_forrange (i, Bits_size(&s1))
+ printf("%d", Bits_test(&s1, i));
puts("");
printf("all: ");
Bits_set_pattern(&s1, 0x3333333333333333);
- c_forrange (i, Bits_size(s1))
- printf("%d", Bits_test(s1, i));
+ c_forrange (i, Bits_size(&s1))
+ printf("%d", Bits_test(&s1, i));
puts("");
}
diff --git a/examples/prime.c b/examples/prime.c
index aee0a89e..cc16603b 100644
--- a/examples/prime.c
+++ b/examples/prime.c
@@ -11,7 +11,7 @@ cbits sieveOfEratosthenes(size_t n)
for (size_t i = 3; i < q; i += 2) {
size_t j = i;
for (; j < n; j += 2) {
- if (cbits_test(bits, j>>1)) {
+ if (cbits_test(&bits, j>>1)) {
i = j;
break;
}
@@ -30,13 +30,13 @@ int main(void)
clock_t t1 = clock();
c_autovar (cbits primes = sieveOfEratosthenes(n + 1), cbits_drop(&primes)) {
puts("done");
- size_t np = cbits_count(primes);
+ size_t np = cbits_count(&primes);
clock_t t2 = clock();
printf("number of primes: %" PRIuMAX ", time: %f\n", np, (t2 - t1) / (float)CLOCKS_PER_SEC);
printf("2");
for (size_t i = 3; i < 1000; i += 2)
- if (cbits_test(primes, i>>1)) printf(" %" PRIuMAX "", i);
+ if (cbits_test(&primes, i>>1)) printf(" %" PRIuMAX "", i);
puts("");
}
}