list

package
v0.3.8 Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2024 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrorListElementIsNil          = errors.New("list element is nil")
	ErrorListElementIsNotInTheList = errors.New("list element is not in the list")
)

Functions

This section is empty.

Types

type Element

type Element[T any] struct {

	// The Value stored with this element.
	Value T
	// contains filtered or unexported fields
}

Element is an element of a linked list.

func (*Element[T]) Next

func (e *Element[T]) Next() *Element[T]

Next returns the next list element or nil for the last one.

func (*Element[T]) Prev

func (e *Element[T]) Prev() *Element[T]

Prev returns the previous list element or nil for the first one.

type Iterator added in v0.3.3

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

Iterator with ability to validate himself when current element is removed from list.

func NewIterator added in v0.3.3

func NewIterator[T any](list *List[T]) Iterator[T]

Creates iterator. Iterator is not valid until Next() call.

func (*Iterator[T]) Current added in v0.3.3

func (it *Iterator[T]) Current() *Element[T]

func (*Iterator[T]) Next added in v0.3.3

func (it *Iterator[T]) Next() bool

func (*Iterator[T]) Valid added in v0.3.3

func (it *Iterator[T]) Valid() bool

type List

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

List represents a doubly linked list.

A doubly linked list (DLL) is a special type of linked list in which each node contains a pointer to the previous node as well as the next node of the linked list.

func NewList

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

NewList creates new List instance.

func NewListPooled

func NewListPooled[T any](pool *sync.Pool) *List[T]

NewListPooled creates new List instance. Pooled tree uses given pool for nodes creating/releasing.

func (*List[T]) Back

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

Back returns the last element of list l or nil if the list is empty.

func (*List[T]) Clean

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

Clean cleans list l by removing all existing elements.

func (*List[T]) Front

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

Front returns the first element of list l or nil if the list is empty.

func (*List[T]) InsertAfter

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

InsertAfter inserts a new element e with value v immediately after mark and returns e. If mark is not an element of l, the list is not modified. The mark must not be nil.

func (*List[T]) InsertBefore

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

InsertBefore inserts a new element e with value v immediately before mark and returns e. If mark is not an element of l, the list is not modified. The mark must not be nil.

func (*List[T]) Iterator added in v0.3.3

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

func (*List[T]) Len

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

Len returns the number of elements of list l.

func (*List[T]) MoveAfter

func (l *List[T]) MoveAfter(e, mark *Element[T])

MoveAfter moves element e to its new position after mark. If e or mark is not an element of l, or e == mark, the list is not modified. The element and mark must not be nil.

func (*List[T]) MoveBefore

func (l *List[T]) MoveBefore(e, mark *Element[T])

MoveBefore moves element e to its new position before mark. If e or mark is not an element of l, or e == mark, the list is not modified. The element and mark must not be nil.

func (*List[T]) MoveToBack

func (l *List[T]) MoveToBack(e *Element[T])

MoveToBack moves element e to the back of list l. If e is not an element of l, the list is not modified. The element must not be nil.

func (*List[T]) MoveToFront

func (l *List[T]) MoveToFront(e *Element[T])

MoveToFront moves element e to the front of list l. If e is not an element of l, the list is not modified. The element must not be nil.

func (*List[T]) PushBack

func (l *List[T]) PushBack(v T) *Element[T]

PushBack inserts a new element e with value v at the back of list l and returns e.

func (*List[T]) PushBackList

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

PushBackList inserts a copy of another list at the back of list l. The lists l and other may be the same. They must not be nil.

func (*List[T]) PushFront

func (l *List[T]) PushFront(v T) *Element[T]

PushFront inserts a new element e with value v at the front of list l and returns e.

func (*List[T]) PushFrontList

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

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

func (*List[T]) Remove

func (l *List[T]) Remove(e *Element[T]) (v T, err error)

Remove removes e from l if e is an element of list l.

Jump to

Keyboard shortcuts

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