-
Notifications
You must be signed in to change notification settings - Fork 0
Home
Go package: s2list.
Imports package elist.
Dr. Alan U. Kennington.
The s2list package implements singly-linked lists of nodes which have parent-pointers to the containing list. This helps to ensure integrity, for example by preventing a node from being an element of the same list twice, or an element of two different lists simultaneously.
A List_node is an element of a List_base. Every List_node has a base-pointer which is nil if the node is not in a list, or points to the List_base if it is within that list. When a List_node is removed from a list, the base-pointer is set to nil.
next *List_node // Next node in a singly linked list. base *List_base // The base in which this object is listed. value interface{} // The payload of the list node.
List_base is a singly-linked list implementation which has pointers to both the head and tail elements of the list.
first *List_node // First node of the list. last *List_node // Last node of the list.
Every node in the list has a base-pointer which points to the list-base which it is contained in, or which equals nil if the node is not contained in a list. Various checks are made by List_base methods to prevent corruption of the list structure, but to further protect the integrity of these lists, it is best to not re-export list bases or list nodes to other packages.
List_iter is used for traversals of the nodes in a List_base.
base *List_base // The list which is used for the iteration. current *List_node // The last node delivered by the iterator.
List_base lists can also be traversed using the List_base::GetFirst() and List_node::GetNext() functions. However, the List_iter::Next() function performs integrity checks to ensure valid results. (For example, a node could be moved from one list to another between List_node::GetNext() calls, which would result in the traversal continuing from the original list to a different list!)