linklist

package
v1.7.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 21, 2024 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Iterator

type Iterator[T any] struct {
	// contains filtered or unexported fields
}

Iterator is an iterator over a List.

func (*Iterator[T]) Get

func (it *Iterator[T]) Get() T

Get returns the current element.

func (*Iterator[T]) GetRef

func (it *Iterator[T]) GetRef() *T

GetRef returns a reference to the current element.

func (*Iterator[T]) Index

func (it *Iterator[T]) Index() int

Index returns the current index.

func (*Iterator[T]) InsertAfter

func (it *Iterator[T]) InsertAfter(value T)

InsertAfter inserts the specified element after the current element. Iterator keeps pointing to the current element.

func (*Iterator[T]) InsertBefore

func (it *Iterator[T]) InsertBefore(value T)

InsertBefore inserts the specified element before the current element. Iterator then points to the inserted element.

func (*Iterator[T]) Move

func (it *Iterator[T]) Move()

Move moves the iterator to the next element.

func (*Iterator[T]) Node

func (it *Iterator[T]) Node() *Node[T]

Node returns the current node.

func (*Iterator[T]) Remove

func (it *Iterator[T]) Remove()

Remove removes the current element. Iterator then points to the next element.

func (*Iterator[T]) Set

func (it *Iterator[T]) Set(value T)

Set sets the current element.

func (*Iterator[T]) Valid

func (it *Iterator[T]) Valid() bool

Valid returns true if the iterator is currently pointing to a valid element.

type List

type List[T any] struct {
	// contains filtered or unexported fields
}

List is a doubly linked list implementation. The zero value is ready to use. Do not copy a non-zero List.

func New

func New[T any]() *List[T]

New creates an empty list.

func NewFromIterable added in v1.6.1

func NewFromIterable[T any](iterable iter.Iterable[T]) *List[T]

NewFromIterable creates a list from the specified iter.Iterable.

func (*List[T]) Append

func (list *List[T]) Append(value T)

Append inserts the specified element at the end of the List.

func (*List[T]) Clear

func (list *List[T]) Clear()

Clear removes all elements from the List.

func (*List[T]) Clone

func (list *List[T]) Clone() cols.Collection[T]

Clone returns a shallow copy of the List.

func (*List[T]) CollectionIterator

func (list *List[T]) CollectionIterator() cols.Iterator[T]

CollectionIterator returns an iterator over the elements in the List.

func (*List[T]) FindIndex

func (list *List[T]) FindIndex(predicate predication.Predicate[T]) (int, bool)

FindIndex returns the index of the first element that matches the specified predicate.

func (*List[T]) FindNode

func (list *List[T]) FindNode(predicate predication.Predicate[T]) (*Node[T], bool)

FindNode returns the first node that matches the specified predicate.

func (*List[T]) FindRef

func (list *List[T]) FindRef(predicate predication.Predicate[T]) (*T, bool)

FindRef returns a reference to the first element that matches the specified predicate.

func (*List[T]) Get

func (list *List[T]) Get(index int) T

Get returns the element at the specified index. Negative indices are interpreted as relative to the end of the List. Panics if the index is out of bounds.

func (*List[T]) GetNode

func (list *List[T]) GetNode(index int) *Node[T]

GetNode returns the node at the specified index. Negative indices are interpreted as relative to the end of the List. Panics if the index is out of bounds.

func (*List[T]) GetRef

func (list *List[T]) GetRef(index int) *T

GetRef returns a reference to the element at the specified index. Negative indices are interpreted as relative to the end of the List. Panics if the index is out of bounds.

func (*List[T]) Head

func (list *List[T]) Head() *Node[T]

Head returns the first node in the List.

func (*List[T]) Insert

func (list *List[T]) Insert(index int, value T)

Insert inserts the specified element at the specified index. Negative indices are interpreted as relative to the end of the List. Panics if the index is out of bounds.

func (*List[T]) Iterator

func (list *List[T]) Iterator() iter.Iterator[T]

Iterator returns an iterator over the elements in the List.

func (*List[T]) Join

func (list *List[T]) Join(other cols.Collection[T])

Join appends all elements from the other collection to the List. The other collection is cleared.

func (*List[T]) Prepend

func (list *List[T]) Prepend(value T)

Prepend inserts the specified element at the beginning of the List.

func (*List[T]) RefsStream

func (list *List[T]) RefsStream(yield func(*T) bool)

RefsStream streams references to the elements in the List.

func (*List[T]) Remove

func (list *List[T]) Remove(index int)

Remove removes the element at the specified index. Negative indices are interpreted as relative to the end of the List. Panics if the index is out of bounds.

func (*List[T]) RemoveNode

func (list *List[T]) RemoveNode(node *Node[T])

RemoveNode removes the specified node from the List. Panics if the node is not part of the List.

func (*List[T]) Reverse

func (list *List[T]) Reverse()

Reverse reverses the order of the elements in the List.

func (*List[T]) Set

func (list *List[T]) Set(index int, value T)

Set sets the element at the specified index. Negative indices are interpreted as relative to the end of the List. Panics if the index is out of bounds.

func (*List[T]) Size

func (list *List[T]) Size() int

Size returns the number of elements in the list.

func (*List[T]) Sort

func (list *List[T]) Sort(comparator comparison.Comparator[T])

Sort sorts the elements in the List by the specified comparator. The sorting algorithm is a stable variant of merge sort.

func (*List[T]) Stream

func (list *List[T]) Stream(yield func(T) bool)

Stream streams the elements in the List.

func (*List[T]) Tail

func (list *List[T]) Tail() *Node[T]

Tail returns the last node in the List.

type Node

type Node[T any] struct {
	Value T // The value stored in the node.
	// contains filtered or unexported fields
}

Node is an element of a linked list. It should not be created directly.

func (*Node[T]) InsertAfter

func (node *Node[T]) InsertAfter(value T)

InsertAfter inserts the specified element immediately after this node.

func (*Node[T]) InsertBefore

func (node *Node[T]) InsertBefore(value T)

InsertBefore inserts the specified element immediately before this node.

func (*Node[T]) Next

func (node *Node[T]) Next() *Node[T]

Next returns the next node in the List.

func (*Node[T]) Prev

func (node *Node[T]) Prev() *Node[T]

Prev returns the previous node in the List.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL