linkedlist

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2025 License: GPL-3.0 Imports: 1 Imported by: 0

README

LinkedList

This is double linked list implementation with hash-map index Useful in cases of memory optimization and efficient go through many linked elements. Thread unsafe.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Element

type Element[V any] struct {
	// The value stored with this element.
	Value V
	// contains filtered or unexported fields
}

func (*Element[V]) ID

func (e *Element[V]) ID() string

func (*Element[V]) IsEmpty

func (e *Element[V]) IsEmpty() bool

func (*Element[V]) Next

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

func (*Element[V]) Prev

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

func (*Element[V]) Root

func (e *Element[V]) Root() *Element[V]

type Entity

type Entity interface {
	ID() string
}

type List

type List[V 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[V any]() *List[V]

func (*List[V]) Append

func (l *List[V]) Append(elements ...V)

func (*List[V]) Back

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

func (*List[V]) ByID

func (l *List[V]) ByID(id string) *Element[V]

func (*List[V]) Front

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

func (*List[V]) Init

func (l *List[V]) Init() *List[V]

func (*List[V]) InsertAfter

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

func (*List[V]) InsertBefore

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

func (*List[V]) Len

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

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

func (*List[V]) List

func (l *List[V]) List() (result []V)

func (*List[V]) MoveAfter

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

MoveAfter moves element e to its new position after mark.

func (*List[V]) MoveBefore

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

MoveBefore moves element e to its new position before mark.

func (*List[V]) MoveToBack

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

MoveToBack moves element e to the back of list l.

func (*List[V]) MoveToFront

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

MoveToFront moves element e to the front of list l.

func (*List[V]) NextID

func (l *List[V]) NextID() string

func (*List[V]) PushBack

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

func (*List[V]) PushBackList

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

PushBackList inserts a copy of another list at the back of list l.

func (*List[V]) PushFront

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

func (*List[V]) PushFrontList

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

PushFrontList inserts a copy of another list at the front of list l.

func (*List[V]) Remove

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

func (*List[V]) ValueToAny

func (l *List[V]) ValueToAny(v V) any

Jump to

Keyboard shortcuts

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