summaryrefslogtreecommitdiffhomepage
path: root/misc/examples/new_smap.c
diff options
context:
space:
mode:
Diffstat (limited to 'misc/examples/new_smap.c')
-rw-r--r--misc/examples/new_smap.c61
1 files changed, 25 insertions, 36 deletions
diff --git a/misc/examples/new_smap.c b/misc/examples/new_smap.c
index 0870ee3d..d8245b8b 100644
--- a/misc/examples/new_smap.c
+++ b/misc/examples/new_smap.c
@@ -4,15 +4,10 @@
forward_csmap(PMap, struct Point, int);
// Use forward declared PMap in struct
-struct MyStruct {
+typedef struct {
PMap pntmap;
cstr name;
-} typedef MyStruct;
-
-// int => int map
-#define i_key int
-#define i_val int
-#include <stc/csmap.h>
+} MyStruct;
// Point => int map
struct Point { int x, y; } typedef Point;
@@ -25,7 +20,7 @@ int point_cmp(const Point* a, const Point* b) {
#define i_key Point
#define i_val int
#define i_cmp point_cmp
-#define i_opt c_is_forward
+#define i_is_forward
#include <stc/csmap.h>
// cstr => cstr map
@@ -42,36 +37,30 @@ int point_cmp(const Point* a, const Point* b) {
int main()
{
- c_auto (csmap_int, imap) {
- csmap_int_insert(&imap, 123, 321);
- }
-
- c_auto (PMap, pmap) {
- pmap = c_make(PMap, {
- {{42, 14}, 1},
- {{32, 94}, 2},
- {{62, 81}, 3},
- });
+ PMap pmap = c_make(PMap, {
+ {{42, 14}, 1},
+ {{32, 94}, 2},
+ {{62, 81}, 3},
+ });
+ SMap smap = c_make(SMap, {
+ {"Hello, friend", "this is the mapped value"},
+ {"The brown fox", "jumped"},
+ {"This is the time", "for all good things"},
+ });
+ SSet sset = {0};
- c_forpair (p, i, PMap, pmap)
- printf(" (%d,%d: %d)", _.p->x, _.p->y, *_.i);
- puts("");
- }
+ c_forpair (p, i, PMap, pmap)
+ printf(" (%d,%d: %d)", _.p->x, _.p->y, *_.i);
+ puts("");
- c_auto (SMap, smap) {
- smap = c_make(SMap, {
- {"Hello, friend", "this is the mapped value"},
- {"The brown fox", "jumped"},
- {"This is the time", "for all good things"},
- });
+ c_forpair (i, j, SMap, smap)
+ printf(" (%s: %s)\n", cstr_str(_.i), cstr_str(_.j));
- c_forpair (i, j, SMap, smap)
- printf(" (%s: %s)\n", cstr_str(_.i), cstr_str(_.j));
- }
+ SSet_emplace(&sset, "Hello, friend");
+ SSet_emplace(&sset, "Goodbye, foe");
+ printf("Found? %s\n", SSet_contains(&sset, "Hello, friend") ? "true" : "false");
- c_auto (SSet, sset) {
- SSet_emplace(&sset, "Hello, friend");
- SSet_emplace(&sset, "Goodbye, foe");
- printf("Found? %s\n", SSet_contains(&sset, "Hello, friend") ? "true" : "false");
- }
+ PMap_drop(&pmap);
+ SMap_drop(&smap);
+ SSet_drop(&sset);
}