simplelist

package
v1.3.27 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2023 License: MIT Imports: 5 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[T any] struct {
	Lock sync.Locker
	// contains filtered or unexported fields
}

List represents a single direction list:

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

func New

func New[T any](opts ...Option) *List[T]

New creates a list

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

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

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

func (*List[T]) MoveToFront

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

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

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

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

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

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

func NewIterator

func NewIterator[T any](node *Node[T]) *ListIterator[T]

NewIterator news a ListIterator

func (*ListIterator[T]) Clone

func (iter *ListIterator[T]) Clone() iterator.ConstIterator[T]

Clone clones iter to a new ListIterator

func (*ListIterator[T]) Equal

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

Equal returns whether iter is equal to other

func (*ListIterator[T]) IsValid

func (iter *ListIterator[T]) IsValid() bool

IsValid returns whether iter is valid

func (*ListIterator[T]) Next

func (iter *ListIterator[T]) Next() iterator.ConstIterator[T]

Next returns the next iterator

func (*ListIterator[T]) SetValue

func (iter *ListIterator[T]) SetValue(value T)

SetValue sets the value of iter

func (*ListIterator[T]) Value

func (iter *ListIterator[T]) Value() T

Value returns the internal value of iter

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.

type Option added in v1.3.3

type Option func(option *Options)

Option is a function type used to set Options

func WithGoroutineSafe added in v1.3.3

func WithGoroutineSafe() Option

WithGoroutineSafe is used to set the set goroutine-safe Note that iterators are not goroutine safe, and it is useless to turn on the setting option here. so don't use iterators in multi goroutines

type Options added in v1.3.3

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

Options holds the Set's options

Jump to

Keyboard shortcuts

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