list.h 1.38 KB
/* Double-linked list routines */

#ifndef __LIST
#define __LIST

typedef struct sElement {
	void *pContent;
	struct sElement *pNext;
	struct sElement *pPrev;
} tElement;

typedef tElement *tPosition;

typedef struct sList {
	int nCount;
	struct sElement Header;
} tList;

typedef int tVisitFunc();	/* return 1 to abort */
	/* tVisitFunc(void *pContent, void *pArgs); */

void List_Init(tList *pList);
int List_IsEmpty(tList *pList);
int List_GetCount(tList *pList);
tPosition List_AddAfter(tList *pList, tPosition pos, void *pContent);
tPosition List_AddBefore(tList *pList, tPosition pos, void *pContent);
tPosition List_AddHead(tList *pList, void *pContent);
tPosition List_AddTail(tList *pList, void *pContent);
tPosition List_GotoHead(tList *pList);
tPosition List_GotoTail(tList *pList);
void *List_GetNext(tList *pList, tPosition *ppos);
void *List_GetPrev(tList *pList, tPosition *ppos);
void *List_RemoveAt(tList *pList, tPosition pos);
void *List_RemoveHead(tList *pList);
void *List_RemoveTail(tList *pList);
tPosition List_Find(tList *pList, void *pContent);
void *List_GetAt(tList *pList, tPosition pos);
tPosition List_TraverseForward(tList *pList, tPosition pos, tVisitFunc *pVisitFunc, void *pArgs);
tPosition List_TraverseBackward(tList *pList, tPosition pos, tVisitFunc *pVisitFunc, void *pArgs);
void List_Sort(tList *pList, int (*comp)(const void *pContent1, const void *pContent2));

#endif