109 struct cx_list_s *list, |
109 struct cx_list_s *list, |
110 size_t index, |
110 size_t index, |
111 const void *data |
111 const void *data |
112 ) { |
112 ) { |
113 cx_kv_list *kv_list = (cx_kv_list*)list; |
113 cx_kv_list *kv_list = (cx_kv_list*)list; |
114 // TODO: trick the base method by adding the required space for the key to the elem_size |
|
115 return kv_list->list_methods->insert_element(list, index, data); |
114 return kv_list->list_methods->insert_element(list, index, data); |
116 } |
115 } |
117 |
116 |
118 static size_t cx_kvl_insert_array( |
117 static size_t cx_kvl_insert_array( |
119 struct cx_list_s *list, |
118 struct cx_list_s *list, |
120 size_t index, |
119 size_t index, |
121 const void *data, |
120 const void *data, |
122 size_t n |
121 size_t n |
123 ) { |
122 ) { |
124 cx_kv_list *kv_list = (cx_kv_list*)list; |
123 cx_kv_list *kv_list = (cx_kv_list*)list; |
125 // TODO: trick the base method by adding the required space for the key to the elem_size |
|
126 return kv_list->list_methods->insert_array(list, index, data, n); |
124 return kv_list->list_methods->insert_array(list, index, data, n); |
127 } |
125 } |
128 |
126 |
129 static size_t cx_kvl_insert_sorted( |
127 static size_t cx_kvl_insert_sorted( |
130 struct cx_list_s *list, |
128 struct cx_list_s *list, |
131 const void *sorted_data, |
129 const void *sorted_data, |
132 size_t n |
130 size_t n |
133 ) { |
131 ) { |
134 cx_kv_list *kv_list = (cx_kv_list*)list; |
132 cx_kv_list *kv_list = (cx_kv_list*)list; |
135 // TODO: trick the base method by adding the required space for the key to the elem_size |
|
136 return kv_list->list_methods->insert_sorted(list, sorted_data, n); |
133 return kv_list->list_methods->insert_sorted(list, sorted_data, n); |
137 } |
134 } |
138 |
135 |
139 static int cx_kvl_insert_iter( |
136 static int cx_kvl_insert_iter( |
140 struct cx_iterator_s *iter, |
137 struct cx_iterator_s *iter, |
141 const void *elem, |
138 const void *elem, |
142 int prepend |
139 int prepend |
143 ) { |
140 ) { |
144 cx_kv_list *kv_list = iter->src_handle.m; |
141 cx_kv_list *kv_list = iter->src_handle.m; |
145 // TODO: trick the base method by adding the required space for the key to the elem_size |
|
146 return kv_list->list_methods->insert_iter(iter, elem, prepend); |
142 return kv_list->list_methods->insert_iter(iter, elem, prepend); |
147 } |
143 } |
148 |
144 |
149 static size_t cx_kvl_remove( |
145 static size_t cx_kvl_remove( |
150 struct cx_list_s *list, |
146 struct cx_list_s *list, |
234 |
230 |
235 static void *cx_kvl_map_put(CxMap *map, CxHashKey key, void *value) { |
231 static void *cx_kvl_map_put(CxMap *map, CxHashKey key, void *value) { |
236 cx_kv_list *kv_list = ((struct cx_kv_list_map_s*)map)->list; |
232 cx_kv_list *kv_list = ((struct cx_kv_list_map_s*)map)->list; |
237 // insert the data into the list first (assume that insertion destroys the sorted property) |
233 // insert the data into the list first (assume that insertion destroys the sorted property) |
238 kv_list->list.base.collection.sorted = false; |
234 kv_list->list.base.collection.sorted = false; |
239 // TODO: use the same trick as above to increase the element size temporarily to add the key to the data |
|
240 void *node_data = kv_list->list_methods->insert_element( |
235 void *node_data = kv_list->list_methods->insert_element( |
241 &kv_list->list.base, kv_list->list.base.collection.size, |
236 &kv_list->list.base, kv_list->list.base.collection.size, |
242 kv_list->list.base.collection.store_pointer ? &value : value); |
237 kv_list->list.base.collection.store_pointer ? &value : value); |
243 if (node_data == NULL) return NULL; // LCOV_EXCL_LINE |
238 if (node_data == NULL) return NULL; // LCOV_EXCL_LINE |
244 // then insert the key into the map, referring to the node data |
239 // then insert the key into the map, referring to the node data |