Documentation ¶
Index ¶
- type LinkedListDescendingIterator
- func (i *LinkedListDescendingIterator[V]) HasNext() bool
- func (i *LinkedListDescendingIterator[V]) HasPrevious() bool
- func (i *LinkedListDescendingIterator[V]) Next() V
- func (i *LinkedListDescendingIterator[V]) NextIndex() int
- func (i *LinkedListDescendingIterator[V]) Previous() V
- func (i *LinkedListDescendingIterator[V]) PreviousIndex() int
- func (i *LinkedListDescendingIterator[V]) Remove()
- func (i *LinkedListDescendingIterator[V]) Set(value V)
- type LinkedListIterator
- func (i *LinkedListIterator[V]) HasNext() bool
- func (i *LinkedListIterator[V]) HasPrevious() bool
- func (i *LinkedListIterator[V]) Next() V
- func (i *LinkedListIterator[V]) NextIndex() int
- func (i *LinkedListIterator[V]) Previous() V
- func (i *LinkedListIterator[V]) PreviousIndex() int
- func (i *LinkedListIterator[V]) Remove()
- func (i *LinkedListIterator[V]) Set(value V)
- type List
- func From[V any](equal structs.EqualFunc[V], other structs.Collection[V]) *List[V]
- func FromOrdered[V constraints.Ordered](other structs.Collection[V]) *List[V]
- func New[V any](equal structs.EqualFunc[V]) *List[V]
- func NewOrdered[V constraints.Ordered]() *List[V]
- func Of[V any](equal structs.EqualFunc[V], values ...V) *List[V]
- func OfOrdered[V constraints.Ordered](values ...V) *List[V]
- func (l *List[V]) Add(value V) bool
- func (l *List[V]) AddAll(other structs.Collection[V]) bool
- func (l *List[V]) AddFirst(value V) bool
- func (l *List[V]) AddFirstNode(node *Node[V])
- func (l *List[V]) AddIndex(index int, value V)
- func (l *List[V]) AddIndexNode(index int, node *Node[V])
- func (l *List[V]) AddIterator(iter structs.Iterator[V]) bool
- func (l *List[V]) AddLast(value V) bool
- func (l *List[V]) AddLastNode(node *Node[V])
- func (l *List[V]) AddNode(node *Node[V])
- func (l *List[V]) Clear()
- func (l *List[V]) Clone() *List[V]
- func (l *List[V]) CloneBack() *List[V]
- func (l *List[V]) Contains(value V) bool
- func (l *List[V]) ContainsAll(other structs.Collection[V]) bool
- func (l *List[V]) ContainsIterator(iter structs.Iterator[V]) bool
- func (l *List[V]) DescendingIterator() structs.Iterator[V]
- func (l *List[V]) Each(f func(value V))
- func (l *List[V]) EachBack(f func(value V))
- func (l *List[V]) EachNode(f func(node *Node[V]))
- func (l *List[V]) EachNodeBack(f func(node *Node[V]))
- func (l *List[V]) FindLastNode(value V) *Node[V]
- func (l *List[V]) FindNode(value V) *Node[V]
- func (l *List[V]) Get(index int) V
- func (l *List[V]) GetFirst() V
- func (l *List[V]) GetFirstNode() *Node[V]
- func (l *List[V]) GetLast() V
- func (l *List[V]) GetLastNode() *Node[V]
- func (l *List[V]) GetNode(index int) *Node[V]
- func (l *List[V]) IndexOf(value V) int
- func (l *List[V]) IndexOfNode(node *Node[V]) int
- func (l *List[V]) InsertAfter(before, value V) bool
- func (l *List[V]) InsertAfterNode(target *Node[V], value V) bool
- func (l *List[V]) InsertBefore(before, value V) bool
- func (l *List[V]) InsertBeforeNode(target *Node[V], value V) bool
- func (l *List[V]) InsertNodeAfterNode(target *Node[V], node *Node[V]) bool
- func (l *List[V]) InsertNodeBeforeNode(target *Node[V], node *Node[V]) bool
- func (l *List[V]) IsEmpty() bool
- func (l *List[V]) Iterator() structs.Iterator[V]
- func (l *List[V]) LastIndexOf(value V) int
- func (l *List[V]) Offer(value V) bool
- func (l *List[V]) OfferFirst(value V) bool
- func (l *List[V]) OfferLast(value V) bool
- func (l *List[V]) Peek() V
- func (l *List[V]) PeekFirst() V
- func (l *List[V]) PeekLast() V
- func (l *List[V]) Poll() V
- func (l *List[V]) PollFirst() V
- func (l *List[V]) PollLast() V
- func (l *List[V]) Pop() V
- func (l *List[V]) Push(value V)
- func (l *List[V]) Remove(value V) bool
- func (l *List[V]) RemoveAll(other structs.Collection[V]) bool
- func (l *List[V]) RemoveFirst() V
- func (l *List[V]) RemoveFirstOccurrence(value V) bool
- func (l *List[V]) RemoveHead() V
- func (l *List[V]) RemoveIndex(index int) V
- func (l *List[V]) RemoveIndexNode(index int) *Node[V]
- func (l *List[V]) RemoveIterator(iter structs.Iterator[V]) bool
- func (l *List[V]) RemoveLast() V
- func (l *List[V]) RemoveLastOccurrence(value V) bool
- func (l *List[V]) RemoveNode(node *Node[V])
- func (l *List[V]) RetainAll(other structs.Collection[V]) bool
- func (l *List[V]) Reverse()
- func (l *List[V]) Set(index int, value V) V
- func (l *List[V]) Size() int
- func (l *List[V]) Sort(cmp structs.LessFunc[V])
- func (l *List[V]) String() string
- func (l *List[V]) Values() []V
- type Node
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type LinkedListDescendingIterator ¶
type LinkedListDescendingIterator[V any] struct { // contains filtered or unexported fields }
func (*LinkedListDescendingIterator[V]) HasNext ¶
func (i *LinkedListDescendingIterator[V]) HasNext() bool
func (*LinkedListDescendingIterator[V]) HasPrevious ¶
func (i *LinkedListDescendingIterator[V]) HasPrevious() bool
func (*LinkedListDescendingIterator[V]) Next ¶
func (i *LinkedListDescendingIterator[V]) Next() V
func (*LinkedListDescendingIterator[V]) NextIndex ¶
func (i *LinkedListDescendingIterator[V]) NextIndex() int
func (*LinkedListDescendingIterator[V]) Previous ¶
func (i *LinkedListDescendingIterator[V]) Previous() V
func (*LinkedListDescendingIterator[V]) PreviousIndex ¶
func (i *LinkedListDescendingIterator[V]) PreviousIndex() int
func (*LinkedListDescendingIterator[V]) Remove ¶
func (i *LinkedListDescendingIterator[V]) Remove()
func (*LinkedListDescendingIterator[V]) Set ¶
func (i *LinkedListDescendingIterator[V]) Set(value V)
type LinkedListIterator ¶
type LinkedListIterator[V any] struct { // contains filtered or unexported fields }
func (*LinkedListIterator[V]) HasNext ¶
func (i *LinkedListIterator[V]) HasNext() bool
func (*LinkedListIterator[V]) HasPrevious ¶
func (i *LinkedListIterator[V]) HasPrevious() bool
func (*LinkedListIterator[V]) Next ¶
func (i *LinkedListIterator[V]) Next() V
func (*LinkedListIterator[V]) NextIndex ¶
func (i *LinkedListIterator[V]) NextIndex() int
func (*LinkedListIterator[V]) Previous ¶
func (i *LinkedListIterator[V]) Previous() V
func (*LinkedListIterator[V]) PreviousIndex ¶
func (i *LinkedListIterator[V]) PreviousIndex() int
func (*LinkedListIterator[V]) Remove ¶
func (i *LinkedListIterator[V]) Remove()
func (*LinkedListIterator[V]) Set ¶
func (i *LinkedListIterator[V]) Set(value V)
type List ¶
type List[V any] struct { // contains filtered or unexported fields }
List is an implementation of a doubly-linked list.
Removal operations: removed node's pointers remain intact unless the node is re-inserted into a list.
func FromOrdered ¶
func FromOrdered[V constraints.Ordered](other structs.Collection[V]) *List[V]
FromOrdered creates a List from an existing collection of a type that implements constraints.Ordered.
func NewOrdered ¶
func NewOrdered[V constraints.Ordered]() *List[V]
NewOrdered creates an empty List from a type that implements constraints.Ordered.
func OfOrdered ¶
func OfOrdered[V constraints.Ordered](values ...V) *List[V]
OfOrdered creates a List from an existing slice of a type that implements constraints.Ordered.
func (*List[V]) AddAll ¶
func (l *List[V]) AddAll(other structs.Collection[V]) bool
AddAll adds all the values in the other collection to the end of the list.
Time Complexity: O(n)
func (*List[V]) AddFirstNode ¶
AddFirstNode adds a node to the front of the list.
Time Complexity: O(1)
func (*List[V]) AddIndex ¶
AddIndex adds a value at the specified index in the list.
Time Complexity: O(n)
func (*List[V]) AddIndexNode ¶
AddIndexNode adds a node at the specified index in the list.
Time Complexity: O(n)
func (*List[V]) AddIterator ¶
AddIterator adds all the values in the iterator to the list.
Time Complexity: O(n)
func (*List[V]) Clone ¶
Clone creates a new list with the same values, starting at the front.
Time Complexity: O(n)
Space Complexity: O(n)
func (*List[V]) CloneBack ¶
CloneBack creates a new list with the same values, starting at the back.
Time Complexity: O(n)
Space Complexity: O(n)
func (*List[V]) Contains ¶
Contains returns whether the value is present the list.
Time Complexity: O(n)
func (*List[V]) ContainsAll ¶
func (l *List[V]) ContainsAll(other structs.Collection[V]) bool
ContainsAll returns whether all the values in the other collection are present the list.
Time Complexity: O(nm)
n = size of the current list m = size of the other collection
func (*List[V]) ContainsIterator ¶
ContainsIterator returns whether all the values in the iterator are present the list.
Time Complexity: O(nm)
n = size of the current list m = number of values in the iterator
func (*List[V]) DescendingIterator ¶
DescendingIterator returns a LinkedListDescendingIterator for the list.
func (*List[V]) Each ¶
func (l *List[V]) Each(f func(value V))
Each calls a function for each value in the list, starting at the front.
func (*List[V]) EachBack ¶
func (l *List[V]) EachBack(f func(value V))
EachBack calls a function for each value in the list, starting at the end.
func (*List[V]) EachNode ¶
EachNode calls a function for each element in the list, starting at the front.
func (*List[V]) EachNodeBack ¶
EachNodeBack calls a function for each element in the list, starting at the end.
func (*List[V]) FindLastNode ¶
FindLastNode attempts to find and return the last node with the specified value.
Time Complexity: O(n)
func (*List[V]) FindNode ¶
FindNode attempts to find and return the first node with the specified value.
Time Complexity: O(n)
func (*List[V]) GetFirst ¶
func (l *List[V]) GetFirst() V
GetFirst returns the value at the front of the list.
Time Complexity: O(1)
func (*List[V]) GetFirstNode ¶
GetFirstNode returns the node at the front of the list.
Time Complexity: O(1)
func (*List[V]) GetLast ¶
func (l *List[V]) GetLast() V
GetLast returns the value at the end of the list.
Time Complexity: O(1)
func (*List[V]) GetLastNode ¶
GetLastNode returns the node at the head of the list.
Time Complexity: O(1)
func (*List[V]) IndexOf ¶
IndexOf returns the first index of a value in the list, otherwise -1.
Time Complexity: O(n)
func (*List[V]) IndexOfNode ¶
IndexOfNode returns the index of a node in the list, otherwise -1.
Time Complexity: O(n)
func (*List[V]) InsertAfter ¶
InsertAfter inserts a node after the first occurrence of an existing value in the list.
Time Complexity: O(n)
func (*List[V]) InsertAfterNode ¶
InsertAfterNode inserts a value after an existing node in the list.
Time Complexity: O(1)
func (*List[V]) InsertBefore ¶
InsertBefore inserts a node before the first occurrence of an existing value in the list.
Time Complexity: O(n)
func (*List[V]) InsertBeforeNode ¶
InsertBeforeNode inserts a value before an existing node in the list.
Time Complexity: O(1)
func (*List[V]) InsertNodeAfterNode ¶
InsertNodeAfterNode inserts a node after an existing node in the list.
Time Complexity: O(1)
func (*List[V]) InsertNodeBeforeNode ¶
InsertNodeBeforeNode inserts a node before an existing node in the list.
Time Complexity: O(1)
func (*List[V]) LastIndexOf ¶
LastIndexOf returns the last index of a value in the list, otherwise -1.
Time Complexity: O(n)
func (*List[V]) Offer ¶
Offer offers a value to the linked list, adding it to the end of the list.
Time Complexity: O(1)
func (*List[V]) OfferFirst ¶
OfferFirst offers a value to the linked list, adding it to the front of the list.
Time Complexity: O(1)
func (*List[V]) OfferLast ¶
OfferLast offers a value to the linked list, adding it to the end of the list.
Time Complexity: O(1)
func (*List[V]) Peek ¶
func (l *List[V]) Peek() V
Peek returns the first value in the list, or the zero value of the type if the list is empty.
Time Complexity: O(1)
func (*List[V]) PeekFirst ¶
func (l *List[V]) PeekFirst() V
PeekFirst returns the first value in the list, or the zero value of the type if the list is empty.
Time Complexity: O(1)
func (*List[V]) PeekLast ¶
func (l *List[V]) PeekLast() V
PeekLast returns the last value in the list, or the zero value of the type if the list is empty.
Time Complexity: O(1)
func (*List[V]) Poll ¶
func (l *List[V]) Poll() V
Poll removes and returns the first value in the list, or returns the zero value of the type if the list is empty.
Time Complexity: O(1)
func (*List[V]) PollFirst ¶
func (l *List[V]) PollFirst() V
PollFirst removes and returns the first value in the list, or returns the zero value of the type if the list is empty.
Time Complexity: O(1)
func (*List[V]) PollLast ¶
func (l *List[V]) PollLast() V
PollLast removes and returns the last value in the list, or returns the zero value of the type if the list is empty.
Time Complexity: O(1)
func (*List[V]) Pop ¶
func (l *List[V]) Pop() V
Pop removes and returns the first value in the list.
Time Complexity: O(1)
func (*List[V]) Push ¶
func (l *List[V]) Push(value V)
Push appends a value to the front of the list.
Time Complexity: O(1)
func (*List[V]) RemoveAll ¶
func (l *List[V]) RemoveAll(other structs.Collection[V]) bool
RemoveAll removes all the values in the other collection from the list.
Time Complexity: O(nm)
n = size of the current list m = size of the other collection
func (*List[V]) RemoveFirst ¶
func (l *List[V]) RemoveFirst() V
RemoveFirst removes and returns the first value in the list.
Time Complexity: O(1)
func (*List[V]) RemoveFirstOccurrence ¶
RemoveFirstOccurrence removes the first occurrence of a value from the list.
Time Complexity: O(n)
func (*List[V]) RemoveHead ¶
func (l *List[V]) RemoveHead() V
RemoveHead removes and returns the first value in the list.
Time Complexity: O(1)
func (*List[V]) RemoveIndex ¶
RemoveIndex removes the element at the specified index from the list and returns its value.
Time Complexity: O(n)
func (*List[V]) RemoveIndexNode ¶
RemoveIndexNode removes the node at the specified index from the list and returns it.
Time Complexity: O(n)
func (*List[V]) RemoveIterator ¶
RemoveIterator removes all the values in the iterator from the list.
Time Complexity: O(nm)
n = size of the current list m = number of values in the iterator
func (*List[V]) RemoveLast ¶
func (l *List[V]) RemoveLast() V
RemoveLast removes and returns the last value in the list.
Time Complexity: O(1)
func (*List[V]) RemoveLastOccurrence ¶
RemoveLastOccurrence removes the last occurrence of a value from the list.
Time Complexity: O(n)
func (*List[V]) RetainAll ¶
func (l *List[V]) RetainAll(other structs.Collection[V]) bool
RetainAll removes all the values not present in the other collection from the list.
Time Complexity: O(nm)
n = size of the current list m = time complexity of Contains on the other collection
func (*List[V]) Reverse ¶
func (l *List[V]) Reverse()
Reverse reverses the list.
Time Complexity: O(n)
func (*List[V]) Set ¶
Set sets the value at the specified index, returning the old value.
Time Complexity: O(n)
func (*List[V]) Sort ¶
Sort sorts the list based on a comparator.
Time Complexity: best case O(nlogn), worst case O(n^2). See slices.SortFunc (algorithm: pattern-defeating quicksort).