summaryrefslogtreecommitdiffhomepage
path: root/examples/queue.c
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2021-05-18 22:08:47 +0200
committerTyge Løvset <[email protected]>2021-05-18 22:08:47 +0200
commit4578ae03cea28def01dc9f5fe882234857b1238e (patch)
treed57cd864da28f9d13c446e0730e2582c35556f0a /examples/queue.c
parenta8d94f4acea04681c89b46233f90bd8f4cee6ebf (diff)
downloadSTC-modified-4578ae03cea28def01dc9f5fe882234857b1238e.tar.gz
STC-modified-4578ae03cea28def01dc9f5fe882234857b1238e.zip
Added the new c_defer(), c_with(), c_withvar() macros into the examples.
Diffstat (limited to 'examples/queue.c')
-rw-r--r--examples/queue.c30
1 files changed, 15 insertions, 15 deletions
diff --git a/examples/queue.c b/examples/queue.c
index 23640a39..e3a74f33 100644
--- a/examples/queue.c
+++ b/examples/queue.c
@@ -17,21 +17,21 @@ int main() {
stc64_t rng = stc64_init(1234);
dist = stc64_uniform_init(0, n);
- cqueue_i queue = cqueue_i_init();
+ c_withvar (cqueue_i, queue)
+ {
+ // Push ten million random numbers onto the queue.
+ c_forrange (n)
+ cqueue_i_push(&queue, stc64_uniform(&rng, &dist));
- // Push ten million random numbers onto the queue.
- c_forrange (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) { // range uses initial n only.
- int r = stc64_uniform(&rng, &dist);
- if (r & 1)
- ++n, cqueue_i_push(&queue, r);
- else
- --n, cqueue_i_pop(&queue);
+ // Push or pop on the queue ten million times
+ printf("%d\n", n);
+ c_forrange (n) { // range uses initial n only.
+ int r = stc64_uniform(&rng, &dist);
+ if (r & 1)
+ ++n, cqueue_i_push(&queue, r);
+ else
+ --n, cqueue_i_pop(&queue);
+ }
+ printf("%d, %zu\n", n, cqueue_i_size(queue));
}
- printf("%d, %zu\n", n, cqueue_i_size(queue));
- cqueue_i_del(&queue);
}