acnlists.h

Generic handling for single and double linked lists.

Summary
acnlists.hGeneric handling for single and double linked lists.
Macros
Single linked listsEach list member structure contains one pointer lnk.r pointing to its right neighbour.
Single linked lists with pointer to tailEach list member structure contains one pointer lnk.r pointing to its right neighbour.
Double linked listsEach list member structure contains two pointers lnk.r and lnk.l pointing to its right and left neighbours.

Macros

Single linked lists

Each list member structure contains one pointer lnk.r pointing to its right neighbour.  The last item in the list has a NULL pointer.  The head of list pointer used to reach the list identifes the head item and the list progresses to the right.

A pointer to any list member can be used as an insertion point for new items.  The macro slInsertR() adds an item immediately to the right of this member and evaluates as a pointer to the new member.

To unlink an item is expensive if the list is long and requires a temporary pointer - the type parameter is the type of the linked structure e.g.  “struct mylinkedstruct”

slLinkdeclare a link structure
slInsertRinsert an object after itemp
slAddHeadinsert an object at the head of the list
slUnlinkunlink an object

Single linked lists with pointer to tail

Each list member structure contains one pointer lnk.r pointing to its right neighbour.  The last item in the list has a NULL pointer.  The head of list pointer used to reach the list identifes the head item and the list progresses to the right.  A tail pointer identifies the last item.

A pointer to any list member can be used as an insertion point for new items.  The macro slInsertR() adds an item immediately to the right of this member and evaluates as a pointer to the new member.

To unlink an item is expensive if the list is long and requires a temporary pointer - the type parameter is the type of the linked structure e.g.  “struct mylinkedstruct”

stlLinkdeclare a link structure
stlInsertRinsert an object after itemp
stlAddHeadinsert an object at the head of the list
stlAddTailinsert an object at the tail of the list
stlUnlinkunlink an object

Double linked lists

Each list member structure contains two pointers lnk.r and lnk.l pointing to its right and left neighbours.  These pointers form a ring so that the tail of the list joins to the head.  The head of list pointer used to reach the list identifes the head item and the list progresses to the right, so the tail item is the left neighbour of the head (the head/tail break comes between the head item and its left neighbour.

A pointer to any list member can be used as a handle on the list and defines an insertion point for new items.  The macros dlInsertL() and dlInsertR() add an item immediately to the left or right of this member and evaluate as a pointer to the new member.

dlLinkdeclare a link structure
dlInsertRinsert an object to the right of itemp
dlInsertLinsert an object to the left of itemp
dlAddHeadinsert an object at the head of the list
dlAddTailinsert an object at the tail of the list
dlUnlinkunlink an object
Close