compare_vecs | copy_vec | merge_sort | merge_sort_recurse |
Ordertype compare_vecs(int *a, int *b, int n);
void copy_vec(int *a, int *b, int n);
void merge_sort(void *a[], /* array to sort */ int n, /* size of array */ Ordertype (*comp_proc) (void *, void *));This is a general-purpose sorting routine. You give it an array of pointers to sort, the size of the array, and a comparison function.
Here is an example of how to use it.
{ Term args[MAX_ACM_ARGS]; int n; < set n and put the n terms you wish to sort into args[] > merge_sort((void **) args, n, (Ordertype (*)(void*,void*)) term_compare_ncv); < args[] is now ordered by term_compare_ncv() > }
void merge_sort_recurse(void *a[], /* array to sort */ void *w[], /* work array */ int start, /* index of first element */ int end, /* index of last element */ Ordertype (*comp_proc) (void *, void *));This is the recursive part of a general-purpose merge sort. You won't ordinarily call this (use merge_sort instead). Use this only if you manage allocation of the work array.
Here is an example of how to use it.
{ Term args[MAX_ACM_ARGS], work[MAX_ACM_ARGS]; int n; < put the n terms you wish to sort into args[] > merge_sort_recurse((void **) args, (void **) work, 0, n-1, (Ordertype (*)(void*,void*)) term_compare_ncv); < args[] is now ordered by term_compare_ncv() > }
/* basic order relations */ typedef enum { NOT_COMPARABLE, SAME_AS, LESS_THAN, GREATER_THAN, LESS_THAN_OR_SAME_AS, GREATER_THAN_OR_SAME_AS, NOT_LESS_THAN, NOT_GREATER_THAN } Ordertype;