list

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2026 License: MIT Imports: 0 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package list provides a doubly linked list built around reusable, caller-owned nodes.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type List

type List[T any] struct {
	// contains filtered or unexported fields
}

List is a doubly linked list. Lists must be created with New.

func New

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

New returns an initialized empty list.

func (*List[T]) Back

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

Back returns the last node or nil if the list is empty.

func (*List[T]) Front

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

Front returns the first node or nil if the list is empty.

func (*List[T]) InsertAfter

func (l *List[T]) InsertAfter(n, mark *Node[T])

InsertAfter inserts n after mark, which must be a node of l. It has the same contract for n as List.PushBack.

func (*List[T]) InsertBefore

func (l *List[T]) InsertBefore(n, mark *Node[T])

InsertBefore inserts n before mark. It has the same contract as List.InsertAfter.

func (*List[T]) PushBack

func (l *List[T]) PushBack(n *Node[T])

PushBack inserts n at the back of the list. n can be a detached node or a node of l, in which case it is moved to the new position. Pushing a node of another list is a no-op - detach it first.

func (*List[T]) PushFront

func (l *List[T]) PushFront(n *Node[T])

PushFront inserts n at the front of the list. It has the same contract for n as List.PushBack.

type Node

type Node[T any] struct {
	Value T
	// contains filtered or unexported fields
}

Node is a node of a List. The zero value is a detached node ready to be inserted into a list.

func (*Node[T]) Detach

func (n *Node[T]) Detach()

Detach removes n from the list it belongs to. It is a no-op if n is already detached.

func (*Node[T]) Next

func (n *Node[T]) Next() *Node[T]

Next returns the next node or nil if n is the last one or is detached.

func (*Node[T]) Prev

func (n *Node[T]) Prev() *Node[T]

Prev returns the previous node or nil if n is the first one or is detached.

Jump to

Keyboard shortcuts

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