Skip to content

Latest commit

 

History

History
 
 

list

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

list

import "github.com/zyedidia/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/zyedidia/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