diff options
| author | Tyge Løvset <[email protected]> | 2020-07-21 16:52:18 +0200 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2020-07-21 16:52:18 +0200 |
| commit | 5fc073318a697b1b67b0102ab2df12395f1f9f05 (patch) | |
| tree | 3156019fa25529f688fafab4479be1141ff68aa0 /examples/list.c | |
| parent | 289df4cb64a365ad0a0e55864efc79aa32c36b94 (diff) | |
| download | STC-modified-5fc073318a697b1b67b0102ab2df12395f1f9f05.tar.gz STC-modified-5fc073318a697b1b67b0102ab2df12395f1f9f05.zip | |
Cleaned up MAP API. Added 2 examles.
Diffstat (limited to 'examples/list.c')
| -rw-r--r-- | examples/list.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/examples/list.c b/examples/list.c new file mode 100644 index 00000000..4fa76f81 --- /dev/null +++ b/examples/list.c @@ -0,0 +1,23 @@ +#include <stdio.h>
+#include <time.h>
+#include <stc/clist.h>
+#include <stc/crandom.h>
+declare_CList(ix, uint64_t);
+
+int main() {
+ CList_ix list = clist_init;
+ pcg32_random_t pcg = pcg32_seed(time(NULL), 0);
+ int n;
+ for (int i=0; i<10000000; ++i) // ten million
+ clist_ix_pushBack(&list, pcg32_random(&pcg));
+ n = 100;
+ c_foreach (i, clist_ix, list)
+ if (n--) printf("%8d: %10zu\n", 100 - n, i.item->value); else break;
+ // Sort them...
+ clist_ix_sort(&list); // mergesort O(n*log n)
+ n = 100;
+ puts("sorted");
+ c_foreach (i, clist_ix, list)
+ if (n--) printf("%8d: %10zu\n", 100 - n, i.item->value); else break;
+ clist_ix_destroy(&list);
+}
\ No newline at end of file |
