linked

package
v0.0.0-...-6dfbae8 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2024 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package linked contains an implementation of a doubly-linked circular list.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Index

func Index[T comparable](l *Linked[T], v T) int

Index returns the index of the first element with value v, or -1 if not present.

Types

type Element

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

Element represents an element of the list.

func Find

func Find[T comparable](l *Linked[T], v T) (*Element[T], bool)

Find returns the first element with the value v, or nil if not present. The second parameter is true if the element is found; otherwise, it is false.

func (*Element[T]) Next

func (e *Element[T]) Next() *Element[T]

Next returns the next element or nil.

func (*Element[T]) Prev

func (e *Element[T]) Prev() *Element[T]

Prev returns the previous element or nil.

type Iterator

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

Iterator is an iterator for a linked list.

func (*Iterator[T]) Next

func (i *Iterator[T]) Next() *Element[T]

Next returns the next element or nil.

func (*Iterator[T]) Prev

func (i *Iterator[T]) Prev() *Element[T]

Prev returns the previous element or nil.

type Linked

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

Linked represents a doubly-linked circular list.

func New

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

New returns an initialized list.

func (*Linked[T]) At

func (l *Linked[T]) At(ind int) (*Element[T], error)

At returns an element at index ind.

func (*Linked[T]) Back

func (l *Linked[T]) Back() *Element[T]

Back returns the last element of the list or nil if the list is empty.

func (*Linked[T]) Empty

func (l *Linked[T]) Empty() bool

Empty returns whether the list is empty.

func (*Linked[T]) Front

func (l *Linked[T]) Front() *Element[T]

Front returns the first element of the list or nil if the list is empty.

func (*Linked[T]) InsertAfter

func (l *Linked[T]) InsertAfter(v T, p *Element[T]) *Element[T]

InsertAfter inserts a new element with value v immediately after p and returns e. If p is not an element of the list l, nil is returned.

func (*Linked[T]) InsertBack

func (l *Linked[T]) InsertBack(v T) *Element[T]

InsertBack inserts a new element e with value v at the back of the list and returns e.

func (*Linked[T]) InsertBefore

func (l *Linked[T]) InsertBefore(v T, p *Element[T]) *Element[T]

InsertBefore inserts a new element with value v immediately before p and returns e. If p is not an element of the list l, nil is returned.

func (*Linked[T]) InsertFront

func (l *Linked[T]) InsertFront(v T) *Element[T]

InsertFront inserts a new element e with value v at the front of the list and returns e.

func (*Linked[T]) Iter

func (l *Linked[T]) Iter() Iterator[T]

Iter returns an iterator pointing at the first element.

func (*Linked[T]) Len

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

Len returns the number of elements in the list.

func (*Linked[T]) Remove

func (l *Linked[T]) Remove(e *Element[T])

Remove removes element e from list l if e is an element of list l.

Jump to

Keyboard shortcuts

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