ucx/map.c

branch
newapi
changeset 324
ce13a778654a
parent 174
0358f1d9c506
equal deleted inserted replaced
323:38cb8e3992e8 324:ce13a778654a
34 static void cx_empty_map_noop(__attribute__((__unused__)) CxMap *map) { 34 static void cx_empty_map_noop(__attribute__((__unused__)) CxMap *map) {
35 // this is a noop, but MUST be implemented 35 // this is a noop, but MUST be implemented
36 } 36 }
37 37
38 static void *cx_empty_map_get( 38 static void *cx_empty_map_get(
39 __attribute__((__unused__)) CxMap const *map, 39 __attribute__((__unused__)) const CxMap *map,
40 __attribute__((__unused__)) CxHashKey key 40 __attribute__((__unused__)) CxHashKey key
41 ) { 41 ) {
42 return NULL; 42 return NULL;
43 } 43 }
44 44
45 static bool cx_empty_map_iter_valid(__attribute__((__unused__)) void const *iter) { 45 static bool cx_empty_map_iter_valid(__attribute__((__unused__)) const void *iter) {
46 return false; 46 return false;
47 } 47 }
48 48
49 static CxIterator cx_empty_map_iterator( 49 static CxIterator cx_empty_map_iterator(
50 struct cx_map_s const *map, 50 const struct cx_map_s *map,
51 __attribute__((__unused__)) enum cx_map_iterator_type type 51 __attribute__((__unused__)) enum cx_map_iterator_type type
52 ) { 52 ) {
53 CxIterator iter = {0}; 53 CxIterator iter = {0};
54 iter.src_handle = map; 54 iter.src_handle.c = map;
55 iter.base.valid = cx_empty_map_iter_valid; 55 iter.base.valid = cx_empty_map_iter_valid;
56 return iter; 56 return iter;
57 } 57 }
58 58
59 static struct cx_map_class_s cx_empty_map_class = { 59 static struct cx_map_class_s cx_empty_map_class = {
64 NULL, 64 NULL,
65 cx_empty_map_iterator 65 cx_empty_map_iterator
66 }; 66 };
67 67
68 CxMap cx_empty_map = { 68 CxMap cx_empty_map = {
69 NULL, 69 {
70 NULL, 70 NULL,
71 0, 71 NULL,
72 0, 72 0,
73 NULL, 73 0,
74 NULL, 74 NULL,
75 NULL, 75 NULL,
76 false, 76 NULL,
77 false
78 },
77 &cx_empty_map_class 79 &cx_empty_map_class
78 }; 80 };
79 81
80 CxMap *const cxEmptyMap = &cx_empty_map; 82 CxMap *const cxEmptyMap = &cx_empty_map;
81 83
82 // </editor-fold> 84 // </editor-fold>
83 85
84 CxMutIterator cxMapMutIteratorValues(CxMap *map) { 86 CxIterator cxMapMutIteratorValues(CxMap *map) {
85 CxIterator it = map->cl->iterator(map, CX_MAP_ITERATOR_VALUES); 87 CxIterator it = map->cl->iterator(map, CX_MAP_ITERATOR_VALUES);
86 it.base.mutating = true; 88 it.base.mutating = true;
87 89 return it;
88 // we know the iterators share the same memory layout
89 CxMutIterator iter;
90 memcpy(&iter, &it, sizeof(CxMutIterator));
91 return iter;
92 } 90 }
93 91
94 CxMutIterator cxMapMutIteratorKeys(CxMap *map) { 92 CxIterator cxMapMutIteratorKeys(CxMap *map) {
95 CxIterator it = map->cl->iterator(map, CX_MAP_ITERATOR_KEYS); 93 CxIterator it = map->cl->iterator(map, CX_MAP_ITERATOR_KEYS);
96 it.base.mutating = true; 94 it.base.mutating = true;
97 95 return it;
98 // we know the iterators share the same memory layout
99 CxMutIterator iter;
100 memcpy(&iter, &it, sizeof(CxMutIterator));
101 return iter;
102 } 96 }
103 97
104 CxMutIterator cxMapMutIterator(CxMap *map) { 98 CxIterator cxMapMutIterator(CxMap *map) {
105 CxIterator it = map->cl->iterator(map, CX_MAP_ITERATOR_PAIRS); 99 CxIterator it = map->cl->iterator(map, CX_MAP_ITERATOR_PAIRS);
106 it.base.mutating = true; 100 it.base.mutating = true;
107 101 return it;
108 // we know the iterators share the same memory layout
109 CxMutIterator iter;
110 memcpy(&iter, &it, sizeof(CxMutIterator));
111 return iter;
112 } 102 }

mercurial