diff options
| author | Tyge Løvset <[email protected]> | 2020-09-20 13:37:27 +0200 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2020-09-20 13:37:27 +0200 |
| commit | 84c1716de710d2d9067c9f8a50487e3ab2d6fa42 (patch) | |
| tree | ae5be1a90482b4940a6555ed1ff44c2e518dbe0d /examples | |
| parent | 927a1b015b7b934220edf9b5c758eed540f3e510 (diff) | |
| download | STC-modified-84c1716de710d2d9067c9f8a50487e3ab2d6fa42.tar.gz STC-modified-84c1716de710d2d9067c9f8a50487e3ab2d6fa42.zip | |
Possible to redefine STC memory allocator globally.
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/inits.c | 15 | ||||
| -rw-r--r-- | examples/queue.c | 4 |
2 files changed, 9 insertions, 10 deletions
diff --git a/examples/inits.c b/examples/inits.c index 14fe8a64..27ee3c9b 100644 --- a/examples/inits.c +++ b/examples/inits.c @@ -10,18 +10,17 @@ using_cmap_strkey(cnt, int); typedef struct {int x, y;} ipair_t;
inline static int ipair_compare(const ipair_t* a, const ipair_t* b) {
- int c = c_default_compare(&a->x, &b->x);
- return c != 0 ? c : c_default_compare(&a->y, &b->y);
+ int cx = c_default_compare(&a->x, &b->x);
+ return cx == 0 ? c_default_compare(&a->y, &b->y) : cx;
}
+
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, >);
-
-int main(void) {
-
+int main(void)
+{
// CVEC FLOAT / PRIORITY QUEUE
cvec_f floats = cvec_INIT;
@@ -32,11 +31,11 @@ int main(void) { // CVEC PRIORITY QUEUE
- cpqueue_f_build(&floats); // reorganise vec
+ cpqueue_f_build(&floats); // make heap
c_push_items(&floats, cpqueue_f, {40.0f, 20.0f, 50.0f, 30.0f, 10.0f});
// sorted:
- while (cvec_size(floats) > 0) {
+ while (! cpqueue_f_empty(floats)) {
printf("%.1f ", *cpqueue_f_top(&floats));
cpqueue_f_pop(&floats);
}
diff --git a/examples/queue.c b/examples/queue.c index e4426884..c56214a7 100644 --- a/examples/queue.c +++ b/examples/queue.c @@ -14,12 +14,12 @@ int main() { cqueue_i queue = cqueue_i_init();
// Push ten million random numbers onto the queue.
- c_forrange (i, int, 0, n)
+ c_forrange (n)
cqueue_i_push(&queue, crand_uniform_i32(&rng, &dist));
// Push or pop on the queue ten million times
printf("%d\n", n);
- c_forrange (i, int, n, 0, -1) {
+ c_forrange (n) { // range uses initial n only.
int r = crand_uniform_i32(&rng, &dist);
if (r & 1)
++n, cqueue_i_push(&queue, r);
|
