xlist

package
v3.89.5 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2024 License: Apache-2.0 Imports: 0 Imported by: 0

Documentation

Overview

Package xlist is a copy of standard container/list but uses generics for strict checks on compile time

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Element

type Element[T any] struct {

	// The value stored with this element.
	Value T
	// contains filtered or unexported fields
}

Element is an element of a linked list.

func (*Element[T]) Next

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

Next returns the next list element or nil.

func (*Element[T]) Prev

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

Prev returns the previous list element or nil.

type List

type List[T any] interface {
	// PushBack inserts a new element e with value v at the back of list l and returns e.
	PushBack(v T) *Element[T]

	// PushBackList inserts a copy of another list at the back of list l.
	// The lists l and other may be the same. They must not be nil.
	PushBackList(other List[T])

	// PushFront inserts a new element e with value v at the front of list l and returns e.
	PushFront(v T) *Element[T]

	// PushFrontList inserts a copy of another list at the front of list l.
	// The lists l and other may be the same. They must not be nil.
	PushFrontList(other List[T])

	// MoveToFront moves element e to the front of list l.
	// If e is not an element of l, the list is not modified.
	// The element must not be nil.
	MoveToFront(e *Element[T])

	// MoveToBack moves element e to the back of list l.
	// If e is not an element of l, the list is not modified.
	// The element must not be nil.
	MoveToBack(e *Element[T])

	// MoveAfter moves element e to its new position after mark.
	// If e or mark is not an element of l, or e == mark, the list is not modified.
	// The element and mark must not be nil.
	MoveAfter(e, mark *Element[T])

	// MoveBefore moves element e to its new position before mark.
	// If e or mark is not an element of l, or e == mark, the list is not modified.
	// The element and mark must not be nil.
	MoveBefore(e, mark *Element[T])

	// Remove removes e from l if e is an element of list l.
	// It returns the element value e.Value.
	// The element must not be nil.
	Remove(e *Element[T]) T

	// InsertBefore inserts a new element e with value v immediately before mark and returns e.
	// If mark is not an element of l, the list is not modified.
	// The mark must not be nil.
	InsertBefore(v T, mark *Element[T]) *Element[T]

	// InsertAfter inserts a new element e with value v immediately after mark and returns e.
	// If mark is not an element of l, the list is not modified.
	// The mark must not be nil.
	InsertAfter(v T, mark *Element[T]) *Element[T]

	// Front returns the first element of list l or nil if the list is empty.
	Front() *Element[T]

	// Back returns the last element of list l or nil if the list is empty.
	Back() *Element[T]

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

	// Clear clears the list l.
	Clear()
}

List represents a doubly linked list. The zero value for List is an empty list ready to use.

func New

func New[T any]() List[T]

New returns an initialized list.

Jump to

Keyboard shortcuts

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