list

package module
v0.0.0-...-494db03 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2024 License: MIT Imports: 0 Imported by: 1

README

go-list

a doubly-linked list library with generic support.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Elem

type Elem[T any] struct {
	Next  *Elem[T]
	Prev  *Elem[T]
	Value T
}

Elem represents an element in a doubly-linked list.

type List

type List[T any] struct {
	Head *Elem[T]
	Tail *Elem[T]
	// contains filtered or unexported fields
}

List implements a doubly-linked list, where: - Head = index 0 (i.e. the front) - Tail = index n-1 (i.e. the back)

func (*List[T]) InsertAfter

func (l *List[T]) InsertAfter(v T, at *Elem[T]) *Elem[T]

InsertAfter adds 'v' into the list after 'at'.

func (*List[T]) InsertBefore

func (l *List[T]) InsertBefore(v T, at *Elem[T]) *Elem[T]

InsertBefore adds 'v' into the list before 'at'.

func (*List[T]) InsertElemAfter

func (l *List[T]) InsertElemAfter(elem *Elem[T], at *Elem[T])

InsertElemAfter adds 'elem' into the list after 'at' (i.e. at.Next = elem).

func (*List[T]) InsertElemBefore

func (l *List[T]) InsertElemBefore(elem *Elem[T], at *Elem[T])

InsertElemBefore adds 'elem' into the list before 'at' (i.e. at.Prev = elem).

func (*List[T]) Len

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

Len returns the current list length.

func (*List[T]) PushBack

func (l *List[T]) PushBack(v T) *Elem[T]

PushBack adds 'v' to the end of the list.

func (*List[T]) PushElemBack

func (l *List[T]) PushElemBack(elem *Elem[T])

PushBackNode adds 'elem' to the back of the list.

func (*List[T]) PushElemFront

func (l *List[T]) PushElemFront(elem *Elem[T])

PushFrontNode adds 'elem' to the front of the list.

func (*List[T]) PushFront

func (l *List[T]) PushFront(v T) *Elem[T]

PushFront adds 'v' to the beginning of the list.

func (*List[T]) Range

func (l *List[T]) Range(fn func(*Elem[T]))

Range calls 'fn' on every element from head forward in list.

func (*List[T]) RangeReverse

func (l *List[T]) RangeReverse(fn func(*Elem[T]))

RangeReverse calls 'fn' on every element from tail backward in list.

func (*List[T]) Remove

func (l *List[T]) Remove(elem *Elem[T])

Remove removes the 'elem' from the list.

Jump to

Keyboard shortcuts

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