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 CxIterator left = cxListBegin(list); |
|
66 CxIterator right = cxListBegin(other); |
|
67 for (size_t i = 0; i < list->size; i++) { |
|
68 void *leftValue = cxIteratorCurrent(left); |
|
69 void *rightValue = cxIteratorCurrent(right); |
|
70 int d = list->cmpfunc(leftValue, rightValue); |
|
71 if (d != 0) { |
|
72 return d; |
|
73 } |
|
74 cxIteratorNext(left); |
|
75 cxIteratorNext(right); |
|
76 } |
|
77 return 0; |
|
78 } else { |
|
79 return list->size < other->size ? -1 : 1; |
|
80 } |
|
81 } |
|
82 } |