73778ee7fce3f02ee6d72bf47a4e478e863e2bd6 tdreszer Tue Feb 5 17:22:54 2013 -0800 Added slSortMerge and slSortMergeUniq at Angie's request. These functions are little more than wrappers for slSort and slUniqify but are still valuable additions. diff --git src/lib/common.c src/lib/common.c index b0dd20f..503ccbc 100644 --- src/lib/common.c +++ src/lib/common.c @@ -351,30 +351,48 @@ struct slList *oldList = *pSlList; struct slList *newList = NULL, *el; slSort(&oldList, compare); while ((el = slPopHead(&oldList)) != NULL) { if ((newList == NULL) || (compare(&newList, &el) != 0)) slAddHead(&newList, el); else if (free != NULL) free(el); } slReverse(&newList); *pSlList = newList; } +void slSortMerge(void *pA, void *b, CmpFunction *compare) +// Merges and sorts a pair of singly linked lists using slSort. +{ +struct slList **pList = (struct slList **)pA; +slCat(*pList, b); +slSort(pList,compare); +} + +void slSortMergeUniq(void *pA, void *b, CmpFunction *compare, void (*free)()) +// Merges and sorts a pair of singly linked lists leaving only unique +// items via slUniqufy. duplicate itens are defined by the compare routine +// returning 0. If free is provided, items dropped from list can disposed of. +{ +struct slList **pList = (struct slList **)pA; +slCat(*pList, b); +slUniqify(pList,compare,free); +} + boolean slRemoveEl(void *vpList, void *vToRemove) /* Remove element from doubly linked list. Usage: * slRemove(&list, el); * Returns TRUE if element in list. */ { struct slList **pList = vpList; struct slList *toRemove = vToRemove; struct slList *el, *next, *newList = NULL; boolean didRemove = FALSE; for (el = *pList; el != NULL; el = next) { next = el->next; if (el != toRemove) {