src/map.c

changeset 709
1e8ba59e7911
parent 706
8c6edaccaef1
equal deleted inserted replaced
708:1caed6c9ba68 709:1e8ba59e7911
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE. 26 * POSSIBILITY OF SUCH DAMAGE.
27 */ 27 */
28 28
29 #include "cx/map.h" 29 #include "cx/map.h"
30 #include <string.h>
30 31
31 // <editor-fold desc="empty map implementation"> 32 // <editor-fold desc="empty map implementation">
32 33
33 static void cx_empty_map_noop(__attribute__((__unused__)) CxMap *map) { 34 static void cx_empty_map_noop(__attribute__((__unused__)) CxMap *map) {
34 // this is a noop, but MUST be implemented 35 // this is a noop, but MUST be implemented
43 44
44 static bool cx_empty_map_iter_valid(__attribute__((__unused__)) void const *iter) { 45 static bool cx_empty_map_iter_valid(__attribute__((__unused__)) void const *iter) {
45 return false; 46 return false;
46 } 47 }
47 48
48 static CxIterator cx_empty_map_iterator(struct cx_map_s const *map) { 49 static CxIterator cx_empty_map_iterator(
50 struct cx_map_s const *map,
51 __attribute__((__unused__)) enum cx_map_iterator_type type
52 ) {
49 CxIterator iter = {0}; 53 CxIterator iter = {0};
50 iter.src_handle = map; 54 iter.src_handle = map;
51 iter.base.valid = cx_empty_map_iter_valid; 55 iter.base.valid = cx_empty_map_iter_valid;
52 return iter; 56 return iter;
53 } 57 }
54 58
55 static CxMutIterator cx_empty_map_miterator(struct cx_map_s *map) {
56 CxMutIterator iter = {0};
57 iter.src_handle = map;
58 iter.base.valid = cx_empty_map_iter_valid;
59 return iter;
60 }
61
62 static struct cx_map_class_s cx_empty_map_class = { 59 static struct cx_map_class_s cx_empty_map_class = {
63 cx_empty_map_noop, 60 cx_empty_map_noop,
64 cx_empty_map_noop, 61 cx_empty_map_noop,
65 NULL, 62 NULL,
66 cx_empty_map_get, 63 cx_empty_map_get,
67 NULL, 64 NULL,
68 cx_empty_map_iterator, 65 cx_empty_map_iterator
69 cx_empty_map_iterator,
70 cx_empty_map_iterator,
71 cx_empty_map_miterator,
72 cx_empty_map_miterator,
73 cx_empty_map_miterator,
74 }; 66 };
75 67
76 CxMap cx_empty_map = { 68 CxMap cx_empty_map = {
77 NULL, 69 NULL,
78 NULL, 70 NULL,
83 NULL, 75 NULL,
84 false, 76 false,
85 &cx_empty_map_class 77 &cx_empty_map_class
86 }; 78 };
87 79
88 CxMap * const cxEmptyMap = &cx_empty_map; 80 CxMap *const cxEmptyMap = &cx_empty_map;
89 81
90 // </editor-fold> 82 // </editor-fold>
83
84 CxMutIterator cxMapMutIteratorValues(CxMap *map) {
85 CxIterator it = map->cl->iterator(map, CX_MAP_ITERATOR_VALUES);
86 it.base.mutating = true;
87
88 // we know the iterators share the same memory layout
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 // we know the iterators share the same memory layout
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 // we know the iterators share the same memory layout
109 CxMutIterator iter;
110 memcpy(&iter, &it, sizeof(CxMutIterator));
111 return iter;
112 }

mercurial