Documentation ¶
Overview ¶
Package list implements a doubly linked list.
To iterate over a list (where l is a *List[T]):
for e := l.Front(); e != nil; e = e.Next() { // do something with e.Value }
Index ¶
- type Element
- type List
- func (l *List[T]) Back() *Element[T]
- func (l *List[T]) Front() *Element[T]
- func (l *List[T]) Init() *List[T]
- func (l *List[T]) InsertAfter(v T, mark *Element[T]) *Element[T]
- func (l *List[T]) InsertBefore(v T, mark *Element[T]) *Element[T]
- func (l *List[T]) Len() int
- func (l *List[T]) MoveAfter(e, mark *Element[T])
- func (l *List[T]) MoveBefore(e, mark *Element[T])
- func (l *List[T]) MoveToBack(e *Element[T])
- func (l *List[T]) MoveToFront(e *Element[T])
- func (l *List[T]) PushBack(v T) *Element[T]
- func (l *List[T]) PushBackList(other *List[T])
- func (l *List[T]) PushFront(v T) *Element[T]
- func (l *List[T]) PushFrontList(other *List[T])
- func (l *List[T]) Remove(e *Element[T]) T
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Element ¶ added in v0.29.0
type Element[T any] struct { // The value stored with this element. Value T // contains filtered or unexported fields }
Element is an element of a linked list.
type List ¶ added in v0.29.0
type List[T any] struct { // contains filtered or unexported fields }
List represents a doubly linked list. The zero value for List is an empty list ready to use.
func (*List[T]) Back ¶ added in v0.29.0
Back returns the last element of list l or nil if the list is empty.
func (*List[T]) Front ¶ added in v0.29.0
Front returns the first element of list l or nil if the list is empty.
func (*List[T]) InsertAfter ¶ added in v0.29.0
InsertAfter inserts a new element e with value v immediately after mark and returns e. If mark is not an element of l, the list is not modified. The mark must not be nil.
func (*List[T]) InsertBefore ¶ added in v0.29.0
InsertBefore inserts a new element e with value v immediately before mark and returns e. If mark is not an element of l, the list is not modified. The mark must not be nil.
func (*List[T]) Len ¶ added in v0.29.0
Len returns the number of elements of list l. The complexity is O(1).
func (*List[T]) MoveAfter ¶ added in v0.29.0
MoveAfter moves element e to its new position after mark. If e or mark is not an element of l, or e == mark, the list is not modified. The element and mark must not be nil.
func (*List[T]) MoveBefore ¶ added in v0.29.0
MoveBefore moves element e to its new position before mark. If e or mark is not an element of l, or e == mark, the list is not modified. The element and mark must not be nil.
func (*List[T]) MoveToBack ¶ added in v0.29.0
MoveToBack moves element e to the back of list l. If e is not an element of l, the list is not modified. The element must not be nil.
func (*List[T]) MoveToFront ¶ added in v0.29.0
MoveToFront moves element e to the front of list l. If e is not an element of l, the list is not modified. The element must not be nil.
func (*List[T]) PushBack ¶ added in v0.29.0
PushBack inserts a new element e with value v at the back of list l and returns e.
func (*List[T]) PushBackList ¶ added in v0.29.0
PushBackList inserts a copy of another list at the back of list l. The lists l and other may be the same. They must not be nil.
func (*List[T]) PushFront ¶ added in v0.29.0
PushFront inserts a new element e with value v at the front of list l and returns e.
func (*List[T]) PushFrontList ¶ added in v0.29.0
PushFrontList inserts a copy of another list at the front of list l. The lists l and other may be the same. They must not be nil.