bidlist

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2023 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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 New

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

New creates a list

func (*List[T]) Back

func (l *List[T]) Back() T

Back returns the value of the last node

func (*List[T]) BackNode

func (l *List[T]) BackNode() *Node[T]

BackNode returns the last node of the list or nil if the list is empty

func (*List[T]) Clear

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

Clear removes all nodes

func (*List[T]) Empty

func (l *List[T]) Empty() bool

Empty returns true if the list is empty

func (*List[T]) Front

func (l *List[T]) Front() T

Front returns the value of the front node

func (*List[T]) FrontNode

func (l *List[T]) FrontNode() *Node[T]

FrontNode returns the front node of the list or nil if the list is empty

func (*List[T]) InsertAfter

func (l *List[T]) InsertAfter(v T, mark *Node[T]) *Node[T]

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

func (l *List[T]) InsertBefore(v T, mark *Node[T]) *Node[T]

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]) Len

func (l *List[T]) Len() int

Len returns the amount of list nodes.

func (*List[T]) MoveAfter

func (l *List[T]) MoveAfter(n, mark *Node[T])

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

func (l *List[T]) MoveToBack(n *Node[T])

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

func (l *List[T]) MoveToFront(n *Node[T])

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

func (l *List[T]) PushBackList(other *List[T])

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

func (l *List[T]) PushFrontList(other *List[T])

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

func (l *List[T]) Remove(n *Node[T]) T

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.

func (*List[T]) Size

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

Size returns the amount of list nodes.

func (*List[T]) String

func (l *List[T]) String() string

String returns a string representation of the list

func (*List[T]) Traversal

func (l *List[T]) Traversal(visitor visitor.Visitor[T])

Traversal traversals elements in the list, it will not stop until to the end of the list or the visitor returns false

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

type Node

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

Node is a list node

func (*Node[T]) Next

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

Next returns the next list node or nil.

func (*Node[T]) Prev

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

Prev returns the previous list node or nil.

type T added in v1.1.0

type T any

List is an implementation of Container

Jump to

Keyboard shortcuts

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