20 if ((list = (
LIST*) malloc(
sizeof(
LIST)))==NULL) {
21 Serror(
"Failed to create list structure\n");
44 Swarning(
"NULL pointer given for new list item data\n");
120 Serror(
"Null pointer given to GetNextItem()\n");
131 Serror(
"Null pointer given to GetPrevItem()\n");
144 if ((dst =
ListItem(ptr, free_obj))==NULL) {
160 Serror(
"Not implemented\n");
171 Serror(
"Failed to allocate new listitem\n");
185 Serror(
"Null value for LISTITEM\n");
211 if (prev->
next != ptr) {
212 Swarning(
"prev->next Sanity check failed on list\n");
216 assert (list->
tail == ptr);
218 if (list->
curr == ptr) {
225 if (next->
prev != ptr) {
226 Swarning(
"next->prev Sanity check failed on list\n");
230 assert (list->
head == ptr);
232 if (list->
curr == ptr) {
238 if ((next==NULL)&&(prev==NULL)) {
256 if (list->
head==NULL) {
266 if (list->
head==NULL) {
268 Swarning(
"List seems empty (%d items remaining?)",list->
n);
273 if (list->
head==NULL) {
274 Serror (
"List already empty\n");
282 Serror(
"Counter at %d, yet least not empty?\n",list->
n);
301 Serror(
"List still has a head after clearing\n");
304 Serror(
"List still points somewhere after clearing\n");
307 Serror(
"List still has a tail after clearing\n");
310 Serror(
"List size not zero after clearing\n");
330 if (item->
obj == ptr) {
353 for (
int i=0; i<n; i++) {
struct ListItem * next
next item
int RemoveListItem(LIST *list, LISTITEM *ptr)
LISTITEM * ListLinearSearchRetrieve(struct List *list, void *ptr)
LISTITEM * FindItem(LIST *list, void *ptr)
Finds the LISTITEM pointer corresponding to the data.
LISTITEM *(* retrieve)(struct List *list, void *ptr)
Method by which to search objects.
int ClearList(LIST *list)
Clear the list.
LISTITEM * ListAppend(LIST *list, void *p)
Append an item to the list.
LISTITEM * GetNextItem(LISTITEM *ptr)
LISTITEM * ListItem(void *ptr, void(*free_obj)(void *obj))
int FreeListItem(LIST *list, LISTITEM *ptr)
LISTITEM * LinkNext(LISTITEM *src, void *ptr, void(*free_obj)(void *obj))
LISTITEM * LastListItem(LIST *list)
Move to the last list item.
void(* free_obj)(void *obj)
free hook
LISTITEM * LinkPrev(LISTITEM *src, void *ptr, void(*free_obj)(void *obj))
LIST * List(void)
Create a new list.
LISTITEM * curr
current item
LISTITEM * FirstListItem(LIST *list)
Move to the first list item.
struct ListItem * prev
previous item
int PopItem(LIST *list)
Remove the topmost item of the list (also frees obj memory)
LISTITEM * NextListItem(LIST *list)
Advance one item.
A very simple list structure.
LISTITEM * GetPrevItem(LISTITEM *ptr)
int ListSize(LIST *list)
Get the size of the list.
LISTITEM * GetItem(LIST *list, int n)
Get the nth item of the list.