1 #ifndef OSRF_BIG_LIST_H
2 #define OSRF_BIG_LIST_H
6 #include <opensrf/utils.h>
10 Items are stored as void*'s so it's up to the user to
11 manage the data wisely. Also, if the 'freeItem' callback is defined for the list,
12 then, it will be used on any item that needs to be freed, so don't mix data
13 types in the list if you want magic freeing */
15 struct __osrfBigListStruct {
16 Pvoid_t list; /* the list */
17 int size; /* how many items in the list including NULL items between non-NULL items */
18 void (*freeItem) (void* item); /* callback for freeing stored items */
20 typedef struct __osrfBigListStruct osrfBigList;
23 struct __osrfBigBigListIteratorStruct {
25 unsigned long current;
27 typedef struct __osrfBigBigListIteratorStruct osrfBigBigListIterator;
31 Creates a new list iterator with the given list
33 osrfBigBigListIterator* osrfNewBigListIterator( osrfBigList* list );
36 Returns the next non-NULL item in the list, return NULL when
37 the end of the list has been reached
39 void* osrfBigBigListIteratorNext( osrfBigBigListIterator* itr );
42 Deallocates the given list
44 void osrfBigBigListIteratorFree( osrfBigBigListIterator* itr );
46 void osrfBigBigListIteratorReset( osrfBigBigListIterator* itr );
51 @param compress If true, the list will compress empty slots on delete. If item positionality
52 is not important, then using this feature is reccomended to keep the list from growing indefinitely.
53 if item positionality is not important.
54 @return The allocated list
56 osrfBigList* osrfNewBigList();
59 Pushes an item onto the end of the list. This always finds the highest index
60 in the list and pushes the new item into the list after it.
62 @param item The item to push
63 @return 0 on success, -1 on failure
65 int osrfBigListPush( osrfBigList* list, void* item );
69 * Removes the last item in the list
70 * See osrfBigListRemove for details on how the removed item is handled
71 * @return The item, unless 'freeItem' exists, then returns NULL
73 void* osrfBigListPop( osrfBigList* list );
76 Puts the given item into the list at the specified position. If there
77 is already an item at the given position and the list has it's
78 "freeItem" function defined, then it will be used to free said item.
79 If no 'freeItem' callback is defined, then the displaced item will
82 @param item The item to put into the list
83 @param position The position to place the item in
84 @return NULL in successfully inserting the new item and freeing
85 any displaced items. Returns the displaced item if no "freeItem"
88 void* osrfBigListSet( osrfBigList* list, void* item, unsigned long position );
91 Returns the item at the given position
93 @param postiont the position
95 void* osrfBigListGetIndex( osrfBigList* list, unsigned long position );
98 Frees the list and all list items (if the list has a "freeItem" function defined )
101 void osrfBigListFree( osrfBigList* list );
104 Removes the list item at the given index
106 @param position The position of the item to remove
107 @return A pointer to the item removed if "freeItem" is not defined
108 for this list, returns NULL if it is.
110 void* osrfBigListRemove( osrfBigList* list, int position );
113 Finds the list item whose void* is the same as the one passed in
115 @param addr The pointer connected to the list item we're to find
116 @return the index of the item, or -1 if the item was not found
118 int osrfBigListFind( osrfBigList* list, void* addr );
121 void __osrfBigListSetSize( osrfBigList* list );
125 @return The number of non-null items in the list
127 unsigned long osrfBigListGetCount( osrfBigList* list );
130 * May be used as a default memory freeing call
131 * Just calls free() on list items
133 void osrfBigListVanillaFree( void* item );
136 * Tells the list to just call 'free()' on each item when
137 * an item or the whole list is destroyed
139 void osrfBigListSetDefaultFree( osrfBigList* list );