summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--misc/examples/intrusive.c2
-rw-r--r--misc/examples/prime.c25
-rw-r--r--misc/examples/queue.c4
-rw-r--r--misc/examples/random.c2
4 files changed, 19 insertions, 14 deletions
diff --git a/misc/examples/intrusive.c b/misc/examples/intrusive.c
index 4fca654b..80c1f63b 100644
--- a/misc/examples/intrusive.c
+++ b/misc/examples/intrusive.c
@@ -17,7 +17,7 @@ void printList(List list) {
int main(void) {
List list = {0};
c_forlist (i, int, {6, 9, 3, 1, 7, 4, 5, 2, 8})
- List_push_back_node(&list, c_new(List_node, {0, *i.ref}));
+ List_push_back_node(&list, c_new(List_node, {.value=*i.ref}));
printList(list);
diff --git a/misc/examples/prime.c b/misc/examples/prime.c
index cb3b095a..c3db707d 100644
--- a/misc/examples/prime.c
+++ b/misc/examples/prime.c
@@ -5,20 +5,22 @@
#include <stc/algo/filter.h>
#include <stc/algo/crange.h>
+typedef long long llong;
-cbits sieveOfEratosthenes(int64_t n)
+
+cbits sieveOfEratosthenes(llong n)
{
cbits bits = cbits_with_size(n/2 + 1, true);
- int64_t q = (int64_t)sqrt((double) n) + 1;
- for (int64_t i = 3; i < q; i += 2) {
- int64_t j = i;
+ llong q = (llong)sqrt((double) n) + 1;
+ for (llong i = 3; i < q; i += 2) {
+ llong j = i;
for (; j < n; j += 2) {
if (cbits_test(&bits, j>>1)) {
i = j;
break;
}
}
- for (int64_t j = i*i; j < n; j += i*2)
+ for (llong j = i*i; j < n; j += i*2)
cbits_reset(&bits, j>>1);
}
return bits;
@@ -26,13 +28,17 @@ cbits sieveOfEratosthenes(int64_t n)
int main(void)
{
- int n = 1000000000;
- printf("Computing prime numbers up to %d\n", n);
+
+ llong n = 100000000;
+ printf("Computing prime numbers up to %lld\n", n);
clock_t t = clock();
cbits primes = sieveOfEratosthenes(n + 1);
- int np = (int)cbits_count(&primes);
- t = clock() - t;
+
+ llong np = cbits_count(&primes);
+ clock_t t2 = clock();
+
+ printf("Number of primes: %lld, time: %f\n\n", np, (float)(t2 - t1) / (float)CLOCKS_PER_SEC);
puts("Show all the primes in the range [2, 1000):");
printf("2");
@@ -50,7 +56,6 @@ int main(void)
printf("%lld ", *i.ref);
if (c_flt_getcount(i) % 10 == 0) puts("");
}
- printf("Number of primes: %d, time: %.2f\n\n", np, (double)t/CLOCKS_PER_SEC);
cbits_drop(&primes);
}
diff --git a/misc/examples/queue.c b/misc/examples/queue.c
index 56b5beb9..867a6c7b 100644
--- a/misc/examples/queue.c
+++ b/misc/examples/queue.c
@@ -5,8 +5,8 @@
#define i_tag i
#include <stc/cqueue.h>
-int main(void) {
- int n = 100000000;
+int main() {
+ int n = 1000000;
crand_unif_t dist;
crand_t rng = crand_init(1234);
dist = crand_unif_init(0, n);
diff --git a/misc/examples/random.c b/misc/examples/random.c
index b7c0f277..63c5a306 100644
--- a/misc/examples/random.c
+++ b/misc/examples/random.c
@@ -4,7 +4,7 @@
int main(void)
{
- const int N = 1000000000;
+ const size_t N = 10000000;
const uint64_t seed = (uint64_t)time(NULL), range = 1000000;
crand_t rng = crand_init(seed);