diff options
Diffstat (limited to 'src/list.c')
-rw-r--r-- | src/list.c | 25 |
1 files changed, 25 insertions, 0 deletions
@@ -200,3 +200,28 @@ grecs_list_index(struct grecs_list *lp, size_t idx) | |||
200 | return ep ? ep->data : NULL; | 200 | return ep ? ep->data : NULL; |
201 | } | 201 | } |
202 | 202 | ||
203 | int | ||
204 | grecs_list_compare(struct grecs_list *a, struct grecs_list *b) | ||
205 | { | ||
206 | struct grecs_list_entry *ap, *bp; | ||
207 | int (*cmp)(const void *, const void *); | ||
208 | |||
209 | if (!a) | ||
210 | return !!b; | ||
211 | else if (!b) | ||
212 | return 1; | ||
213 | |||
214 | if (grecs_list_size(a) != grecs_list_size(b)) | ||
215 | return 1; | ||
216 | if (a->cmp != b->cmp) | ||
217 | return 1; | ||
218 | |||
219 | cmp = a->cmp ? a->cmp : _ptrcmp; | ||
220 | |||
221 | for (ap = a->head, bp = b->head; ap; ap = ap->next, bp = bp->next) | ||
222 | if (cmp (ap->data, bp->data)) | ||
223 | return 1; | ||
224 | |||
225 | return 0; | ||
226 | } | ||
227 | |||