summaryrefslogtreecommitdiffhomepage
path: root/misc/examples/algorithms
diff options
context:
space:
mode:
authortylov <[email protected]>2023-07-21 00:37:28 +0200
committertylov <[email protected]>2023-07-21 00:37:28 +0200
commit2d67f4040f6eecd41f1b864b43c62823ed75aff0 (patch)
tree084ce603dc4edfa1ccad3aabab5b671a817bc67e /misc/examples/algorithms
parent900295256d825fc323149cd223c49787f32a3696 (diff)
downloadSTC-modified-2d67f4040f6eecd41f1b864b43c62823ed75aff0.tar.gz
STC-modified-2d67f4040f6eecd41f1b864b43c62823ed75aff0.zip
Renamed badly abbreviated names in crand.h.
Moved coroutine.h from algo subfolder to stc. Updated coroutine.h and docs.
Diffstat (limited to 'misc/examples/algorithms')
-rw-r--r--misc/examples/algorithms/forfilter.c3
-rw-r--r--misc/examples/algorithms/forloops.c2
-rw-r--r--misc/examples/algorithms/random.c20
3 files changed, 12 insertions, 13 deletions
diff --git a/misc/examples/algorithms/forfilter.c b/misc/examples/algorithms/forfilter.c
index f3c008b3..644b8459 100644
--- a/misc/examples/algorithms/forfilter.c
+++ b/misc/examples/algorithms/forfilter.c
@@ -3,8 +3,7 @@
#include <stc/cstr.h>
#define i_implement
#include <stc/csview.h>
-#include <stc/algo/filter.h>
-#include <stc/algo/crange.h>
+#include <stc/algorithm.h>
#define i_type IVec
#define i_key int
diff --git a/misc/examples/algorithms/forloops.c b/misc/examples/algorithms/forloops.c
index 72d745f8..300eee18 100644
--- a/misc/examples/algorithms/forloops.c
+++ b/misc/examples/algorithms/forloops.c
@@ -1,5 +1,5 @@
#include <stdio.h>
-#include <stc/algo/filter.h>
+#include <stc/algorithm.h>
#define i_type IVec
#define i_key int
diff --git a/misc/examples/algorithms/random.c b/misc/examples/algorithms/random.c
index b7c0f277..ccd0711d 100644
--- a/misc/examples/algorithms/random.c
+++ b/misc/examples/algorithms/random.c
@@ -4,11 +4,11 @@
int main(void)
{
- const int N = 1000000000;
+ long long N = 1000000000;
const uint64_t seed = (uint64_t)time(NULL), range = 1000000;
crand_t rng = crand_init(seed);
- int64_t sum;
+ long long sum;
clock_t diff, before;
printf("Compare speed of full and unbiased ranged random numbers...\n");
@@ -18,19 +18,19 @@ int main(void)
sum += (uint32_t)crand_u64(&rng);
}
diff = clock() - before;
- printf("full range\t\t: %f secs, %d, avg: %f\n",
- (double)diff/CLOCKS_PER_SEC, N, (double)sum/N);
+ printf("full range\t\t: %f secs, %lld, avg: %f\n",
+ (double)diff/CLOCKS_PER_SEC, N, (double)(sum/N));
- crand_unif_t dist1 = crand_unif_init(0, range);
+ crand_uniform_t dist1 = crand_uniform_init(0, range);
rng = crand_init(seed);
sum = 0;
before = clock();
c_forrange (N) {
- sum += crand_unif(&rng, &dist1); // unbiased
+ sum += crand_uniform(&rng, &dist1); // unbiased
}
diff = clock() - before;
- printf("unbiased 0-%" PRIu64 "\t: %f secs, %d, avg: %f\n",
- range, (double)diff/CLOCKS_PER_SEC, N, (double)sum/N);
+ printf("unbiased 0-%" PRIu64 "\t: %f secs, %lld, avg: %f\n",
+ range, (double)diff/CLOCKS_PER_SEC, N, (double)(sum/N));
sum = 0;
rng = crand_init(seed);
@@ -39,7 +39,7 @@ int main(void)
sum += (int64_t)(crand_u64(&rng) % (range + 1)); // biased
}
diff = clock() - before;
- printf("biased 0-%" PRIu64 " \t: %f secs, %d, avg: %f\n",
- range, (double)diff/CLOCKS_PER_SEC, N, (double)sum/N);
+ printf("biased 0-%" PRIu64 " \t: %f secs, %lld, avg: %f\n",
+ range, (double)diff/CLOCKS_PER_SEC, N, (double)(sum/N));
}