list

package
v1.4.1 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 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
}

func (*Element[T]) List

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

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

func (*Element[T]) Weight

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

type List

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

func New

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

New creates a new empty list with its own mutex and element pool.

func (*List[T]) Back

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

Back returns the last element (LRU tail) or nil if empty.

func (*List[T]) Front added in v1.3.0

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

Front returns the first element (MRU head) or nil if empty.

func (*List[T]) Len

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

Len returns the number of user elements in the list. Safe for concurrent reads.

func (*List[T]) MoveToFront

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

MoveToFront moves e to the front (MRU head). No-op if len<2 or already at head.

func (*List[T]) Next

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

Next returns the element at offset from the front (MRU head). offset=0 -> head. Returns (nil, false) if out of range.

func (*List[T]) NextFromBack added in v1.3.0

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

NextFromBack returns the element at offset from the back (LRU tail). offset=0 -> tail. Returns (nil, false) if out of range.

func (*List[T]) PopBack added in v1.3.0

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

PopBack removes and returns the last element (LRU tail) or nil if empty. Caller is responsible to eventually return the element to the pool via FreeElement AFTER it has consumed e.Value() (e.g., after removing from external storage/index).

func (*List[T]) PushBack

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

PushBack inserts v at the back (LRU tail) and returns the new element.

func (*List[T]) PushFront

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

PushFront inserts v at the front (MRU head) and returns the new element.

func (*List[T]) Remove

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

Remove unlinks e from the list and returns it to the pool. Safe to call multiple times; subsequent calls are no-ops.

func (*List[T]) Sort

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

Sort reorders the list by element Weight (ascending or descending), keeping it circular. NOTE: Sorting is O(n log n) and should be used sparingly in hot paths.

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