summaryrefslogtreecommitdiffhomepage
path: root/examples/list.c
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2020-07-21 16:52:18 +0200
committerTyge Løvset <[email protected]>2020-07-21 16:52:18 +0200
commit5fc073318a697b1b67b0102ab2df12395f1f9f05 (patch)
tree3156019fa25529f688fafab4479be1141ff68aa0 /examples/list.c
parent289df4cb64a365ad0a0e55864efc79aa32c36b94 (diff)
downloadSTC-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.c23
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