list

package
v0.0.0-...-040aaa0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Element

type Element[T any] struct {
	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

func (*Element[T]) Prev

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

Prev returns the previous list element or nil

type List

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

List represents a doubly linked list. The zero value for List is an empty list ready to use

func New

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

New returns an initialized list

func NewFrom

func NewFrom[T any](items ...T) *List[T]

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

func (l *List[T]) Filter(fn func(T) bool) *List[T]

Filter returns all the elements from the collection which satisfies the conditional logic of callback function

func (*List[T]) Find

func (l *List[T]) Find(fn func(T) bool) *Element[T]

Find returns the index of the first found element

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(e *Element[T], v T)

func (*List[T]) InsertBefore

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

func (*List[T]) Map

func (l *List[T]) Map(fn func(T) T)

Map maps an element to another value

func (*List[T]) MapBy

func (l *List[T]) MapBy(fn func(*T))

MapBy maps an element to another value

func (*List[T]) PopBack

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

PopBack returns the last element in the list l

func (*List[T]) PopFront

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

PopFront returns the first element in the list l

func (*List[T]) PushBack

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

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

func (*List[T]) PushFront

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

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

func (*List[T]) Remove

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

Remove removes e from l if e is an element of list l. It returns the element value e.Value. The element must not be nil

func (*List[T]) Size

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

Size returns the number of elements of list l The complexity is O(1).

Jump to

Keyboard shortcuts

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