diff options
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/bits.c | 26 | ||||
| -rw-r--r-- | examples/list.c | 23 |
2 files changed, 49 insertions, 0 deletions
diff --git a/examples/bits.c b/examples/bits.c new file mode 100644 index 00000000..9767f8a3 --- /dev/null +++ b/examples/bits.c @@ -0,0 +1,26 @@ +#include <stdio.h>
+#include "cbitvec.h"
+
+int main() {
+ CBitVec vec = cbitvec_make(23, true);
+ cbitvec_unset(&vec, 9);
+ cbitvec_resize(&vec, 43, false);
+ printf("%4zu: ", vec.size);
+ for (int i=0; i<vec.size; ++i)
+ printf("%d", cbitvec_value(&vec, i));puts("");
+
+ cbitvec_set(&vec, 28);
+ cbitvec_resize(&vec, 77, true);
+ cbitvec_resize(&vec, 93, false);
+ cbitvec_resize(&vec, 102, true);
+ cbitvec_setValue(&vec, 99, false);
+ printf("%4zu: ", vec.size);
+ for (int i=0; i<vec.size; ++i)
+ printf("%d", cbitvec_value(&vec, i));puts("");
+
+ cbitvec_setAll(&vec, false);
+ printf("%4zu: ", vec.size);
+ for (int i=0; i<vec.size; ++i)
+ printf("%d", cbitvec_value(&vec, i));puts("");
+ cbitvec_destroy(&vec);
+}
\ No newline at end of file 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 |
