From 2de66b77d17fd091562560ce5f14161a3f5076b4 Mon Sep 17 00:00:00 2001 From: Tyge Løvset <60263450+tylov@users.noreply.github.com> Date: Mon, 18 Oct 2021 15:58:18 +0200 Subject: Fixed clist.h example in header --- include/stc/clist.h | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/include/stc/clist.h b/include/stc/clist.h index 071cd8cb..aa1ef3e8 100644 --- a/include/stc/clist.h +++ b/include/stc/clist.h @@ -22,34 +22,32 @@ */ /* Circular Singly-linked Lists. - - This implements a std::forward_list-like class in C, but because it is circular, - it also support push* and splice* at both ends of the list. This makes it ideal - for being used as a queue, unlike std::forward_list. Basic usage is similar to cvec: + This implements a std::forward_list-like class in C. Because it is circular, + it also support both push_back() and push_front(), unlike std::forward_list: #include #include - #define i_tag ix #define i_val int64_t + #define i_tag ix #include - int main() { - c_autovar (clist_ix list = clist_ix_init(), clist_ix_del(&list)) + int main() + { + c_auto (clist_ix, list) { - stc64_t rng = stc64_init(12345); int n; - for (int i=0; i<1000000; ++i) // one million - clist_ix_push_back(&list, stc64_rand(&rng) >> 32); + for (int i = 0; i < 1000000; ++i) // one million + clist_ix_push_back(&list, stc64_random() >> 32); n = 0; c_foreach (i, clist_ix, list) - if (++n % 10000 == 0) printf("%8d: %10zd\n", n, i.ref->value); + if (++n % 10000 == 0) printf("%8d: %10zu\n", n, *i.ref); // Sort them... clist_ix_sort(&list); // mergesort O(n*log n) n = 0; puts("sorted"); c_foreach (i, clist_ix, list) - if (++n % 10000 == 0) printf("%8d: %10zd\n", n, i.ref->value); + if (++n % 10000 == 0) printf("%8d: %10zu\n", n, *i.ref); } } */ @@ -377,4 +375,4 @@ _clist_mergesort(clist_VOID_node_t *list, int (*cmp)(const clist_VOID_node_t*, c } #endif // NON-TEMPLATE IMPLEMENTATION #include "template.h" -#define CLIST_H_INCLUDED \ No newline at end of file +#define CLIST_H_INCLUDED -- cgit v1.2.3