simplelist

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2021 License: MIT Imports: 3 Imported by: 0

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 single direction list:

head -> node1 --> node2 --> node3 <- tail

func New

func New() *List

New creates a list

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

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

MoveToBack moves node n to the back of the list. The n must not be nil.

func (*List) MoveToFront

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

MoveToFront moves node n to the front of the list. The n must not be nil.

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

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

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

func (*List) Remove

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

Remove removes node n from the list. The node must not be nil.

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 iterator for list

func NewIterator

func NewIterator(node *Node) *ListIterator

NewIterator news a ListIterator

func (*ListIterator) Clone

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

Clone clones iter to a new ListIterator

func (*ListIterator) Equal

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

Equal returns whether iter is equal to other

func (*ListIterator) IsValid

func (iter *ListIterator) IsValid() bool

IsValid returns whether iter is valid

func (*ListIterator) Next

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

Next returns the next iterator

func (*ListIterator) SetValue

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

SetValue sets the value of iter

func (*ListIterator) Value

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

Value returns the internal value of iter

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.

Jump to

Keyboard shortcuts

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