151 static void cx_kvl_sort(struct cx_list_s *list) { |
151 static void cx_kvl_sort(struct cx_list_s *list) { |
152 cx_kv_list *kv_list = (cx_kv_list*)list; |
152 cx_kv_list *kv_list = (cx_kv_list*)list; |
153 kv_list->list_methods->sort(list); |
153 kv_list->list_methods->sort(list); |
154 } |
154 } |
155 |
155 |
156 static int cx_kvl_compare( |
|
157 const struct cx_list_s *list, |
|
158 const struct cx_list_s *other |
|
159 ) { |
|
160 // TODO: make it so that comparison with normal linked lists is also optimized |
|
161 const cx_kv_list *kv_list = (const cx_kv_list*)list; |
|
162 return kv_list->list_methods->compare(list, other); |
|
163 } |
|
164 |
|
165 static void cx_kvl_reverse(struct cx_list_s *list) { |
156 static void cx_kvl_reverse(struct cx_list_s *list) { |
166 cx_kv_list *kv_list = (cx_kv_list*)list; |
157 cx_kv_list *kv_list = (cx_kv_list*)list; |
167 kv_list->list_methods->reverse(list); |
158 kv_list->list_methods->reverse(list); |
168 } |
159 } |
169 |
160 |
209 CxMap *map = cxHashMapCreate(allocator, CX_STORE_POINTERS, 0); |
200 CxMap *map = cxHashMapCreate(allocator, CX_STORE_POINTERS, 0); |
210 if (map == NULL) { // LCOV_EXCL_START |
201 if (map == NULL) { // LCOV_EXCL_START |
211 cxListFree(list); |
202 cxListFree(list); |
212 return NULL; |
203 return NULL; |
213 } // LCOV_EXCL_STOP |
204 } // LCOV_EXCL_STOP |
|
205 |
|
206 // patch the kv-list class with the compare function of the linked list |
|
207 // this allows cxListCompare() to optimize comparisons between linked lists and kv-list |
|
208 cx_kv_list_class.compare = list->cl->compare; |
214 |
209 |
215 // reallocate the map to add memory for the list back-reference |
210 // reallocate the map to add memory for the list back-reference |
216 struct cx_kv_list_map_s *kv_map = cxRealloc(allocator, map, sizeof(struct cx_kv_list_map_s)); |
211 struct cx_kv_list_map_s *kv_map = cxRealloc(allocator, map, sizeof(struct cx_kv_list_map_s)); |
217 |
212 |
218 // reallocate the list to add memory for storing the metadata |
213 // reallocate the list to add memory for storing the metadata |