summaryrefslogtreecommitdiffhomepage
path: root/examples/mapmap.c
diff options
context:
space:
mode:
authorTyge Lovset <[email protected]>2022-12-20 23:31:51 +0100
committerTyge Lovset <[email protected]>2022-12-20 23:31:51 +0100
commit5f57d597cd27aef55adbcb3b452973b0c6e33667 (patch)
treedfd59c2fd0e36a6ef37912a9d0cc5a65970f1524 /examples/mapmap.c
parent1763be8c8cbbc0896477fcf924edd4180d1345a9 (diff)
downloadSTC-modified-5f57d597cd27aef55adbcb3b452973b0c6e33667.tar.gz
STC-modified-5f57d597cd27aef55adbcb3b452973b0c6e33667.zip
Restructured folders: examples, benchmarks, tests into misc folder.
Diffstat (limited to 'examples/mapmap.c')
-rw-r--r--examples/mapmap.c68
1 files changed, 0 insertions, 68 deletions
diff --git a/examples/mapmap.c b/examples/mapmap.c
deleted file mode 100644
index 488cc539..00000000
--- a/examples/mapmap.c
+++ /dev/null
@@ -1,68 +0,0 @@
-// create a structure like: std::map<std::string, std::map<std::string, std::string>>:
-
-#include <stc/cstr.h>
-
-// People: std::map<std::string, std::string>
-#define i_type People
-#define i_key_str
-#define i_val_str
-#define i_keydrop(p) (printf("kdrop: %s\n", cstr_str(p)), cstr_drop(p)) // override
-#include <stc/csmap.h>
-
-// Departments: std::map<std::string, People>
-#define i_type Departments
-#define i_key_str
-#define i_valclass People
-// Shorthand for:
-// #define i_val People
-// #define i_cmp People_cmp
-// #define i_valclone People_clone
-// #define i_valdrop People_drop
-#include <stc/csmap.h>
-
-
-void add(Departments* deps, const char* name, const char* email, const char* dep)
-{
- People *people = &Departments_insert(deps, cstr_from(dep), People_init()).ref->second;
- People_emplace_or_assign(people, name, email);
-}
-
-int contains(Departments* map, const char* name)
-{
- int count = 0;
- c_foreach (i, Departments, *map)
- if (People_contains(&i.ref->second, name))
- ++count;
- return count;
-}
-
-int main(void)
-{
- c_auto (Departments, map)
- {
- add(&map, "Anna Kendro", "[email protected]", "Support");
- add(&map, "Terry Dane", "[email protected]", "Development");
- add(&map, "Kik Winston", "[email protected]", "Finance");
- add(&map, "Nancy Drew", "[email protected]", "Development");
- add(&map, "Nick Denton", "[email protected]", "Finance");
- add(&map, "Stan Whiteword", "[email protected]", "Marketing");
- add(&map, "Serena Bath", "[email protected]", "Support");
- add(&map, "Patrick Dust", "[email protected]", "Finance");
- add(&map, "Red Winger", "[email protected]", "Marketing");
- add(&map, "Nick Denton", "[email protected]", "Support");
- add(&map, "Colin Turth", "[email protected]", "Support");
- add(&map, "Dennis Kay", "[email protected]", "Marketing");
- add(&map, "Anne Dickens", "[email protected]", "Development");
-
- c_foreach (i, Departments, map)
- c_forpair (name, email, People, i.ref->second)
- printf("%s: %s - %s\n", cstr_str(&i.ref->first), cstr_str(_.name), cstr_str(_.email));
- puts("");
-
- printf("found Nick Denton: %d\n", contains(&map, "Nick Denton"));
- printf("found Patrick Dust: %d\n", contains(&map, "Patrick Dust"));
- printf("found Dennis Kay: %d\n", contains(&map, "Dennis Kay"));
- printf("found Serena Bath: %d\n", contains(&map, "Serena Bath"));
- puts("Done");
- }
-}