Documentation
¶
Overview ¶
Package linkedlist provides a generic doubly linked list with ID-based indexing.
NOT safe for concurrent use. Callers must synchronize access externally.
Index ¶
- type Element
- type Entity
- type List
- func (l *List[V]) Append(elements ...V)
- func (l *List[V]) Back() *Element[V]
- func (l *List[V]) ByID(id string) *Element[V]
- func (l *List[V]) Clear()
- func (l *List[V]) Copy() *List[V]
- func (l *List[V]) Front() *Element[V]
- func (l *List[V]) Init() *List[V]
- func (l *List[V]) InsertAfter(v V, mark *Element[V]) *Element[V]
- func (l *List[V]) InsertBefore(v V, mark *Element[V]) *Element[V]
- func (l *List[V]) Len() int
- func (l *List[V]) List() (result []V)
- func (l *List[V]) MoveAfter(e, mark *Element[V])
- func (l *List[V]) MoveBefore(e, mark *Element[V])
- func (l *List[V]) MoveToBack(e *Element[V])
- func (l *List[V]) MoveToFront(e *Element[V])
- func (l *List[V]) NextID() string
- func (l *List[V]) PushBack(v V) *Element[V]
- func (l *List[V]) PushBackList(other *List[V])
- func (l *List[V]) PushFront(v V) *Element[V]
- func (l *List[V]) PushFrontList(other *List[V])
- func (l *List[V]) Remove(e *Element[V]) V
- func (l *List[V]) ValueToAny(v V) any
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 }
Element is a node in the doubly linked list, holding a value and pointers to adjacent elements.
func (*Element[V]) IsEmpty ¶
IsEmpty reports whether e is an empty (sentinel) element with no assigned ID.
func (*Element[V]) Next ¶
Next returns the next list element or an empty Element if e is at the back.
type Entity ¶
type Entity interface {
ID() string
}
Entity is implemented by values that provide their own identity. When a value stored in the list satisfies Entity, its ID is used as the element key instead of generating a random one.
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 (*List[V]) Append ¶
func (l *List[V]) Append(elements ...V)
Append pushes one or more values to the back of the list.
func (*List[V]) Copy ¶
Copy returns a deep copy of the list. The new list has independent elements but shares the same value references. Element order is preserved.
func (*List[V]) InsertAfter ¶
InsertAfter inserts a new element with value v immediately after mark and returns it. If mark does not belong to l, the list is not modified and nil is returned.
func (*List[V]) InsertBefore ¶
InsertBefore inserts a new element with value v immediately before mark and returns it. If mark does not belong to l, the list is not modified and nil is returned.
func (*List[V]) List ¶
func (l *List[V]) List() (result []V)
List returns all element values in front-to-back order as a slice.
func (*List[V]) MoveBefore ¶
MoveBefore moves element e to its new position before mark.
func (*List[V]) MoveToBack ¶
MoveToBack moves element e to the back of list l.
func (*List[V]) MoveToFront ¶
MoveToFront moves element e to the front of list l.
func (*List[V]) PushBack ¶
PushBack inserts a new element with value v at the back of the list and returns it.
func (*List[V]) PushBackList ¶
PushBackList inserts a copy of another list at the back of list l. The other list may be the same as l.
func (*List[V]) PushFront ¶
PushFront inserts a new element with value v at the front of the list and returns it.
func (*List[V]) PushFrontList ¶
PushFrontList inserts a copy of another list at the front of list l. The other list may be the same as l.
func (*List[V]) ValueToAny ¶
ValueToAny converts a value of type V to the any interface for type assertion.