summaryrefslogtreecommitdiffhomepage
path: root/misc/examples/queue.c
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2023-04-08 22:37:06 +0200
committerGitHub <[email protected]>2023-04-08 22:37:06 +0200
commit43120f2863a67db416ec3b379eb820e2704cafb7 (patch)
treef3b9917940f94c1582bc39ea6f56b735295ec861 /misc/examples/queue.c
parente8be14dfc894eeac859f0287d4d5b4f4745c0585 (diff)
parent6426ac05eb8c4dc1ab22aae2eb4139f9671981b7 (diff)
downloadSTC-modified-43120f2863a67db416ec3b379eb820e2704cafb7.tar.gz
STC-modified-43120f2863a67db416ec3b379eb820e2704cafb7.zip
Merge pull request #53 from tylov/dev42
Version 4.2 RC
Diffstat (limited to 'misc/examples/queue.c')
-rw-r--r--misc/examples/queue.c39
1 files changed, 20 insertions, 19 deletions
diff --git a/misc/examples/queue.c b/misc/examples/queue.c
index 4064cc77..83c18d09 100644
--- a/misc/examples/queue.c
+++ b/misc/examples/queue.c
@@ -1,4 +1,4 @@
-#include <stc/crandom.h>
+#include <stc/crand.h>
#include <stdio.h>
#define i_val int
@@ -7,25 +7,26 @@
int main() {
int n = 100000000;
- stc64_uniform_t dist;
- stc64_t rng = stc64_new(1234);
- dist = stc64_uniform_new(0, n);
+ crand_unif_t dist;
+ crand_t rng = crand_init(1234);
+ dist = crand_unif_init(0, n);
- c_auto (cqueue_i, queue)
- {
- // Push ten million random numbers onto the queue.
- c_forrange (n)
- cqueue_i_push(&queue, (int)stc64_uniform(&rng, &dist));
+ cqueue_i queue = {0};
- // Push or pop on the queue ten million times
- printf("%d\n", n);
- c_forrange (n) { // forrange uses initial n only.
- int r = (int)stc64_uniform(&rng, &dist);
- if (r & 1)
- ++n, cqueue_i_push(&queue, r);
- else
- --n, cqueue_i_pop(&queue);
- }
- printf("%d, %" c_ZI "\n", n, cqueue_i_size(&queue));
+ // Push ten million random numbers onto the queue.
+ c_forrange (n)
+ cqueue_i_push(&queue, (int)crand_unif(&rng, &dist));
+
+ // Push or pop on the queue ten million times
+ printf("%d\n", n);
+ c_forrange (n) { // forrange uses initial n only.
+ int r = (int)crand_unif(&rng, &dist);
+ if (r & 1)
+ ++n, cqueue_i_push(&queue, r);
+ else
+ --n, cqueue_i_pop(&queue);
}
+ printf("%d, %" c_ZI "\n", n, cqueue_i_size(&queue));
+
+ cqueue_i_drop(&queue);
}