bidlist

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2020 License: MIT Imports: 4 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type List

type List struct {
	// contains filtered or unexported fields
}

List represents a bidirectional list:

head -> node1 -- node2 --  node3
         |                   |
        node6 -- node5 --  node4

func New

func New() *List

New creates a list

func (*List) Back

func (l *List) Back() interface{}

Back returns the value of the last node

func (*List) BackNode

func (l *List) BackNode() *Node

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

func (*List) Clear

func (l *List) Clear()

Clear removes all nodes

func (*List) Empty

func (l *List) Empty() bool

Empty returns true if the list is empty

func (*List) Front

func (l *List) Front() interface{}

Front returns the value of the front node

func (*List) FrontNode

func (l *List) FrontNode() *Node

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

func (*List) InsertAfter

func (l *List) InsertAfter(v interface{}, mark *Node) *Node

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) InsertBefore

func (l *List) InsertBefore(v interface{}, mark *Node) *Node

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

func (l *List) Len() int

Len returns the amount of list nodes.

func (*List) MoveAfter

func (l *List) MoveAfter(n, mark *Node)

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) MoveToBack

func (l *List) MoveToBack(n *Node)

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) MoveToFront

func (l *List) MoveToFront(n *Node)

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) PopBack

func (l *List) PopBack() interface{}

PopBack removes the last node in the list and returns its value

func (*List) PopFront

func (l *List) PopFront() interface{}

PopFront removes the first node in the list and returns its value

func (*List) PushBack

func (l *List) PushBack(v interface{})

PushBack inserts a new node n with value v at the back of the list

func (*List) PushBackList

func (l *List) PushBackList(other *List)

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) PushFront

func (l *List) PushFront(v interface{})

PushFront inserts a new node n with value v at the front of the list.

func (*List) PushFrontList

func (l *List) PushFrontList(other *List)

PushFrontList inserts a copy of an other list at the front of the list. The list and other may be the same. They must not be nil.

func (*List) Remove

func (l *List) Remove(n *Node) interface{}

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) Size

func (l *List) Size() int

Size returns the amount of list nodes.

func (*List) String

func (l *List) String() string

String returns a string representation of the list

func (*List) Traversal

func (l *List) Traversal(visitor visitor.Visitor)

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 struct {
	// contains filtered or unexported fields
}

ListIterator is an implementation of list iterator

func NewIterator

func NewIterator(node *Node) *ListIterator

NewIterator creates a ListIterator

func (*ListIterator) Clone

func (iter *ListIterator) Clone() iterator.ConstIterator

Clone clones the iterator to a new iterator

func (*ListIterator) Equal

func (iter *ListIterator) Equal(other iterator.ConstIterator) bool

Equal returns true if the iterator is equal to the passed iterator, otherwise returns false

func (*ListIterator) IsValid

func (iter *ListIterator) IsValid() bool

IsValid returns true if the iterator is valid, otherwise returns false

func (*ListIterator) Next

func (iter *ListIterator) Next() iterator.ConstIterator

Next moves the pointer of iterator to the next node and returns itself

func (*ListIterator) Prev

func (iter *ListIterator) Prev() iterator.ConstBidIterator

Prev moves the pointer of iterator to the previous node and returns itself

func (*ListIterator) SetValue

func (iter *ListIterator) SetValue(value interface{})

SetValue sets the node's value of the iterator point to

func (*ListIterator) Value

func (iter *ListIterator) Value() interface{}

Value returns the node's value of the iterator point to

type Node

type Node struct {
	Value interface{}
	// contains filtered or unexported fields
}

Node is a list node

func (*Node) Next

func (n *Node) Next() *Node

Next returns the next list node or nil.

func (*Node) Prev

func (n *Node) Prev() *Node

Prev returns the previous list node or nil.

Jump to

Keyboard shortcuts

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