1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
// unordered_map<string, unordered_map<string, string>>:
#define i_type People
#define i_key_str
#define i_val_str
#define i_keydrop(p) (printf("kdrop: %s\n", (p)->str), cstr_drop(p))
#include <stc/csmap.h>
#define i_type Departments
#define i_key_str
#define i_val_bind People
#include <stc/csmap.h>
#define i_type Stack
#define i_val_bind People_value
#define i_opt c_no_cmp
//#define i_from People_value_clone
//#define i_drop People_value_drop
#include <stc/cstack.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);
}
Stack contains(Departments* map, const char* name)
{
Stack stk = Stack_init();
const People_value* v;
c_foreach (i, Departments, *map)
if ((v = People_get(&i.ref->second, name))) {
Stack_push(&stk, People_value_clone(*v));
}
return stk;
}
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", i.ref->first.str, _.name.str, _.email.str);
puts("");
c_auto (Stack, s) printf("found: %" PRIuMAX "\n", Stack_size(s = contains(&map, "Nick Denton")));
c_auto (Stack, s) printf("found: %" PRIuMAX "\n", Stack_size(s = contains(&map, "Patrick Dust")));
c_auto (Stack, s) printf("found: %" PRIuMAX "\n", Stack_size(s = contains(&map, "Dennis Kay")));
c_auto (Stack, s) printf("found: %" PRIuMAX "\n", Stack_size(s = contains(&map, "Serena Bath")));
puts("Done");
}
}
|