diff options
| author | Tyge Løvset <[email protected]> | 2021-10-18 15:58:18 +0200 |
|---|---|---|
| committer | GitHub <[email protected]> | 2021-10-18 15:58:18 +0200 |
| commit | 2de66b77d17fd091562560ce5f14161a3f5076b4 (patch) | |
| tree | f174120fff6543fce8227ed18bfc772788947c19 /include | |
| parent | c0d9bf77061f7cff3c7902bdd8e0a131a9b1034f (diff) | |
| download | STC-modified-2de66b77d17fd091562560ce5f14161a3f5076b4.tar.gz STC-modified-2de66b77d17fd091562560ce5f14161a3f5076b4.zip | |
Fixed clist.h example in header
Diffstat (limited to 'include')
| -rw-r--r-- | include/stc/clist.h | 24 |
1 files 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 <stdio.h>
#include <stc/crandom.h>
- #define i_tag ix
#define i_val int64_t
+ #define i_tag ix
#include <stc/clist.h>
- 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
|
