diff options
| author | _Tradam <[email protected]> | 2023-09-08 01:29:47 +0000 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-09-08 01:29:47 +0000 |
| commit | 3c76c7f3d5db3f9586a90d03f8fbb02d79de9acd (patch) | |
| tree | afbe4b540967223911f7c5de36559b82154f02f3 /misc/examples/new_smap.c | |
| parent | 0841165881871ee01b782129be681209aeed2423 (diff) | |
| parent | 1a72205fe05c2375cfd380dd8381a8460d9ed8d1 (diff) | |
| download | STC-modified-modified.tar.gz STC-modified-modified.zip | |
Diffstat (limited to 'misc/examples/new_smap.c')
| -rw-r--r-- | misc/examples/new_smap.c | 66 |
1 files changed, 0 insertions, 66 deletions
diff --git a/misc/examples/new_smap.c b/misc/examples/new_smap.c deleted file mode 100644 index d8245b8b..00000000 --- a/misc/examples/new_smap.c +++ /dev/null @@ -1,66 +0,0 @@ -#include <stc/cstr.h> -#include <stc/forward.h> - -forward_csmap(PMap, struct Point, int); - -// Use forward declared PMap in struct -typedef struct { - PMap pntmap; - cstr name; -} MyStruct; - -// Point => int map -struct Point { int x, y; } typedef Point; -int point_cmp(const Point* a, const Point* b) { - int c = a->x - b->x; - return c ? c : a->y - b->y; -} - -#define i_type PMap -#define i_key Point -#define i_val int -#define i_cmp point_cmp -#define i_is_forward -#include <stc/csmap.h> - -// cstr => cstr map -#define i_type SMap -#define i_key_str -#define i_val_str -#include <stc/csmap.h> - -// cstr set -#define i_type SSet -#define i_key_str -#include <stc/csset.h> - - -int main() -{ - 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 (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"); - - PMap_drop(&pmap); - SMap_drop(&smap); - SSet_drop(&sset); -} |
