wdenk | bdb4a2f | 2002-11-03 01:02:55 +0000 | [diff] [blame] | 1 | #ifndef _LISTS_H_ |
| 2 | #define _LISTS_H_ |
| 3 | |
| 4 | #define LIST_START -1 /* Handy Constants that substitute for item positions */ |
| 5 | #define LIST_END 0 /* END_OF_LIST means one past current length of list when */ |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 6 | /* inserting. Otherwise it refers the last item in the list. */ |
wdenk | bdb4a2f | 2002-11-03 01:02:55 +0000 | [diff] [blame] | 7 | |
| 8 | typedef struct |
| 9 | { |
| 10 | void *ptr; |
| 11 | unsigned int size; |
| 12 | } HandleRecord; |
| 13 | |
| 14 | typedef void **Handle; |
| 15 | |
| 16 | typedef int (*CompareFunction)(void *data1, void *data2) ; |
| 17 | |
| 18 | typedef struct ListStructTag |
| 19 | { |
| 20 | int signature; /* debugging aid */ |
| 21 | int percentIncrease; /* %of current size to increase by when list is out of space */ |
| 22 | int minNumItemsIncrease; /* fixed number of items to increase by when list is out of space */ |
| 23 | int listSize; /* number of items than can fit in the currently allocated memory */ |
| 24 | int itemSize; /* the size of each item in the list (same for every item) */ |
| 25 | int numItems; /* number of items currently in the list */ |
| 26 | unsigned char itemList[1]; /* resizable array of list elements */ |
| 27 | } ListStruct; |
| 28 | |
| 29 | typedef struct ListStructTag **list_t; /* The list abstract data type */ |
| 30 | typedef int ( * ListApplicationFunc)(int index, void *ptrToItem, void *callbackData); |
| 31 | |
| 32 | /* Basic List Operations */ |
| 33 | list_t ListCreate(int elementSize); |
| 34 | int ListNumItems(list_t list); |
| 35 | int ListInsertItem(list_t list, void *ptrToItem, int itemPosition); |
| 36 | int ListInsertItems(list_t list, void *ptrToItems, int firstItemPosition, int numItemsToInsert); |
| 37 | void ListDispose(list_t list); |
| 38 | void *ListGetPtrToItem(list_t list, int itemPosition); |
| 39 | void ListRemoveItem(list_t list, void *itemDestination, int itemPosition); |
| 40 | void ListRemoveItems(list_t list, void *itemsDestination, int firstItemPosition, int numItemsToRemove); |
| 41 | |
wdenk | 1d0350e | 2002-11-11 21:14:20 +0000 | [diff] [blame] | 42 | #if 0 /* rarely ever used; kept here for reference just in case ... */ |
wdenk | bdb4a2f | 2002-11-03 01:02:55 +0000 | [diff] [blame] | 43 | void ListDisposePtrList(list_t list); |
| 44 | void ListGetItem(list_t list, void *itemDestination, int itemPosition); |
| 45 | void ListReplaceItem(list_t list, void *ptrToItem, int itemPosition); |
| 46 | void ListRemoveItem(list_t list, void *itemDestination, int itemPosition); |
| 47 | void ListGetItems(list_t list, void *itemsDestination, int firstItemPosition, int numItemsToGet); |
| 48 | void ListReplaceItems(list_t list, void *ptrToItems, int firstItemPosition, int numItemsToReplace); |
| 49 | void ListRemoveItems(list_t list, void *itemsDestination, int firstItemPosition, int numItemsToRemove); |
| 50 | list_t ListCopy(list_t originalList); |
| 51 | int ListAppend(list_t list1, list_t list2); |
| 52 | void ListClear(list_t list); |
| 53 | int ListEqual(list_t list1, list_t list2); |
| 54 | int ListInsertInOrder(list_t list, void *ptrToItem, CompareFunction compareFunction); |
| 55 | void *ListGetDataPtr(list_t list); |
| 56 | int ListApplyToEach(list_t list, int ascending, ListApplicationFunc funcToApply, void *callbackData); |
| 57 | |
| 58 | /* List Searching and Sorting */ |
| 59 | int ListFindItem(list_t list, void *ptrToItem, int startingPosition, CompareFunction compareFunction); |
| 60 | void ListRemoveDuplicates(list_t list, CompareFunction compareFunction); |
| 61 | int ListBinSearch(list_t list, void *itemPtr, CompareFunction compareFunction); |
| 62 | void ListQuickSort(list_t list, CompareFunction compareFunction); |
| 63 | void ListHeapSort(list_t list, CompareFunction compareFunction); |
| 64 | void ListInsertionSort(list_t list, CompareFunction compareFunction); |
| 65 | int ListIsSorted(list_t list, CompareFunction compareFunction); |
| 66 | |
| 67 | /* Advanced List Functions */ |
| 68 | void ListSetAllocationPolicy(list_t list, int minItemsPerAlloc, int percentIncreasePerAlloc); |
| 69 | void ListCompact(list_t list); |
| 70 | int ListPreAllocate(list_t list, int numItems); |
| 71 | int ListGetItemSize(list_t list); |
| 72 | int GetIntListFromParmInfo(va_list parmInfo, int numIntegers, list_t *integerList); |
| 73 | int ListInsertAfterItem(list_t list, void *ptrToItem, void *ptrToItemToInsertAfter, CompareFunction compareFunction); |
| 74 | int ListInsertBeforeItem(list_t list, void *ptrToItem, void *ptrToItemToInsertBefore, CompareFunction compareFunction); |
wdenk | 1d0350e | 2002-11-11 21:14:20 +0000 | [diff] [blame] | 75 | #endif /* 0 */ |
wdenk | bdb4a2f | 2002-11-03 01:02:55 +0000 | [diff] [blame] | 76 | |
| 77 | #endif /* _LISTS_H_ */ |