blob: b42a2fae1ca744f089dfd255b26a48d8de88ed07 [file] [log] [blame]
wdenkbdb4a2f2002-11-03 01:02:55 +00001#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 */
6 /* inserting. Otherwise it refers the last item in the list. */
7
8typedef struct
9 {
10 void *ptr;
11 unsigned int size;
12 } HandleRecord;
13
14typedef void **Handle;
15
16typedef int (*CompareFunction)(void *data1, void *data2) ;
17
18typedef 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
29typedef struct ListStructTag **list_t; /* The list abstract data type */
30typedef int ( * ListApplicationFunc)(int index, void *ptrToItem, void *callbackData);
31
32/* Basic List Operations */
33list_t ListCreate(int elementSize);
34int ListNumItems(list_t list);
35int ListInsertItem(list_t list, void *ptrToItem, int itemPosition);
36int ListInsertItems(list_t list, void *ptrToItems, int firstItemPosition, int numItemsToInsert);
37void ListDispose(list_t list);
38void *ListGetPtrToItem(list_t list, int itemPosition);
39void ListRemoveItem(list_t list, void *itemDestination, int itemPosition);
40void ListRemoveItems(list_t list, void *itemsDestination, int firstItemPosition, int numItemsToRemove);
41
wdenk1d0350e2002-11-11 21:14:20 +000042#if 0 /* rarely ever used; kept here for reference just in case ... */
wdenkbdb4a2f2002-11-03 01:02:55 +000043void ListDisposePtrList(list_t list);
44void ListGetItem(list_t list, void *itemDestination, int itemPosition);
45void ListReplaceItem(list_t list, void *ptrToItem, int itemPosition);
46void ListRemoveItem(list_t list, void *itemDestination, int itemPosition);
47void ListGetItems(list_t list, void *itemsDestination, int firstItemPosition, int numItemsToGet);
48void ListReplaceItems(list_t list, void *ptrToItems, int firstItemPosition, int numItemsToReplace);
49void ListRemoveItems(list_t list, void *itemsDestination, int firstItemPosition, int numItemsToRemove);
50list_t ListCopy(list_t originalList);
51int ListAppend(list_t list1, list_t list2);
52void ListClear(list_t list);
53int ListEqual(list_t list1, list_t list2);
54int ListInsertInOrder(list_t list, void *ptrToItem, CompareFunction compareFunction);
55void *ListGetDataPtr(list_t list);
56int ListApplyToEach(list_t list, int ascending, ListApplicationFunc funcToApply, void *callbackData);
57
58/* List Searching and Sorting */
59int ListFindItem(list_t list, void *ptrToItem, int startingPosition, CompareFunction compareFunction);
60void ListRemoveDuplicates(list_t list, CompareFunction compareFunction);
61int ListBinSearch(list_t list, void *itemPtr, CompareFunction compareFunction);
62void ListQuickSort(list_t list, CompareFunction compareFunction);
63void ListHeapSort(list_t list, CompareFunction compareFunction);
64void ListInsertionSort(list_t list, CompareFunction compareFunction);
65int ListIsSorted(list_t list, CompareFunction compareFunction);
66
67/* Advanced List Functions */
68void ListSetAllocationPolicy(list_t list, int minItemsPerAlloc, int percentIncreasePerAlloc);
69void ListCompact(list_t list);
70int ListPreAllocate(list_t list, int numItems);
71int ListGetItemSize(list_t list);
72int GetIntListFromParmInfo(va_list parmInfo, int numIntegers, list_t *integerList);
73int ListInsertAfterItem(list_t list, void *ptrToItem, void *ptrToItemToInsertAfter, CompareFunction compareFunction);
74int ListInsertBeforeItem(list_t list, void *ptrToItem, void *ptrToItemToInsertBefore, CompareFunction compareFunction);
wdenk1d0350e2002-11-11 21:14:20 +000075#endif /* 0 */
wdenkbdb4a2f2002-11-03 01:02:55 +000076
77#endif /* _LISTS_H_ */