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 #include "cx/map.h"
30 #include <string.h>
31
32
33
34 static void cx_empty_map_noop(__attribute__((__unused__)) CxMap *map) {
35
36 }
37
38 static void *cx_empty_map_get(
39 __attribute__((__unused__)) CxMap
const *map,
40 __attribute__((__unused__)) CxHashKey key
41 ) {
42 return NULL;
43 }
44
45 static bool cx_empty_map_iter_valid(__attribute__((__unused__))
void const *iter) {
46 return false;
47 }
48
49 static CxIterator cx_empty_map_iterator(
50 struct cx_map_s
const *map,
51 __attribute__((__unused__))
enum cx_map_iterator_type type
52 ) {
53 CxIterator iter = {
0};
54 iter.src_handle = map;
55 iter.base.valid = cx_empty_map_iter_valid;
56 return iter;
57 }
58
59 static struct cx_map_class_s cx_empty_map_class = {
60 cx_empty_map_noop,
61 cx_empty_map_noop,
62 NULL,
63 cx_empty_map_get,
64 NULL,
65 cx_empty_map_iterator
66 };
67
68 CxMap cx_empty_map = {
69 NULL,
70 NULL,
71 0,
72 0,
73 NULL,
74 NULL,
75 NULL,
76 false,
77 &cx_empty_map_class
78 };
79
80 CxMap *
const cxEmptyMap = &cx_empty_map;
81
82
83
84 CxMutIterator cxMapMutIteratorValues(CxMap *map) {
85 CxIterator it = map->cl->iterator(map,
CX_MAP_ITERATOR_VALUES);
86 it.base.mutating = true;
87
88
89 CxMutIterator iter;
90 memcpy(&iter, &it,
sizeof(CxMutIterator));
91 return iter;
92 }
93
94 CxMutIterator cxMapMutIteratorKeys(CxMap *map) {
95 CxIterator it = map->cl->iterator(map,
CX_MAP_ITERATOR_KEYS);
96 it.base.mutating = true;
97
98
99 CxMutIterator iter;
100 memcpy(&iter, &it,
sizeof(CxMutIterator));
101 return iter;
102 }
103
104 CxMutIterator cxMapMutIterator(CxMap *map) {
105 CxIterator it = map->cl->iterator(map,
CX_MAP_ITERATOR_PAIRS);
106 it.base.mutating = true;
107
108
109 CxMutIterator iter;
110 memcpy(&iter, &it,
sizeof(CxMutIterator));
111 return iter;
112 }
113