Documentation
¶
Index ¶
- Variables
- type List
- func (l *List[T]) Back() T
- func (l *List[T]) BackNode() *Node[T]
- func (l *List[T]) Clear()
- func (l *List[T]) Empty() bool
- func (l *List[T]) Front() T
- func (l *List[T]) FrontNode() *Node[T]
- func (l *List[T]) InsertAfter(v T, mark *Node[T]) *Node[T]
- func (l *List[T]) InsertBefore(v T, mark *Node[T]) *Node[T]
- func (l *List[T]) Len() int
- func (l *List[T]) MoveAfter(n, mark *Node[T])
- func (l *List[T]) MoveToBack(n *Node[T])
- func (l *List[T]) MoveToFront(n *Node[T])
- func (l *List[T]) PopBack() T
- func (l *List[T]) PopFront() T
- func (l *List[T]) PushBack(v T)
- func (l *List[T]) PushBackList(other *List[T])
- func (l *List[T]) PushFront(v T)
- func (l *List[T]) PushFrontList(other *List[T])
- func (l *List[T]) Remove(n *Node[T]) T
- func (l *List[T]) Size() int
- func (l *List[T]) String() string
- func (l *List[T]) Traversal(visitor visitor.Visitor[T])
- type ListIterator
- func (iter *ListIterator[T]) Clone() iterator.ConstIterator[T]
- func (iter *ListIterator[T]) Equal(other iterator.ConstIterator[T]) bool
- func (iter *ListIterator[T]) IsValid() bool
- func (iter *ListIterator[T]) Next() iterator.ConstIterator[T]
- func (iter *ListIterator[T]) Prev() iterator.ConstBidIterator[T]
- func (iter *ListIterator[T]) SetValue(value T)
- func (iter *ListIterator[T]) Value() T
- type Node
- type T
Constants ¶
This section is empty.
Variables ¶
var ErrorOutOfRange = errors.New("out of range")
Functions ¶
This section is empty.
Types ¶
type List ¶
type List[T any] struct { // contains filtered or unexported fields }
List represents a bidirectional list:
head -> node1 -- node2 -- node3 | | node6 -- node5 -- node4
func (*List[T]) FrontNode ¶
FrontNode returns the front node of the list or nil if the list is empty
func (*List[T]) InsertAfter ¶
InsertAfter inserts a new node n with value v immediately after mark and returns n. If mark is not a node of l list, the list is not modified. The mark must not be nil.
func (*List[T]) InsertBefore ¶
InsertBefore inserts a new node n with value v immediately before mark and returns n. If mark is not a node of l list, the list is not modified. The mark must not be nil.
func (*List[T]) MoveAfter ¶
MoveAfter moves node n to its new position after mark. If n or mark is not a node of the list, or n == mark, the list is not modified. The node and mark must not be nil.
func (*List[T]) MoveToBack ¶
MoveToBack moves node n to the back of the list. If e is not a node of the list, the list is not modified. The node must not be nil.
func (*List[T]) MoveToFront ¶
MoveToFront moves node n to the front of the list. If n is not a node of the list, the list is not modified. The n must not be nil.
func (*List[T]) PopBack ¶
func (l *List[T]) PopBack() T
PopBack removes the last node in the list and returns its value
func (*List[T]) PopFront ¶
func (l *List[T]) PopFront() T
PopFront removes the first node in the list and returns its value
func (*List[T]) PushBack ¶
func (l *List[T]) PushBack(v T)
PushBack inserts a new node n with value v at the back of the list
func (*List[T]) PushBackList ¶
PushBackList inserts a copy of an other list at the back of the list. The list and other may be the same. They must not be nil.
func (*List[T]) PushFront ¶
func (l *List[T]) PushFront(v T)
PushFront inserts a new node n with value v at the front of the list.
func (*List[T]) PushFrontList ¶
PushFrontList inserts a copy of another list at the front of the list. The list and other may be the same. They must not be nil.
func (*List[T]) Remove ¶
Remove removes n from l list if n is a node of l list. It returns the n value n.Value. The node must not be nil.
type ListIterator ¶
type ListIterator[T any] struct { // contains filtered or unexported fields }
ListIterator is an implementation of list iterator
func NewIterator ¶
func NewIterator[T any](node *Node[T]) *ListIterator[T]
NewIterator creates a ListIterator
func (*ListIterator[T]) Clone ¶
func (iter *ListIterator[T]) Clone() iterator.ConstIterator[T]
Clone clones the iterator to a new iterator
func (*ListIterator[T]) Equal ¶
func (iter *ListIterator[T]) Equal(other iterator.ConstIterator[T]) bool
Equal returns true if the iterator is equal to the passed iterator, otherwise returns false
func (*ListIterator[T]) IsValid ¶
func (iter *ListIterator[T]) IsValid() bool
IsValid returns true if the iterator is valid, otherwise returns false
func (*ListIterator[T]) Next ¶
func (iter *ListIterator[T]) Next() iterator.ConstIterator[T]
Next moves the pointer of iterator to the next node and returns itself
func (*ListIterator[T]) Prev ¶
func (iter *ListIterator[T]) Prev() iterator.ConstBidIterator[T]
Prev moves the pointer of iterator to the previous node and returns itself
func (*ListIterator[T]) SetValue ¶
func (iter *ListIterator[T]) SetValue(value T)
SetValue sets the node's value of the iterator point to
func (*ListIterator[T]) Value ¶
func (iter *ListIterator[T]) Value() T
Value returns the node's value of the iterator point to