list

package
v0.0.0-...-62eb196 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2024 License: Unlicense Imports: 2 Imported by: 0

Documentation

Overview

Package list implements a doubly-linked list.

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. Create new lists with New and then use the list's methods to interact with it.

func New

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

New creates a new, empty linked-list.

func (*List[T]) Back

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

Back returns the last node in the list.

func (*List[T]) Front

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

Front returns the first node in the list.

func (*List[T]) InsertAfter

func (lst *List[T]) InsertAfter(node *Node[T], val T) *Node[T]

InsertAfter inserts a new node with the given value after `node`.

func (*List[T]) InsertBack

func (lst *List[T]) InsertBack(val T)

InsertBack inserts a new node with the given value at the back of the list.

func (*List[T]) InsertBefore

func (lst *List[T]) InsertBefore(node *Node[T], val T) *Node[T]

InsertBefore inserts a new node with the given value before `node`.

func (*List[T]) InsertFront

func (lst *List[T]) InsertFront(val T)

InsertFront inserts a new node with the given value at the front of the list.

func (*List[T]) Len

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

Len is the number of elements in the linked list. O(1)

func (*List[T]) Next

func (lst *List[T]) Next(node *Node[T]) *Node[T]

Next returns the next node in the list after `node`.

func (*List[T]) Nodes

func (lst *List[T]) Nodes() iter.Seq[*Node[T]]

Nodes returns an iterator over all the nodes in the list.

func (*List[T]) Prev

func (lst *List[T]) Prev(node *Node[T]) *Node[T]

Prev returns the previous node in the list before `node`.

func (*List[T]) Remove

func (lst *List[T]) Remove(node *Node[T])

Remove removes the given node from the list.

func (*List[T]) Values

func (lst *List[T]) Values() iter.Seq[T]

Values returns an iterator over all the values in the list.

type Node

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

Node represents a node in the linked list; it holds a generic value, and can be used as a handle into the list for insertions/removals.

Jump to

Keyboard shortcuts

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