diff options
| author | Tyge Løvset <[email protected]> | 2021-05-18 22:08:47 +0200 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2021-05-18 22:08:47 +0200 |
| commit | 4578ae03cea28def01dc9f5fe882234857b1238e (patch) | |
| tree | d57cd864da28f9d13c446e0730e2582c35556f0a /examples/queue.c | |
| parent | a8d94f4acea04681c89b46233f90bd8f4cee6ebf (diff) | |
| download | STC-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.c | 30 |
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);
}
|
