Double Linked List.
More...
Double Linked List.
In my crazed days, I decided that having a double link list 'class' would be useful and I would no longer have to write this code over and over. Amulets & Armor uses this code for all double linked lists. This version has been optimized to not use malloc and free per node pointer structure.
- See Also
- http://www.amuletsandarmor.com/AALicense.txt
#define DOUBLE_LINK_LIST_DEAD_TAG (*((T_word32 *)"DdBl")) |
#define DOUBLE_LINK_LIST_TAG (*((T_word32 *)"DbLi")) |
#define MAX_ALLOCATED_NODES 30000 |
DoubleLinkListAddElementAfterElement adds a new element after another element in a link list.
- Parameters
-
element | – handle of element to go after |
p_data | – Pointer to element data |
DoubleLinkListAddElementAtEnd appends a new element at the end of the link list.
- Parameters
-
linkList | – Handle to link list to append item |
p_data | – Pointer to element data |
DoubleLinkListAddElementAtFront adds a new element at the front of the link list.
- Parameters
-
linkList | – Handle to link list to insert item |
p_data | – Pointer to element data |
DoubleLinkListAddElementBeforeElement adds a new element before another element in a link list.
- Parameters
-
element | – handle of element to go before |
p_data | – Pointer to element data |
DoubleLinkListDestroy goes through a list of double link list nodes and detaches the data with them and then deletes all the nodes.
NOTE: The calling routine must realize that this routine does not deallocate memory attached to a node, it is assumed that the calling routine will do this.
- Parameters
-
linkList | – Handle to link list to destroy |
DoubleLinkListElementGetData pulls out the data pointer from a double link list element.
- Parameters
-
element | – Element to get data out of |
- Returns
- Found data pointer on element
DoubleLinkListElementGetData pulls out the next element from a double link list element.
- Parameters
-
element | – Element to get next element |
- Returns
- Next element
DoubleLinkListElementGetPrevious pulls out the previous element from a double link list element.
- Parameters
-
element | – Element to get previous element |
- Returns
- Previous element
DoubleLinkListFreeAndDestroy goes through a linked list and does a MemFree on each of the data elements and then calls Destroy on the whole list.
- Parameters
-
linkList | – Handle to link list to destroy |
DoubleLinkListGetFirst returns the first element in a double link list.
- Parameters
-
linkList | – List to get first |
- Returns
- First element, or DOUBLE_LINK_LIST_ELEMENT_BAD if none.
DoubleLinkListGetLast returns the last element in a double link list.
- Parameters
-
linkList | – List to get last element |
- Returns
- Last element, or DOUBLE_LINK_LIST_ELEMENT_BAD if none.
DoubleLinkListGetNumberElements returns the number of elements in the given link list.
- Parameters
-
linkList | – Link list to get count of |
- Returns
- Number of elements
DoubleLinkListRemoveElement removes an element from a link list. This routine also returns the data that was attached to this element.
- Parameters
-
element | – removes the element from the list. |
- Returns
- Previously attached node data
DoubleLinkListTraverse travels along the link list and calls the given callback for each of the nodes. In addition, the callback has the choice of aborting the routine. If the traversal stops early that element's handle is returned, else DOUBLE_LINK_LIST_ELEMENT_BAD is returned.
- Parameters
-
linkList | – List to traverse |
callback | – callback to call on each element, returns FALSE to stop traversing. |
- Returns
- Element that traverse stopped on, or DOUBLE_LINK_LIST_ELEMENT_NONE if completed list.
DoubleLinkListCreate creates a new double link list and sets up the list to receive new nodes.
- Returns
- Created double link list.