list

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2022 License: MIT Imports: 0 Imported by: 0

README

list

import "github.com/zendesk/generic/list"

Package list provides an implementation of a doubly-linked list with a front and back. The individual nodes of the list are publicly exposed so that the user can have fine-grained control over the list.

Example

package main

import (
	"fmt"
	"github.com/zendesk/generic/list"
)

func main() {
	l := list.New[int]()
	l.PushBack(0)
	l.PushBack(1)
	l.PushBack(2)
	l.PushBack(3)

	l.Front.Each(func(i int) {
		fmt.Println(i)
	})
}
Output
0
1
2
3

Index

type List

List implements a doubly-linked list.

type List[V any] struct {
    Front, Back *Node[V]
}
func New
func New[V any]() *List[V]

New returns an empty linked list.

func (*List[V]) PushBack
func (l *List[V]) PushBack(v V)

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

func (*List[V]) PushBackNode
func (l *List[V]) PushBackNode(n *Node[V])

PushBackNode adds the node 'n' to the back of the list.

func (*List[V]) PushFront
func (l *List[V]) PushFront(v V)

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

func (*List[V]) PushFrontNode
func (l *List[V]) PushFrontNode(n *Node[V])

PushFrontNode adds the node 'n' to the front of the list.

func (*List[V]) Remove
func (l *List[V]) Remove(n *Node[V])

Remove removes the node 'n' from the list.

type Node

Node is a node in the linked list.

type Node[V any] struct {
    Value      V
    Prev, Next *Node[V]
}
func (*Node[V]) Each
func (n *Node[V]) Each(fn func(val V))

Each calls 'fn' on every element from this node onward in the list.

func (*Node[V]) EachReverse
func (n *Node[V]) EachReverse(fn func(val V))

EachReverse calls 'fn' on every element from this node backward in the list.

Generated by gomarkdoc

Documentation

Overview

Package list provides an implementation of a doubly-linked list with a front and back. The individual nodes of the list are publicly exposed so that the user can have fine-grained control over the list.

Example
Output:

0
1
2
3

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type List

type List[V any] struct {
	Front, Back *Node[V]
}

List implements a doubly-linked list.

func New

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

New returns an empty linked list.

func (*List[V]) PushBack

func (l *List[V]) PushBack(v V)

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

func (*List[V]) PushBackNode

func (l *List[V]) PushBackNode(n *Node[V])

PushBackNode adds the node 'n' to the back of the list.

func (*List[V]) PushFront

func (l *List[V]) PushFront(v V)

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

func (*List[V]) PushFrontNode

func (l *List[V]) PushFrontNode(n *Node[V])

PushFrontNode adds the node 'n' to the front of the list.

func (*List[V]) Remove

func (l *List[V]) Remove(n *Node[V])

Remove removes the node 'n' from the list.

type Node

type Node[V any] struct {
	Value      V
	Prev, Next *Node[V]
}

Node is a node in the linked list.

func (*Node[V]) Each

func (n *Node[V]) Each(fn func(val V))

Each calls 'fn' on every element from this node onward in the list.

func (*Node[V]) EachReverse

func (n *Node[V]) EachReverse(fn func(val V))

EachReverse calls 'fn' on every element from this node backward in the list.

Jump to

Keyboard shortcuts

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