diff options
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/heap.c | 22 | ||||
| -rw-r--r-- | examples/inits.c | 16 | ||||
| -rw-r--r-- | examples/priority.c | 18 |
3 files changed, 28 insertions, 28 deletions
diff --git a/examples/heap.c b/examples/heap.c index b45e5ada..c7292d2e 100644 --- a/examples/heap.c +++ b/examples/heap.c @@ -2,10 +2,10 @@ #include <time.h>
#include <stc/crand.h>
#include <stc/cvec.h>
-#include <stc/cpqueue.h>
+#include <stc/cpque.h>
using_cvec(f, float);
-using_cpqueue(f, cvec_f, >);
+using_cpque(f, cvec_f, >);
int main()
{
@@ -13,36 +13,36 @@ int main() crand_t rng;
int N = 3000000, M = 100;
- cpqueue_f pq = cpqueue_f_init();
+ cpque_f pq = cpque_f_init();
rng = crand_init(seed);
clock_t start = clock();
c_forrange (i, int, N)
cvec_f_push_back(&pq, (float) crand_nextf(&rng)*100000);
- cpqueue_f_make_heap(&pq);
+ cpque_f_make_heap(&pq);
printf("Built priority queue: %f secs\n", (clock() - start) / (float) CLOCKS_PER_SEC);
c_forrange (i, int, M) {
- printf("%g ", *cpqueue_f_top(&pq));
- cpqueue_f_pop(&pq);
+ printf("%g ", *cpque_f_top(&pq));
+ cpque_f_pop(&pq);
}
start = clock();
c_forrange (i, int, M, N)
- cpqueue_f_pop(&pq);
+ cpque_f_pop(&pq);
printf("\n\npopped PQ: %f secs\n", (clock() - start) / (float) CLOCKS_PER_SEC);
start = clock();
c_forrange (i, int, N)
- cpqueue_f_push(&pq, (float) crand_nextf(&rng)*100000);
+ cpque_f_push(&pq, (float) crand_nextf(&rng)*100000);
printf("pushed PQ: %f secs\n", (clock() - start) / (float) CLOCKS_PER_SEC);
c_forrange (i, int, M) {
- printf("%g ", *cpqueue_f_top(&pq));
- cpqueue_f_pop(&pq);
+ printf("%g ", *cpque_f_top(&pq));
+ cpque_f_pop(&pq);
}
puts("");
- cpqueue_f_del(&pq);
+ cpque_f_del(&pq);
}
diff --git a/examples/inits.c b/examples/inits.c index 4ce1421a..28b54835 100644 --- a/examples/inits.c +++ b/examples/inits.c @@ -2,7 +2,7 @@ #include <stc/cstr.h>
#include <stc/cmap.h>
#include <stc/cvec.h>
-#include <stc/cpqueue.h>
+#include <stc/cpque.h>
#include <stc/clist.h>
using_cmap(id, int, cstr_t, cstr_del); // Map of int -> cstr_t
@@ -17,7 +17,7 @@ inline static int ipair_compare(const ipair_t* a, const ipair_t* b) { using_cvec(ip, ipair_t, c_default_del, ipair_compare);
using_clist(ip, ipair_t, c_default_del, ipair_compare);
using_cvec(f, float);
-using_cpqueue(f, cvec_f, >);
+using_cpque(f, cvec_f, >);
int main(void)
{
@@ -31,16 +31,16 @@ int main(void) // CVEC PRIORITY QUEUE
- cpqueue_f_make_heap(&floats);
- c_push_items(&floats, cpqueue_f, {40.0f, 20.0f, 50.0f, 30.0f, 10.0f});
+ cpque_f_make_heap(&floats);
+ c_push_items(&floats, cpque_f, {40.0f, 20.0f, 50.0f, 30.0f, 10.0f});
// sorted:
- while (! cpqueue_f_empty(floats)) {
- printf("%.1f ", *cpqueue_f_top(&floats));
- cpqueue_f_pop(&floats);
+ while (! cpque_f_empty(floats)) {
+ printf("%.1f ", *cpque_f_top(&floats));
+ cpque_f_pop(&floats);
}
puts("\n");
- cpqueue_f_del(&floats);
+ cpque_f_del(&floats);
// CMAP ID
diff --git a/examples/priority.c b/examples/priority.c index 40fb395e..4eb762ec 100644 --- a/examples/priority.c +++ b/examples/priority.c @@ -2,34 +2,34 @@ #include <stdio.h>
#include <time.h>
#include <stc/cvec.h>
-#include <stc/cpqueue.h>
+#include <stc/cpque.h>
#include <stc/cmap.h>
#include <stc/crand.h>
using_cvec(i, int64_t);
-using_cpqueue(i, cvec_i, >); // min-heap (increasing values)
+using_cpque(i, cvec_i, >); // min-heap (increasing values)
int main() {
size_t N = 10000000;
crand_t rng = crand_init(time(NULL));
crand_uniform_t dist = crand_uniform_init(0, N * 10);
- cpqueue_i heap = cpqueue_i_init();
+ cpque_i heap = cpque_i_init();
// Push ten million random numbers to priority queue
c_forrange (N)
- cpqueue_i_push(&heap, crand_uniform(&rng, &dist));
+ cpque_i_push(&heap, crand_uniform(&rng, &dist));
// push some negative numbers too.
- c_push_items(&heap, cpqueue_i, {-231, -32, -873, -4, -343});
+ c_push_items(&heap, cpque_i, {-231, -32, -873, -4, -343});
c_forrange (N)
- cpqueue_i_push(&heap, crand_uniform(&rng, &dist));
+ cpque_i_push(&heap, crand_uniform(&rng, &dist));
// Extract the hundred smallest.
c_forrange (100) {
- printf("%zd ", *cpqueue_i_top(&heap));
- cpqueue_i_pop(&heap);
+ printf("%zd ", *cpque_i_top(&heap));
+ cpque_i_pop(&heap);
}
- cpqueue_i_del(&heap);
+ cpque_i_del(&heap);
}
|
