Documentation ¶
Overview ¶
Package list provides an intrusive circular double linked list. The most useful property is that a list node can remove itself from any list without having a reference to one. This is useful to implement certain algorithms such as timers or priority queues where the list a list node is stored in may be unknown.
Illustration of element nodes forming a circular list. One of the elements is dedicated to the role of list head and does not carry any valid data.
+------------------------------------+ | | +--> +----+ --> +----+ --> +----+ -->+ |Elem| |Elem| |Elem| +<-- +----+ <-- +----+ <-- +----+ <--+ | | +------------------------------------+
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Node ¶
type Node[T any] struct { Value T // Value carried by the node that may be accessed directly. // contains filtered or unexported fields }
Node is a list node carrying a value of type T. A sentinel node is used to represent the list head. The zero value is not a valid node as its prev and next pointers must be initialized.
func (*Node[T]) InitLinks ¶
InitLinks initializes a node so that list operations may be performed on it. This method should be used to initialize list nodes for which the user manages memory. It should not be used when New was used to allocate a node
func (*Node[T]) IsLinked ¶
IsLinked reports whether node is linked to another node. The method reports if a list is non-empty when applied to a list head node.
func (*Node[T]) Next ¶
Next returns the node next to node. This may be node itself if unlinked and pointing to itself.