diff options
| author | tylov <[email protected]> | 2023-07-20 15:09:10 +0200 |
|---|---|---|
| committer | tylov <[email protected]> | 2023-07-20 15:12:29 +0200 |
| commit | 900295256d825fc323149cd223c49787f32a3696 (patch) | |
| tree | 6c79cf4209e3975bb6865e2940b9cb56ea469c73 | |
| parent | 224a04f7fa7549ed94d2a1415eb25829e39a7cca (diff) | |
| download | STC-modified-900295256d825fc323149cd223c49787f32a3696.tar.gz STC-modified-900295256d825fc323149cd223c49787f32a3696.zip | |
Moved examples to sub-directories. Added cotask1.c cotask2.c examples.
| -rw-r--r-- | misc/examples/algorithms/forfilter.c (renamed from misc/examples/forfilter.c) | 0 | ||||
| -rw-r--r-- | misc/examples/algorithms/forloops.c (renamed from misc/examples/forloops.c) | 138 | ||||
| -rw-r--r-- | misc/examples/algorithms/random.c (renamed from misc/examples/random.c) | 0 | ||||
| -rw-r--r-- | misc/examples/algorithms/shape.c (renamed from misc/examples/shape.c) | 0 | ||||
| -rw-r--r-- | misc/examples/algorithms/shape.cpp (renamed from misc/examples/shape.cpp) | 0 | ||||
| -rw-r--r-- | misc/examples/bitsets/bits.c (renamed from misc/examples/bits.c) | 0 | ||||
| -rw-r--r-- | misc/examples/bitsets/bits2.c (renamed from misc/examples/bits2.c) | 0 | ||||
| -rw-r--r-- | misc/examples/bitsets/prime.c (renamed from misc/examples/prime.c) | 0 | ||||
| -rw-r--r-- | misc/examples/coroutines/cointerleave.c (renamed from misc/examples/cointerleave.c) | 0 | ||||
| -rw-r--r-- | misc/examples/coroutines/coread.c (renamed from misc/examples/coread.c) | 0 | ||||
| -rw-r--r-- | misc/examples/coroutines/coroutines.c (renamed from misc/examples/coroutines.c) | 0 | ||||
| -rw-r--r-- | misc/examples/coroutines/cotasks1.c | 100 | ||||
| -rw-r--r-- | misc/examples/coroutines/cotasks2.c | 103 | ||||
| -rw-r--r-- | misc/examples/coroutines/dining_philosophers.c (renamed from misc/examples/dining_philosophers.c) | 0 | ||||
| -rw-r--r-- | misc/examples/coroutines/generator.c (renamed from misc/examples/generator.c) | 0 | ||||
| -rw-r--r-- | misc/examples/coroutines/scheduler.c (renamed from misc/examples/scheduler.c) | 0 | ||||
| -rw-r--r-- | misc/examples/coroutines/triples.c (renamed from misc/examples/triples.c) | 0 | ||||
| -rw-r--r-- | misc/examples/hashmaps/birthday.c (renamed from misc/examples/birthday.c) | 0 | ||||
| -rw-r--r-- | misc/examples/hashmaps/books.c (renamed from misc/examples/books.c) | 0 | ||||
| -rw-r--r-- | misc/examples/hashmaps/hashmap.c (renamed from misc/examples/hashmap.c) | 0 | ||||
| -rw-r--r-- | misc/examples/hashmaps/new_map.c (renamed from misc/examples/new_map.c) | 0 | ||||
| -rw-r--r-- | misc/examples/hashmaps/phonebook.c (renamed from misc/examples/phonebook.c) | 0 | ||||
| -rw-r--r-- | misc/examples/hashmaps/unordered_set.c (renamed from misc/examples/unordered_set.c) | 0 | ||||
| -rw-r--r-- | misc/examples/hashmaps/vikings.c (renamed from misc/examples/vikings.c) | 0 | ||||
| -rw-r--r-- | misc/examples/linkedlists/intrusive.c (renamed from misc/examples/intrusive.c) | 0 | ||||
| -rw-r--r-- | misc/examples/linkedlists/list.c (renamed from misc/examples/list.c) | 0 | ||||
| -rw-r--r-- | misc/examples/linkedlists/list_erase.c (renamed from misc/examples/list_erase.c) | 0 | ||||
| -rw-r--r-- | misc/examples/linkedlists/list_splice.c (renamed from misc/examples/list_splice.c) | 0 | ||||
| -rw-r--r-- | misc/examples/linkedlists/new_list.c (renamed from misc/examples/new_list.c) | 0 | ||||
| -rwxr-xr-x | misc/examples/make.sh | 18 | ||||
| -rw-r--r-- | misc/examples/mixed/astar.c (renamed from misc/examples/astar.c) | 0 | ||||
| -rw-r--r-- | misc/examples/mixed/complex.c (renamed from misc/examples/complex.c) | 0 | ||||
| -rw-r--r-- | misc/examples/mixed/convert.c (renamed from misc/examples/convert.c) | 0 | ||||
| -rw-r--r-- | misc/examples/mixed/demos.c (renamed from misc/examples/demos.c) | 0 | ||||
| -rw-r--r-- | misc/examples/mixed/inits.c (renamed from misc/examples/inits.c) | 0 | ||||
| -rw-r--r-- | misc/examples/mixed/read.c (renamed from misc/examples/read.c) | 4 | ||||
| -rw-r--r-- | misc/examples/priorityqueues/functor.c (renamed from misc/examples/functor.c) | 0 | ||||
| -rw-r--r-- | misc/examples/priorityqueues/new_pque.c (renamed from misc/examples/new_pque.c) | 0 | ||||
| -rw-r--r-- | misc/examples/priorityqueues/priority.c (renamed from misc/examples/priority.c) | 0 | ||||
| -rw-r--r-- | misc/examples/queues/new_queue.c (renamed from misc/examples/new_queue.c) | 0 | ||||
| -rw-r--r-- | misc/examples/queues/queue.c (renamed from misc/examples/queue.c) | 0 | ||||
| -rw-r--r-- | misc/examples/regularexpressions/regex1.c (renamed from misc/examples/regex1.c) | 0 | ||||
| -rw-r--r-- | misc/examples/regularexpressions/regex2.c (renamed from misc/examples/regex2.c) | 0 | ||||
| -rw-r--r-- | misc/examples/regularexpressions/regex_match.c (renamed from misc/examples/regex_match.c) | 0 | ||||
| -rw-r--r-- | misc/examples/regularexpressions/regex_replace.c (renamed from misc/examples/regex_replace.c) | 0 | ||||
| -rw-r--r-- | misc/examples/sidebyside.cpp | 57 | ||||
| -rw-r--r-- | misc/examples/smartpointers/arc_containers.c (renamed from misc/examples/arc_containers.c) | 0 | ||||
| -rw-r--r-- | misc/examples/smartpointers/arc_demo.c (renamed from misc/examples/arc_demo.c) | 0 | ||||
| -rw-r--r-- | misc/examples/smartpointers/arcvec_erase.c (renamed from misc/examples/arcvec_erase.c) | 0 | ||||
| -rw-r--r-- | misc/examples/smartpointers/box.c (renamed from misc/examples/box.c) | 0 | ||||
| -rw-r--r-- | misc/examples/smartpointers/box2.c (renamed from misc/examples/box2.c) | 0 | ||||
| -rw-r--r-- | misc/examples/smartpointers/music_arc.c (renamed from misc/examples/music_arc.c) | 0 | ||||
| -rw-r--r-- | misc/examples/smartpointers/new_sptr.c (renamed from misc/examples/new_sptr.c) | 0 | ||||
| -rw-r--r-- | misc/examples/smartpointers/person_arc.c (renamed from misc/examples/person_arc.c) | 0 | ||||
| -rw-r--r-- | misc/examples/smartpointers/rawptr_elements.c (renamed from misc/examples/rawptr_elements.c) | 0 | ||||
| -rw-r--r-- | misc/examples/sortedmaps/csmap_erase.c (renamed from misc/examples/csmap_erase.c) | 0 | ||||
| -rw-r--r-- | misc/examples/sortedmaps/csmap_find.c (renamed from misc/examples/csmap_find.c) | 0 | ||||
| -rw-r--r-- | misc/examples/sortedmaps/csmap_insert.c (renamed from misc/examples/csmap_insert.c) | 0 | ||||
| -rw-r--r-- | misc/examples/sortedmaps/csset_erase.c (renamed from misc/examples/csset_erase.c) | 0 | ||||
| -rw-r--r-- | misc/examples/sortedmaps/gauss2.c (renamed from misc/examples/gauss2.c) | 0 | ||||
| -rw-r--r-- | misc/examples/sortedmaps/listmap.c (renamed from misc/examples/mmap.c) | 0 | ||||
| -rw-r--r-- | misc/examples/sortedmaps/mapmap.c (renamed from misc/examples/mapmap.c) | 0 | ||||
| -rw-r--r-- | misc/examples/sortedmaps/multimap.c (renamed from misc/examples/multimap.c) | 0 | ||||
| -rw-r--r-- | misc/examples/sortedmaps/new_smap.c (renamed from misc/examples/new_smap.c) | 0 | ||||
| -rw-r--r-- | misc/examples/sortedmaps/sorted_map.c (renamed from misc/examples/sorted_map.c) | 0 | ||||
| -rw-r--r-- | misc/examples/spans/multidim.c (renamed from misc/examples/multidim.c) | 0 | ||||
| -rw-r--r-- | misc/examples/spans/printspan.c (renamed from misc/examples/printspan.c) | 0 | ||||
| -rw-r--r-- | misc/examples/strings/cstr_match.c (renamed from misc/examples/cstr_match.c) | 0 | ||||
| -rw-r--r-- | misc/examples/strings/replace.c (renamed from misc/examples/replace.c) | 0 | ||||
| -rw-r--r-- | misc/examples/strings/splitstr.c (renamed from misc/examples/splitstr.c) | 0 | ||||
| -rw-r--r-- | misc/examples/strings/sso_map.c (renamed from misc/examples/sso_map.c) | 0 | ||||
| -rw-r--r-- | misc/examples/strings/sso_substr.c (renamed from misc/examples/sso_substr.c) | 0 | ||||
| -rw-r--r-- | misc/examples/strings/sview_split.c (renamed from misc/examples/sview_split.c) | 0 | ||||
| -rw-r--r-- | misc/examples/strings/utf8replace_c.c (renamed from misc/examples/utf8replace_c.c) | 0 | ||||
| -rw-r--r-- | misc/examples/strings/utf8replace_rs.rs (renamed from misc/examples/utf8replace_rs.rs) | 0 | ||||
| -rw-r--r-- | misc/examples/vectors/lower_bound.c (renamed from misc/examples/lower_bound.c) | 0 | ||||
| -rw-r--r-- | misc/examples/vectors/new_vec.c (renamed from misc/examples/new_vec.c) | 0 | ||||
| -rw-r--r-- | misc/examples/vectors/stack.c (renamed from misc/examples/stack.c) | 0 |
78 files changed, 284 insertions, 136 deletions
diff --git a/misc/examples/forfilter.c b/misc/examples/algorithms/forfilter.c index f3c008b3..f3c008b3 100644 --- a/misc/examples/forfilter.c +++ b/misc/examples/algorithms/forfilter.c diff --git a/misc/examples/forloops.c b/misc/examples/algorithms/forloops.c index 47cced8f..72d745f8 100644 --- a/misc/examples/forloops.c +++ b/misc/examples/algorithms/forloops.c @@ -1,69 +1,69 @@ -#include <stdio.h>
-#include <stc/algo/filter.h>
-
-#define i_type IVec
-#define i_key int
-#include <stc/cstack.h>
-
-#define i_type IMap
-#define i_key int
-#define i_val int
-#include <stc/cmap.h>
-
-
-int main(void)
-{
- puts("c_forrange:");
- c_forrange (30) printf(" xx");
- puts("");
-
- c_forrange (i, 30) printf(" %lld", i);
- puts("");
-
- c_forrange (i, 30, 60) printf(" %lld", i);
- puts("");
-
- c_forrange (i, 30, 90, 2) printf(" %lld", i);
-
- puts("\n\nc_forlist:");
- c_forlist (i, int, {12, 23, 453, 65, 676})
- printf(" %d", *i.ref);
- puts("");
-
- c_forlist (i, const char*, {"12", "23", "453", "65", "676"})
- printf(" %s", *i.ref);
- puts("");
-
- IVec vec = c_init(IVec, {12, 23, 453, 65, 113, 215, 676, 34, 67, 20, 27, 66, 189, 45, 280, 199});
- IMap map = c_init(IMap, {{12, 23}, {453, 65}, {676, 123}, {34, 67}});
-
- puts("\n\nc_foreach:");
- c_foreach (i, IVec, vec)
- printf(" %d", *i.ref);
-
- puts("\n\nc_foreach_r: reverse");
- c_foreach_rv (i, IVec, vec)
- printf(" %d", *i.ref);
-
- puts("\n\nc_foreach in map:");
- c_foreach (i, IMap, map)
- printf(" (%d %d)", i.ref->first, i.ref->second);
-
- puts("\n\nc_forpair:");
- c_forpair (key, val, IMap, map)
- printf(" (%d %d)", *_.key, *_.val);
-
- #define isOdd(i) (*i.ref & 1)
-
- puts("\n\nc_forfilter:");
- c_forfilter (i, IVec, vec,
- isOdd(i) &&
- c_flt_skip(i, 4) &&
- c_flt_take(i, 4)
- ){
- printf(" %d", *i.ref);
- }
-
- IVec_drop(&vec);
- IMap_drop(&map);
-}
+#include <stdio.h> +#include <stc/algo/filter.h> + +#define i_type IVec +#define i_key int +#include <stc/cstack.h> + +#define i_type IMap +#define i_key int +#define i_val int +#include <stc/cmap.h> + + +int main(void) +{ + puts("c_forrange:"); + c_forrange (30) printf(" xx"); + puts(""); + + c_forrange (i, 30) printf(" %lld", i); + puts(""); + + c_forrange (i, 30, 60) printf(" %lld", i); + puts(""); + + c_forrange (i, 30, 90, 2) printf(" %lld", i); + + puts("\n\nc_forlist:"); + c_forlist (i, int, {12, 23, 453, 65, 676}) + printf(" %d", *i.ref); + puts(""); + + c_forlist (i, const char*, {"12", "23", "453", "65", "676"}) + printf(" %s", *i.ref); + puts(""); + + IVec vec = c_init(IVec, {12, 23, 453, 65, 113, 215, 676, 34, 67, 20, 27, 66, 189, 45, 280, 199}); + IMap map = c_init(IMap, {{12, 23}, {453, 65}, {676, 123}, {34, 67}}); + + puts("\n\nc_foreach:"); + c_foreach (i, IVec, vec) + printf(" %d", *i.ref); + + puts("\n\nc_foreach_r: reverse"); + c_foreach_rv (i, IVec, vec) + printf(" %d", *i.ref); + + puts("\n\nc_foreach in map:"); + c_foreach (i, IMap, map) + printf(" (%d %d)", i.ref->first, i.ref->second); + + puts("\n\nc_forpair:"); + c_forpair (key, val, IMap, map) + printf(" (%d %d)", *_.key, *_.val); + + #define isOdd(i) (*i.ref & 1) + + puts("\n\nc_forfilter:"); + c_forfilter (i, IVec, vec, + isOdd(i) && + c_flt_skip(i, 4) && + c_flt_take(i, 4) + ){ + printf(" %d", *i.ref); + } + + IVec_drop(&vec); + IMap_drop(&map); +} diff --git a/misc/examples/random.c b/misc/examples/algorithms/random.c index b7c0f277..b7c0f277 100644 --- a/misc/examples/random.c +++ b/misc/examples/algorithms/random.c diff --git a/misc/examples/shape.c b/misc/examples/algorithms/shape.c index bd4bdd5a..bd4bdd5a 100644 --- a/misc/examples/shape.c +++ b/misc/examples/algorithms/shape.c diff --git a/misc/examples/shape.cpp b/misc/examples/algorithms/shape.cpp index ea1f53d2..ea1f53d2 100644 --- a/misc/examples/shape.cpp +++ b/misc/examples/algorithms/shape.cpp diff --git a/misc/examples/bits.c b/misc/examples/bitsets/bits.c index e0a11346..e0a11346 100644 --- a/misc/examples/bits.c +++ b/misc/examples/bitsets/bits.c diff --git a/misc/examples/bits2.c b/misc/examples/bitsets/bits2.c index de2f16f4..de2f16f4 100644 --- a/misc/examples/bits2.c +++ b/misc/examples/bitsets/bits2.c diff --git a/misc/examples/prime.c b/misc/examples/bitsets/prime.c index cb3b095a..cb3b095a 100644 --- a/misc/examples/prime.c +++ b/misc/examples/bitsets/prime.c diff --git a/misc/examples/cointerleave.c b/misc/examples/coroutines/cointerleave.c index 599ceaab..599ceaab 100644 --- a/misc/examples/cointerleave.c +++ b/misc/examples/coroutines/cointerleave.c diff --git a/misc/examples/coread.c b/misc/examples/coroutines/coread.c index a13f6be5..a13f6be5 100644 --- a/misc/examples/coread.c +++ b/misc/examples/coroutines/coread.c diff --git a/misc/examples/coroutines.c b/misc/examples/coroutines/coroutines.c index b8dfaa13..b8dfaa13 100644 --- a/misc/examples/coroutines.c +++ b/misc/examples/coroutines/coroutines.c diff --git a/misc/examples/coroutines/cotasks1.c b/misc/examples/coroutines/cotasks1.c new file mode 100644 index 00000000..c87582f1 --- /dev/null +++ b/misc/examples/coroutines/cotasks1.c @@ -0,0 +1,100 @@ +// https://mariusbancila.ro/blog/2020/06/22/a-cpp20-coroutine-example/ + +#include <time.h> +#include <stdio.h> +#define i_static +#include <stc/cstr.h> +#include <stc/algo/coroutine.h> + +struct next_value { + int val; + int cco_state; + cco_timer tm; +}; + +int next_value(struct next_value* co) +{ + cco_routine (co) { + while (true) { + cco_timer_await(&co->tm, 1 + rand() % 2); + co->val = rand(); + cco_yield(); + } + } + return 0; +} + +void print_time() +{ + time_t now = time(NULL); + char mbstr[64]; + strftime(mbstr, sizeof(mbstr), "[%H:%M:%S]", localtime(&now)); + printf("%s ", mbstr); +} + +// PRODUCER + +struct produce_items { + struct next_value next; + cstr str; + int cco_state; +}; + +int produce_items(struct produce_items* p) +{ + cco_routine (p) { + p->str = cstr_null; + while (true) + { + cco_await(next_value(&p->next) != CCO_AWAIT); + cstr_printf(&p->str, "item %d", p->next.val); + print_time(); + printf("produced %s\n", cstr_str(&p->str)); + cco_yield(); + } + cco_cleanup: + cstr_drop(&p->str); + puts("done produce"); + } + return 0; +} + +// CONSUMER + +struct consume_items { + int n, i; + int cco_state; +}; + +int consume_items(struct consume_items* c, struct produce_items* p) +{ + cco_routine (c) { + for (c->i = 1; c->i <= c->n; ++c->i) + { + printf("consume #%d\n", c->i); + cco_await(produce_items(p) != CCO_AWAIT); + print_time(); + printf("consumed %s\n", cstr_str(&p->str)); + } + cco_cleanup: + puts("done consume"); + } + return 0; +} + +int main(void) +{ + struct produce_items produce = {0}; + struct consume_items consume = {.n=5}; + int count = 0; + + cco_block_on(consume_items(&consume, &produce)) + { + ++count; + //cco_sleep(0.001); + //if (consume.i == 3) cco_stop(&consume); + } + cco_stop(&produce); + produce_items(&produce); + printf("count: %d\n", count); +}
\ No newline at end of file diff --git a/misc/examples/coroutines/cotasks2.c b/misc/examples/coroutines/cotasks2.c new file mode 100644 index 00000000..293583bc --- /dev/null +++ b/misc/examples/coroutines/cotasks2.c @@ -0,0 +1,103 @@ +// https://mariusbancila.ro/blog/2020/06/22/a-cpp20-coroutine-example/ + +#include <time.h> +#include <stdio.h> +#define i_static +#include <stc/cstr.h> +#include <stc/algo/coroutine.h> + +cco_task_struct (next_value, + int val; + cco_timer tm; +); + +int next_value(struct next_value* co, cco_runtime* rt) +{ + cco_routine (co) { + while (true) { + cco_timer_await(&co->tm, 1 + rand() % 2); + co->val = rand(); + cco_yield(); + } + } + return 0; +} + +void print_time() +{ + time_t now = time(NULL); + char mbstr[64]; + strftime(mbstr, sizeof(mbstr), "[%H:%M:%S]", localtime(&now)); + printf("%s ", mbstr); +} + +// PRODUCER + +cco_task_struct (produce_items, + struct next_value next; + cstr str; +); + +int produce_items(struct produce_items* p, cco_runtime* rt) +{ + cco_routine (p) { + p->str = cstr_null; + while (true) + { + // await for next CCO_YIELD in next_value() + cco_await_task(&p->next, rt, CCO_YIELD); + cstr_printf(&p->str, "item %d", p->next.val); + print_time(); + printf("produced %s\n", cstr_str(&p->str)); + cco_yield(); + } + cco_cleanup: + cstr_drop(&p->str); + puts("done produce"); + } + return 0; +} + +// CONSUMER + +cco_task_struct (consume_items, + int n, i; + struct produce_items produce; +); + +int consume_items(struct consume_items* c, cco_runtime* rt) +{ + cco_routine (c) { + for (c->i = 1; c->i <= c->n; ++c->i) + { + printf("consume #%d\n", c->i); + cco_await_task(&c->produce, rt, CCO_YIELD); + print_time(); + printf("consumed %s\n", cstr_str(&c->produce.str)); + } + cco_cleanup: + cco_stop(&c->produce); + cco_resume(&c->produce, rt); + puts("done consume"); + } + return 0; +} + +int main(void) +{ + struct consume_items consume = { + .n=5, + .cco_fn=consume_items, + .produce={.cco_fn=produce_items, .next={.cco_fn=next_value}}, + }; + int count = 0; + + cco_block_task(&consume) + { + ++count; + //cco_sleep(0.001); + //if (consume.i == 3) + // cco_stop(&consume); + } + printf("count: %d\n", count); +}
\ No newline at end of file diff --git a/misc/examples/dining_philosophers.c b/misc/examples/coroutines/dining_philosophers.c index a5063a42..a5063a42 100644 --- a/misc/examples/dining_philosophers.c +++ b/misc/examples/coroutines/dining_philosophers.c diff --git a/misc/examples/generator.c b/misc/examples/coroutines/generator.c index a15f9ba5..a15f9ba5 100644 --- a/misc/examples/generator.c +++ b/misc/examples/coroutines/generator.c diff --git a/misc/examples/scheduler.c b/misc/examples/coroutines/scheduler.c index 38defd0f..38defd0f 100644 --- a/misc/examples/scheduler.c +++ b/misc/examples/coroutines/scheduler.c diff --git a/misc/examples/triples.c b/misc/examples/coroutines/triples.c index 9f2fcc1e..9f2fcc1e 100644 --- a/misc/examples/triples.c +++ b/misc/examples/coroutines/triples.c diff --git a/misc/examples/birthday.c b/misc/examples/hashmaps/birthday.c index 4742cb45..4742cb45 100644 --- a/misc/examples/birthday.c +++ b/misc/examples/hashmaps/birthday.c diff --git a/misc/examples/books.c b/misc/examples/hashmaps/books.c index 1fd57f27..1fd57f27 100644 --- a/misc/examples/books.c +++ b/misc/examples/hashmaps/books.c diff --git a/misc/examples/hashmap.c b/misc/examples/hashmaps/hashmap.c index cf11b7f7..cf11b7f7 100644 --- a/misc/examples/hashmap.c +++ b/misc/examples/hashmaps/hashmap.c diff --git a/misc/examples/new_map.c b/misc/examples/hashmaps/new_map.c index de990040..de990040 100644 --- a/misc/examples/new_map.c +++ b/misc/examples/hashmaps/new_map.c diff --git a/misc/examples/phonebook.c b/misc/examples/hashmaps/phonebook.c index faf7566e..faf7566e 100644 --- a/misc/examples/phonebook.c +++ b/misc/examples/hashmaps/phonebook.c diff --git a/misc/examples/unordered_set.c b/misc/examples/hashmaps/unordered_set.c index dd899d78..dd899d78 100644 --- a/misc/examples/unordered_set.c +++ b/misc/examples/hashmaps/unordered_set.c diff --git a/misc/examples/vikings.c b/misc/examples/hashmaps/vikings.c index d6125854..d6125854 100644 --- a/misc/examples/vikings.c +++ b/misc/examples/hashmaps/vikings.c diff --git a/misc/examples/intrusive.c b/misc/examples/linkedlists/intrusive.c index c22ed260..c22ed260 100644 --- a/misc/examples/intrusive.c +++ b/misc/examples/linkedlists/intrusive.c diff --git a/misc/examples/list.c b/misc/examples/linkedlists/list.c index ad8bebb8..ad8bebb8 100644 --- a/misc/examples/list.c +++ b/misc/examples/linkedlists/list.c diff --git a/misc/examples/list_erase.c b/misc/examples/linkedlists/list_erase.c index 211c5a5d..211c5a5d 100644 --- a/misc/examples/list_erase.c +++ b/misc/examples/linkedlists/list_erase.c diff --git a/misc/examples/list_splice.c b/misc/examples/linkedlists/list_splice.c index f1fd6e1f..f1fd6e1f 100644 --- a/misc/examples/list_splice.c +++ b/misc/examples/linkedlists/list_splice.c diff --git a/misc/examples/new_list.c b/misc/examples/linkedlists/new_list.c index 2112bf1f..2112bf1f 100644 --- a/misc/examples/new_list.c +++ b/misc/examples/linkedlists/new_list.c diff --git a/misc/examples/make.sh b/misc/examples/make.sh index cf224950..7135ffdf 100755 --- a/misc/examples/make.sh +++ b/misc/examples/make.sh @@ -37,18 +37,20 @@ else fi if [ $run = 0 ] ; then - for i in *.c ; do - echo $comp -I../../include $i $clibs $oflag$(basename $i .c).exe - $comp -I../../include $i $clibs $oflag$(basename $i .c).exe + for i in */*.c ; do + #out=$(basename $i .c).exe + out=$(dirname $i)/$(basename $i .c).exe + echo $comp -I../../include $i $clibs $oflag$out + $comp -I../../include $i $clibs $oflag$out done else - for i in *.c ; do + for i in */*.c ; do echo $comp -I../../include $i $clibs $comp -I../../include $i $clibs - if [ -f $(basename -s .c $i).exe ]; then ./$(basename -s .c $i).exe; fi - if [ -f ./a.exe ]; then ./a.exe; fi - if [ -f ./a.out ]; then ./a.out; fi + #out=$(basename $i .c).exe + out=$(dirname $i)/$(basename $i .c).exe + if [ -f $out ]; then ./$out; fi done fi -rm -f a.out *.o *.obj # *.exe +#rm -f a.out *.o *.obj # *.exe diff --git a/misc/examples/astar.c b/misc/examples/mixed/astar.c index 590b7952..590b7952 100644 --- a/misc/examples/astar.c +++ b/misc/examples/mixed/astar.c diff --git a/misc/examples/complex.c b/misc/examples/mixed/complex.c index 4eb1574b..4eb1574b 100644 --- a/misc/examples/complex.c +++ b/misc/examples/mixed/complex.c diff --git a/misc/examples/convert.c b/misc/examples/mixed/convert.c index fa64560e..fa64560e 100644 --- a/misc/examples/convert.c +++ b/misc/examples/mixed/convert.c diff --git a/misc/examples/demos.c b/misc/examples/mixed/demos.c index 1a604d9f..1a604d9f 100644 --- a/misc/examples/demos.c +++ b/misc/examples/mixed/demos.c diff --git a/misc/examples/inits.c b/misc/examples/mixed/inits.c index 53a49f1f..53a49f1f 100644 --- a/misc/examples/inits.c +++ b/misc/examples/mixed/inits.c diff --git a/misc/examples/read.c b/misc/examples/mixed/read.c index b12f7409..de04fd31 100644 --- a/misc/examples/read.c +++ b/misc/examples/mixed/read.c @@ -7,9 +7,9 @@ cvec_str read_file(const char* name) { - cvec_str vec = cvec_str_init(); + cvec_str vec = {0}; c_with (FILE* f = fopen(name, "r"), fclose(f)) - c_with (cstr line = cstr_null, cstr_drop(&line)) + c_with (cstr line = {0}, cstr_drop(&line)) while (cstr_getline(&line, f)) cvec_str_push(&vec, cstr_clone(line)); return vec; diff --git a/misc/examples/functor.c b/misc/examples/priorityqueues/functor.c index e3bde1dd..e3bde1dd 100644 --- a/misc/examples/functor.c +++ b/misc/examples/priorityqueues/functor.c diff --git a/misc/examples/new_pque.c b/misc/examples/priorityqueues/new_pque.c index 16823bb6..16823bb6 100644 --- a/misc/examples/new_pque.c +++ b/misc/examples/priorityqueues/new_pque.c diff --git a/misc/examples/priority.c b/misc/examples/priorityqueues/priority.c index bf2e188a..bf2e188a 100644 --- a/misc/examples/priority.c +++ b/misc/examples/priorityqueues/priority.c diff --git a/misc/examples/new_queue.c b/misc/examples/queues/new_queue.c index f3592df6..f3592df6 100644 --- a/misc/examples/new_queue.c +++ b/misc/examples/queues/new_queue.c diff --git a/misc/examples/queue.c b/misc/examples/queues/queue.c index 56b5beb9..56b5beb9 100644 --- a/misc/examples/queue.c +++ b/misc/examples/queues/queue.c diff --git a/misc/examples/regex1.c b/misc/examples/regularexpressions/regex1.c index d8032358..d8032358 100644 --- a/misc/examples/regex1.c +++ b/misc/examples/regularexpressions/regex1.c diff --git a/misc/examples/regex2.c b/misc/examples/regularexpressions/regex2.c index a798b1a1..a798b1a1 100644 --- a/misc/examples/regex2.c +++ b/misc/examples/regularexpressions/regex2.c diff --git a/misc/examples/regex_match.c b/misc/examples/regularexpressions/regex_match.c index 11426d2d..11426d2d 100644 --- a/misc/examples/regex_match.c +++ b/misc/examples/regularexpressions/regex_match.c diff --git a/misc/examples/regex_replace.c b/misc/examples/regularexpressions/regex_replace.c index f1ea2711..f1ea2711 100644 --- a/misc/examples/regex_replace.c +++ b/misc/examples/regularexpressions/regex_replace.c diff --git a/misc/examples/sidebyside.cpp b/misc/examples/sidebyside.cpp deleted file mode 100644 index 9414b691..00000000 --- a/misc/examples/sidebyside.cpp +++ /dev/null @@ -1,57 +0,0 @@ -#include <iostream> -#include <map> -#include <string> -#include <stc/cstr.h> - -#define i_type IIMap -#define i_key int -#define i_val int -#include <stc/csmap.h> - -#define i_type SIMap -#define i_key_str -#define i_val int -#include <stc/cmap.h> - -int main(void) { - { - std::map<int, int> hist; - hist.emplace(12, 100).first->second += 1; - hist.emplace(13, 100).first->second += 1; - hist.emplace(12, 100).first->second += 1; - - for (auto i: hist) - std::cout << i.first << ", " << i.second << std::endl; - std::cout << std::endl; - } - { - IIMap hist = {0}; - IIMap_insert(&hist, 12, 100).ref->second += 1; - IIMap_insert(&hist, 13, 100).ref->second += 1; - IIMap_insert(&hist, 12, 100).ref->second += 1; - - c_foreach (i, IIMap, hist) - printf("%d, %d\n", i.ref->first, i.ref->second); - puts(""); - IIMap_drop(&hist); - } - // =================================================== - { - std::map<std::string, int> food = - {{"burger", 5}, {"pizza", 12}, {"steak", 15}}; - - for (auto i: food) - std::cout << i.first << ", " << i.second << std::endl; - std::cout << std::endl; - } - { - SIMap food = {0}; - c_forlist (i, SIMap_raw, {{"burger", 5}, {"pizza", 12}, {"steak", 15}}) - SIMap_emplace(&food, i.ref->first, i.ref->second); - - c_foreach (i, SIMap, food) - printf("%s, %d\n", cstr_str(&i.ref->first), i.ref->second); - puts(""); - SIMap_drop(&food); - } -} diff --git a/misc/examples/arc_containers.c b/misc/examples/smartpointers/arc_containers.c index 2fb04c56..2fb04c56 100644 --- a/misc/examples/arc_containers.c +++ b/misc/examples/smartpointers/arc_containers.c diff --git a/misc/examples/arc_demo.c b/misc/examples/smartpointers/arc_demo.c index 929a48a1..929a48a1 100644 --- a/misc/examples/arc_demo.c +++ b/misc/examples/smartpointers/arc_demo.c diff --git a/misc/examples/arcvec_erase.c b/misc/examples/smartpointers/arcvec_erase.c index ba54c1c7..ba54c1c7 100644 --- a/misc/examples/arcvec_erase.c +++ b/misc/examples/smartpointers/arcvec_erase.c diff --git a/misc/examples/box.c b/misc/examples/smartpointers/box.c index 94d126c0..94d126c0 100644 --- a/misc/examples/box.c +++ b/misc/examples/smartpointers/box.c diff --git a/misc/examples/box2.c b/misc/examples/smartpointers/box2.c index eaab1c47..eaab1c47 100644 --- a/misc/examples/box2.c +++ b/misc/examples/smartpointers/box2.c diff --git a/misc/examples/music_arc.c b/misc/examples/smartpointers/music_arc.c index 16111b0b..16111b0b 100644 --- a/misc/examples/music_arc.c +++ b/misc/examples/smartpointers/music_arc.c diff --git a/misc/examples/new_sptr.c b/misc/examples/smartpointers/new_sptr.c index 3c6fa16c..3c6fa16c 100644 --- a/misc/examples/new_sptr.c +++ b/misc/examples/smartpointers/new_sptr.c diff --git a/misc/examples/person_arc.c b/misc/examples/smartpointers/person_arc.c index 38c883a7..38c883a7 100644 --- a/misc/examples/person_arc.c +++ b/misc/examples/smartpointers/person_arc.c diff --git a/misc/examples/rawptr_elements.c b/misc/examples/smartpointers/rawptr_elements.c index 694ce12e..694ce12e 100644 --- a/misc/examples/rawptr_elements.c +++ b/misc/examples/smartpointers/rawptr_elements.c diff --git a/misc/examples/csmap_erase.c b/misc/examples/sortedmaps/csmap_erase.c index 8d4eeae3..8d4eeae3 100644 --- a/misc/examples/csmap_erase.c +++ b/misc/examples/sortedmaps/csmap_erase.c diff --git a/misc/examples/csmap_find.c b/misc/examples/sortedmaps/csmap_find.c index c392338d..c392338d 100644 --- a/misc/examples/csmap_find.c +++ b/misc/examples/sortedmaps/csmap_find.c diff --git a/misc/examples/csmap_insert.c b/misc/examples/sortedmaps/csmap_insert.c index c9f02891..c9f02891 100644 --- a/misc/examples/csmap_insert.c +++ b/misc/examples/sortedmaps/csmap_insert.c diff --git a/misc/examples/csset_erase.c b/misc/examples/sortedmaps/csset_erase.c index 9c7f5e1a..9c7f5e1a 100644 --- a/misc/examples/csset_erase.c +++ b/misc/examples/sortedmaps/csset_erase.c diff --git a/misc/examples/gauss2.c b/misc/examples/sortedmaps/gauss2.c index 1ab8ade5..1ab8ade5 100644 --- a/misc/examples/gauss2.c +++ b/misc/examples/sortedmaps/gauss2.c diff --git a/misc/examples/mmap.c b/misc/examples/sortedmaps/listmap.c index 04a605a7..04a605a7 100644 --- a/misc/examples/mmap.c +++ b/misc/examples/sortedmaps/listmap.c diff --git a/misc/examples/mapmap.c b/misc/examples/sortedmaps/mapmap.c index d3065659..d3065659 100644 --- a/misc/examples/mapmap.c +++ b/misc/examples/sortedmaps/mapmap.c diff --git a/misc/examples/multimap.c b/misc/examples/sortedmaps/multimap.c index 1068a5dc..1068a5dc 100644 --- a/misc/examples/multimap.c +++ b/misc/examples/sortedmaps/multimap.c diff --git a/misc/examples/new_smap.c b/misc/examples/sortedmaps/new_smap.c index ee946c9a..ee946c9a 100644 --- a/misc/examples/new_smap.c +++ b/misc/examples/sortedmaps/new_smap.c diff --git a/misc/examples/sorted_map.c b/misc/examples/sortedmaps/sorted_map.c index 89381554..89381554 100644 --- a/misc/examples/sorted_map.c +++ b/misc/examples/sortedmaps/sorted_map.c diff --git a/misc/examples/multidim.c b/misc/examples/spans/multidim.c index 798a1126..798a1126 100644 --- a/misc/examples/multidim.c +++ b/misc/examples/spans/multidim.c diff --git a/misc/examples/printspan.c b/misc/examples/spans/printspan.c index cd3c5f4f..cd3c5f4f 100644 --- a/misc/examples/printspan.c +++ b/misc/examples/spans/printspan.c diff --git a/misc/examples/cstr_match.c b/misc/examples/strings/cstr_match.c index be03e981..be03e981 100644 --- a/misc/examples/cstr_match.c +++ b/misc/examples/strings/cstr_match.c diff --git a/misc/examples/replace.c b/misc/examples/strings/replace.c index 59a56bf7..59a56bf7 100644 --- a/misc/examples/replace.c +++ b/misc/examples/strings/replace.c diff --git a/misc/examples/splitstr.c b/misc/examples/strings/splitstr.c index ef7ed174..ef7ed174 100644 --- a/misc/examples/splitstr.c +++ b/misc/examples/strings/splitstr.c diff --git a/misc/examples/sso_map.c b/misc/examples/strings/sso_map.c index 4f84b651..4f84b651 100644 --- a/misc/examples/sso_map.c +++ b/misc/examples/strings/sso_map.c diff --git a/misc/examples/sso_substr.c b/misc/examples/strings/sso_substr.c index 687658df..687658df 100644 --- a/misc/examples/sso_substr.c +++ b/misc/examples/strings/sso_substr.c diff --git a/misc/examples/sview_split.c b/misc/examples/strings/sview_split.c index ac275da0..ac275da0 100644 --- a/misc/examples/sview_split.c +++ b/misc/examples/strings/sview_split.c diff --git a/misc/examples/utf8replace_c.c b/misc/examples/strings/utf8replace_c.c index 1d54486f..1d54486f 100644 --- a/misc/examples/utf8replace_c.c +++ b/misc/examples/strings/utf8replace_c.c diff --git a/misc/examples/utf8replace_rs.rs b/misc/examples/strings/utf8replace_rs.rs index 8b163b4e..8b163b4e 100644 --- a/misc/examples/utf8replace_rs.rs +++ b/misc/examples/strings/utf8replace_rs.rs diff --git a/misc/examples/lower_bound.c b/misc/examples/vectors/lower_bound.c index bea828f2..bea828f2 100644 --- a/misc/examples/lower_bound.c +++ b/misc/examples/vectors/lower_bound.c diff --git a/misc/examples/new_vec.c b/misc/examples/vectors/new_vec.c index 88efd55a..88efd55a 100644 --- a/misc/examples/new_vec.c +++ b/misc/examples/vectors/new_vec.c diff --git a/misc/examples/stack.c b/misc/examples/vectors/stack.c index 6297fb6f..6297fb6f 100644 --- a/misc/examples/stack.c +++ b/misc/examples/vectors/stack.c |
