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 */
6 /* inserting. Otherwise it refers the last item in the list. */
14 typedef void **Handle
;
16 typedef int (*CompareFunction
)(void *data1
, void *data2
) ;
18 typedef struct ListStructTag
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 */
29 typedef struct ListStructTag
**list_t
; /* The list abstract data type */
30 typedef int ( * ListApplicationFunc
)(int index
, void *ptrToItem
, void *callbackData
);
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
);
42 #if 0 /* rarely ever used; kept here for reference just in case ... */
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
);
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
);
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
);
77 #endif /* _LISTS_H_ */