src/list.c

changeset 618
1f5a8f6f3015
parent 528
4fbfac557df8
child 628
1e2be40f0cb5
equal deleted inserted replaced
617:cec11387c1be 618:1f5a8f6f3015
49 } 49 }
50 50
51 list->cl->destructor(list); 51 list->cl->destructor(list);
52 cxFree(list->allocator, list); 52 cxFree(list->allocator, list);
53 } 53 }
54
55 int cxListCompare(
56 CxList const *list,
57 CxList const *other
58 ) {
59 if (list->cl->compare == other->cl->compare) {
60 /* same compare function, lists are compatible */
61 return list->cl->compare(list, other);
62 } else {
63 /* different compare functions, use iterator */
64 if (list->size == other->size) {
65 // TODO: we would need a const iterator
66 CxIterator left = cxListBegin(list);
67 CxIterator right = cxListBegin(other);
68 for (size_t i = 0; i < list->size; i++) {
69 void *leftValue = cxIteratorCurrent(&left);
70 void *rightValue = cxIteratorCurrent(&right);
71 int d = list->cmpfunc(leftValue, rightValue);
72 if (d != 0) {
73 return d;
74 }
75 cxIteratorNext(&left);
76 cxIteratorNext(&right);
77 }
78 return 0;
79 } else {
80 return list->size < other->size ? -1 : 1;
81 }
82 }
83 }

mercurial