summaryrefslogtreecommitdiffhomepage
path: root/examples/new_queue.c
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2022-09-26 23:56:09 +0200
committerTyge Løvset <[email protected]>2022-09-26 23:56:09 +0200
commit60c4432678073faa271fe9b6f632c5a3789d5727 (patch)
treeaf8dc7b274bf1d7ad96b7774275092a1ecbe1a03 /examples/new_queue.c
parent2c31b421b6c867ab956a843dace0d95769a97667 (diff)
downloadSTC-modified-60c4432678073faa271fe9b6f632c5a3789d5727.tar.gz
STC-modified-60c4432678073faa271fe9b6f632c5a3789d5727.zip
Deprecated c_pair() macro. Replaced with c_PAIR(), analogous to c_ARGsv() macro which are both unsafe regarding side effects on arg.
Diffstat (limited to 'examples/new_queue.c')
-rw-r--r--examples/new_queue.c23
1 files changed, 12 insertions, 11 deletions
diff --git a/examples/new_queue.c b/examples/new_queue.c
index ea68c9b9..eebf3493 100644
--- a/examples/new_queue.c
+++ b/examples/new_queue.c
@@ -16,29 +16,30 @@ int point_cmp(const Point* a, const Point* b) {
#define i_tag pnt
#include <stc/cqueue.h>
+#define i_type IQ
#define i_val int
#include <stc/cqueue.h>
int main() {
- int n = 60000000;
+ int n = 50000000;
stc64_t rng = stc64_new(time(NULL));
stc64_uniform_t dist = stc64_uniform_new(0, n);
- c_auto (cqueue_int, Q)
+ c_auto (IQ, Q)
{
// Push eight million random numbers onto the queue.
- for (int i=0; i<n; ++i)
- cqueue_int_push(&Q, stc64_uniform(&rng, &dist));
+ c_forloop (n)
+ IQ_push(&Q, stc64_uniform(&rng, &dist));
- // Push or pop on the queue ten million times
- printf("befor: size %" PRIuMAX ", capacity %" PRIuMAX "\n", cqueue_int_size(&Q), cqueue_int_capacity(&Q));
- for (int i=n; i>0; --i) {
+ // Push or pop on the queue 50 million times
+ printf("befor: size %" PRIuMAX ", capacity %" PRIuMAX "\n", IQ_size(&Q), IQ_capacity(&Q));
+ c_forloop (n) {
int r = stc64_uniform(&rng, &dist);
- if (r & 1)
- cqueue_int_push(&Q, r);
+ if (r & 3)
+ IQ_push(&Q, r);
else
- cqueue_int_pop(&Q);
+ IQ_pop(&Q);
}
- printf("after: size %" PRIuMAX ", capacity %" PRIuMAX "\n", cqueue_int_size(&Q), cqueue_int_capacity(&Q));
+ printf("after: size %" PRIuMAX ", capacity %" PRIuMAX "\n", IQ_size(&Q), IQ_capacity(&Q));
}
}