list

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 12, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package list implements a thread-safe doubly-linked string list similar to Redis Lists. Supports O(1) push/pop at both ends.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type List

type List struct {
	// contains filtered or unexported fields
}

List is a thread-safe doubly-linked list of strings.

func New

func New() *List

New creates an empty List.

func (*List) ForEach

func (l *List) ForEach(fn func(elem string) bool)

ForEach calls fn for each element. Stops if fn returns false.

func (*List) LIndex

func (l *List) LIndex(index int) (string, bool)

LIndex returns the element at index. Negative indices count from end.

func (*List) LInsert

func (l *List) LInsert(before bool, pivot, value string) int

LInsert inserts value before or after pivot. Returns new length or -1 if pivot not found.

func (*List) LLen

func (l *List) LLen() int

LLen returns the number of elements.

func (*List) LPop

func (l *List) LPop() (string, bool)

LPop removes and returns the head element. ok=false if empty.

func (*List) LPos

func (l *List) LPos(value string, rank, count, maxLen int) []int

LPos returns the first index of value, or -1 if not found. rank: 1-based Nth match. count: max positions to return. maxLen: max scan distance.

func (*List) LPush

func (l *List) LPush(elems ...string) int

LPush inserts elements at the head. Returns new length.

func (*List) LRange

func (l *List) LRange(start, stop int) []string

LRange returns elements from start to stop (inclusive). Negative indices count from end.

func (*List) LRem

func (l *List) LRem(count int, value string) int

LRem removes up to count occurrences of value. count > 0: remove from head; count < 0: remove from tail; count = 0: remove all.

func (*List) LSet

func (l *List) LSet(index int, value string) bool

LSet sets the element at index. Returns false if out of range.

func (*List) LTrim

func (l *List) LTrim(start, stop int)

LTrim keeps only elements in [start, stop] range.

func (*List) RPop

func (l *List) RPop() (string, bool)

RPop removes and returns the tail element. ok=false if empty.

func (*List) RPush

func (l *List) RPush(elems ...string) int

RPush inserts elements at the tail. Returns new length.

Jump to

Keyboard shortcuts

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