-/* Merges lists A and B into a single list, which is returned. Cases are
- compared according to comparison function COMPARE, which receives auxiliary
- data AUX. */
-static struct case_list *
-merge (struct case_list *a, struct case_list *b,
- int (*compare) (const struct ccase *,
- const struct ccase *, void *aux),
- void *aux)
-{
- struct case_list head;
- struct case_list *tail = &head;
-
- while (a != NULL && b != NULL)
- if (compare (&a->c, &b->c, aux) < 0)
- {
- tail->next = a;
- tail = a;
- a = a->next;
- }
- else
- {
- tail->next = b;
- tail = b;
- b = b->next;
- }
-
- tail->next = a == NULL ? b : a;
-
- return head.next;
-}
-
-/* Sorts the list beginning at FIRST, returning the new first case. Cases are
- compared according to comparison function COMPARE, which receives auxiliary
- data AUX. */
-static struct case_list *
-merge_sort (struct case_list *first,
- int (*compare) (const struct ccase *,
- const struct ccase *, void *aux),
- void *aux)
-{
- /* FIXME: we should use a "natural" merge sort to take
- advantage of the natural order of the data. */
- struct case_list *middle, *last, *tmp;
-
- /* A list of zero or one elements is already sorted. */
- if (first == NULL || first->next == NULL)
- return first;
-
- middle = first;
- last = first->next;
- while (last != NULL && last->next != NULL)
- {
- middle = middle->next;
- last = last->next->next;
- }
- tmp = middle;
- middle = middle->next;
- tmp->next = NULL;
- return merge (merge_sort (first, compare, aux),
- merge_sort (middle, compare, aux),
- compare, aux);
-}
-
-/* Tries to sort casefile CF according to comparison function
- COMPARE, which is passes auxiliary data AUX. If successful,
- returns nonzero. Currently only sorting of in-memory
- casefiles is implemented. */
-int
-casefile_sort (struct casefile *cf,
- int (*compare) (const struct ccase *,
- const struct ccase *, void *aux),
- void *aux)