list

package
v0.9.1 Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2025 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Direction

type Direction int
const (
	FromFront Direction = iota
	FromBack
)

type Element

type Element[T types.Sized] struct {
	// contains filtered or unexported fields
}

Element is a node in the doubly linked list that holds a value of type T. Never touch fields directly outside of List methods.

func (*Element[T]) List

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

List returns the whole list if this element.

func (*Element[T]) Next

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

func (*Element[T]) Prev

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

func (*Element[T]) Value

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

Value returns the value. NOT thread-safe! Only use inside locked section or single-threaded use!

func (*Element[T]) Weight

func (e *Element[T]) Weight() int64

type List

type List[T types.Sized] struct {
	// contains filtered or unexported fields
}

List is a generic doubly linked list with optional thread safety.

func New

func New[T types.Sized]() *List[T]

New creates a new list. If isThreadSafe is true, all ops are guarded by a mutex.

func (*List[T]) Back

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

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

func (*List[T]) Len

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

Len returns the list length (O(1)). Thread-safe if guarded.

func (*List[T]) MoveToFront

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

MoveToFront moves e to the front of the list without removing it from memory or touching the pool.

func (*List[T]) Next

func (l *List[T]) Next(offset int) (*Element[T], bool)

Next returns the element at the given offset from the front (0-based). Returns (nil, false) if offset is out of bounds.

func (*List[T]) PrevUnlocked

func (l *List[T]) PrevUnlocked(offset int) (*Element[T], bool)

PrevUnlocked returns the element at the given offset from the back (0-based). Returns (nil, false) if offset is out of bounds.

func (*List[T]) PushBack

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

PushBack inserts v at the back and returns new element. Thread-safe if guarded.

func (*List[T]) PushFront

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

PushFront inserts v at the front and returns new element. Thread-safe if guarded.

func (*List[T]) Remove

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

Remove removes e from l and returns its value. Thread-safe.

func (*List[T]) Sort

func (l *List[T]) Sort(ord Order)

func (*List[T]) Walk

func (l *List[T]) Walk(dir Direction, fn func(l *List[T], el *Element[T]) (shouldContinue bool))

Walk executes fn for each element in order (under lock if guarded).

type Order

type Order int
const (
	DESC Order = iota
	ASC
)

Jump to

Keyboard shortcuts

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