Documentation
¶
Index ¶
- func AllOfList[T any](l *list.List) []T
- func ListOf[T any](items ...T) *list.List
- func SliceOf[T any](items ...T) []T
- func WriteStrings(w io.Writer, values ...string) error
- type Element
- type List
- func (l *List[T]) Back() Element[T]
- func (l *List[T]) Front() Element[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
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AllOfList ¶
AllOfList returns all elements of the given list as a slice of type T.
The caller must ensure that every element stored in the list is of type T. If an element has a different type, this function will panic at runtime.
If the list is nil or empty, an empty slice is returned.
func ListOf ¶
ListOf creates a new list.List and populates it with the provided items.
All elements are inserted in the order they appear in the argument list.
Types ¶
type Element ¶ added in v0.0.11
Element is an element of a linked list.
func (Element[T]) Next ¶ added in v0.0.11
Next returns the next element of list l or nil if e is the last element.
func (Element[T]) Prev ¶ added in v0.0.11
Prev returns the previous element of list l or nil if e is the first element.
type List ¶ added in v0.0.11
List is a doubly linked list.
func New ¶ added in v0.0.11
New returns an empty list.
Example ¶
l := New[int]()
l.PushBack(1)
l.PushBack(2)
l.PushBack(3)
for e := l.Front(); e.Valid(); e = e.Next() {
_ = e.Value()
}
func (*List[T]) Back ¶ added in v0.0.11
Back returns the last element of list l or nil if the list is empty.
func (*List[T]) Front ¶ added in v0.0.11
Front returns the first element of list l or nil if the list is empty.
func (*List[T]) InsertAfter ¶ added in v0.0.11
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.0.11
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.
Example ¶
l := New[int]()
e1 := l.PushBack(1)
e3 := l.PushBack(3)
l.InsertBefore(2, e3)
for e := l.Front(); e.Valid(); e = e.Next() {
_ = e.Value()
}
_ = e1
func (*List[T]) Len ¶ added in v0.0.11
Len returns the number of elements of list l. The complexity is O(1).
func (*List[T]) MoveAfter ¶ added in v0.0.11
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.0.11
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.0.11
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.0.11
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.
Example ¶
l := New[int]() l.PushBack(1) l.PushBack(2) l.PushBack(3) e := l.Back() l.MoveToFront(e) _ = l.Front().Value()
func (*List[T]) PushBack ¶ added in v0.0.11
PushBack inserts a new element e with value v at the back of list l and returns e.
Example ¶
l := New[string]()
l.PushBack("apple")
l.PushBack("banana")
l.PushBack("cherry")
front := l.Front().Value()
back := l.Back().Value()
_ = front
_ = back
func (*List[T]) PushBackList ¶ added in v0.0.11
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.
Example ¶
l1 := New[int]()
l1.PushBack(1)
l1.PushBack(2)
l2 := New[int]()
l2.PushBack(3)
l2.PushBack(4)
l1.PushBackList(l2)
for e := l1.Front(); e.Valid(); e = e.Next() {
_ = e.Value()
}
func (*List[T]) PushFront ¶ added in v0.0.11
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.0.11
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.
func (*List[T]) Remove ¶ added in v0.0.11
Remove removes e from l if e is an element of list l. It returns the element value e.Value. The element must not be nil.
Example ¶
l := New[int]()
e1 := l.PushBack(10)
e2 := l.PushBack(20)
e3 := l.PushBack(30)
l.Remove(e2)
for e := l.Front(); e.Valid(); e = e.Next() {
_ = e.Value()
}
_ = e1
_ = e3