Documentation
¶
Overview ¶
Package list provides an implementation of a doubly-linked list with a front and back. The individual nodes of the list are publicly exposed so that the user can have fine-grained control over the list.
Example ¶
package main import ( "fmt" "github.com/st1064870/generic/list" ) func main() { l := list.New[int]() l.PushBack(0) l.PushBack(1) l.PushBack(2) l.PushBack(3) l.Front.Each(func(i int) { fmt.Println(i) }) }
Output: 0 1 2 3
Index ¶
- type List
- func (l *List[V]) InsertAfter(n *Node[V], next *Node[V]) *Node[V]
- func (l *List[V]) InsertBefore(n *Node[V], prev *Node[V]) *Node[V]
- func (l *List[V]) PushBack(v V)
- func (l *List[V]) PushBackNode(n *Node[V])
- func (l *List[V]) PushFront(v V)
- func (l *List[V]) PushFrontNode(n *Node[V])
- func (l *List[V]) Remove(n *Node[V])
- type Node
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type List ¶
List implements a doubly-linked list.
func (*List[V]) InsertAfter ¶
InsertAfter adds 'next' into the list after 'n'. Returns the added node.
func (*List[V]) InsertBefore ¶
InsertBefore adds 'prev' into the list before 'n'. Returns the added node.
func (*List[V]) PushBack ¶
func (l *List[V]) PushBack(v V)
PushBack adds 'v' to the end of the list.
func (*List[V]) PushBackNode ¶
PushBackNode adds the node 'n' to the back of the list.
func (*List[V]) PushFront ¶
func (l *List[V]) PushFront(v V)
PushFront adds 'v' to the beginning of the list.
func (*List[V]) PushFrontNode ¶
PushFrontNode adds the node 'n' to the front of the list.
type Node ¶
Node is a node in the linked list.
func (*Node[V]) Each ¶
func (n *Node[V]) Each(fn func(val V))
Each calls 'fn' on every element from this node onward in the list.
func (*Node[V]) EachReverse ¶
func (n *Node[V]) EachReverse(fn func(val V))
EachReverse calls 'fn' on every element from this node backward in the list.
func (*Node[V]) EachReverseNode ¶
EachReverseNode calls 'fn' on every node from this node backward in the list.