src/list.c

changeset 680
19379743e5a0
parent 677
b09aae58bba4
child 699
35b2b99ee523
equal deleted inserted replaced
679:022fbd4bc057 680:19379743e5a0
217 217
218 int cxListCompare( 218 int cxListCompare(
219 CxList const *list, 219 CxList const *list,
220 CxList const *other 220 CxList const *other
221 ) { 221 ) {
222 if (list->cl->compare == other->cl->compare) { 222 if ((list->store_pointer ^ other->store_pointer) ||
223 // same compare function, lists are compatible 223 ((list->climpl == NULL) ^ (other->climpl != NULL)) ||
224 return list->cl->compare(list, other); 224 ((list->climpl != NULL ? list->climpl->compare : list->cl->compare) !=
225 } else { 225 (other->climpl != NULL ? other->climpl->compare : other->cl->compare))) {
226 // different compare functions, use iterator 226 // lists are definitely different - cannot use internal compare function
227 if (list->size == other->size) { 227 if (list->size == other->size) {
228 CxIterator left = cxListIterator(list); 228 CxIterator left = cxListIterator(list);
229 CxIterator right = cxListIterator(other); 229 CxIterator right = cxListIterator(other);
230 for (size_t i = 0; i < list->size; i++) { 230 for (size_t i = 0; i < list->size; i++) {
231 void *leftValue = cxIteratorCurrent(left); 231 void *leftValue = cxIteratorCurrent(left);
239 } 239 }
240 return 0; 240 return 0;
241 } else { 241 } else {
242 return list->size < other->size ? -1 : 1; 242 return list->size < other->size ? -1 : 1;
243 } 243 }
244 } else {
245 // lists are compatible
246 return list->cl->compare(list, other);
244 } 247 }
245 } 248 }
246 249
247 CxMutIterator cxListMutIteratorAt( 250 CxMutIterator cxListMutIteratorAt(
248 CxList *list, 251 CxList *list,

mercurial