list

package module
v0.0.0-...-80cf31c Latest Latest
Warning

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

Go to latest
Published: May 11, 2022 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

list provides the List data structure.

A List is a doubly-linked list.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Iterator

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

Iterator provides an iterator over the List type.

func (*Iterator[T]) Next

func (i *Iterator[T]) Next() (*T, error)

Next returns the next item in the iterator over a list. Returns nil, errors.Empty at the end of the iterator.

type List

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

List is the doubly-linked list data structure.

func New

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

New constructs a new List

func (*List[T]) Collect

func (l *List[T]) Collect(items ...T)

Collect appends a variable number of items to the list.

func (*List[T]) Del

func (l *List[T]) Del(index int) (*T, error)

Del removes and returns an element from the list at the specified index. Returns errors.IndexOutOfBounds if index < 0 or index > len(l).

func (*List[T]) Dequeue

func (l *List[T]) Dequeue() (*T, error)

Dequeue removes and returns the first element in the list.

func (*List[T]) Enqueue

func (l *List[T]) Enqueue(elem T)

Enqueue appends an item to the end of the list.

func (*List[T]) FromIterator

func (l *List[T]) FromIterator(iter iterator.Iterator[T]) error

FromIterator collects the items from the iterator into the list.

func (*List[T]) Get

func (l *List[T]) Get(index int) (*T, error)

Get returns a pointer to an item in the List located at index. Returns nil, errors.Empty if the List is empty. Returns nil, errors.IndexOutOfBounds if index < 0 or index > len(l).

func (*List[T]) Ins

func (l *List[T]) Ins(index int, elem T) error

Ins inserts an element into the list at the specified index. Returns errors.IndexOutOfBounds if index < 0 or index > len(l).

func (*List[T]) IntoIterator

func (l *List[T]) IntoIterator() iterator.Iterator[T]

IntoIterator returns an iterator over the items in the list.

func (*List[T]) Peek

func (l *List[T]) Peek() (*T, error)

Peek returns the first element in the list without removing it.

func (*List[T]) PeekBack

func (l *List[T]) PeekBack() (*T, error)

PeekBack returns a pointer to the back of the List. Returns nil, errors.Empty if the List is empty.

func (*List[T]) PeekFront

func (l *List[T]) PeekFront() (*T, error)

PeekFront returns a pointer to the front of the List. Returns nil, errors.Empty if the List is empty.

func (*List[T]) Pop

func (l *List[T]) Pop() (*T, error)

Pop removes and returns the first element in the list.

func (*List[T]) PopBack

func (l *List[T]) PopBack() (*T, error)

PopBack removes and returns an item from the back of the List. Returns nil, errors.Empty if the List is empty.

func (*List[T]) PopFront

func (l *List[T]) PopFront() (*T, error)

PopFront removes and returns an item from the front of the List. Returns nil, errors.Empty if the List is empty.

func (*List[T]) Push

func (l *List[T]) Push(elem T)

Push prepends the list with an element.

func (*List[T]) PushBack

func (l *List[T]) PushBack(item T)

PushBack pushes an item onto the back of the doubly-linked list.

func (*List[T]) PushFront

func (l *List[T]) PushFront(item T)

PushFront pushes an item onto the front of the double-linked list.

func (*List[T]) Set

func (l *List[T]) Set(index int, item T) error

Set sets the item located at index in the List. returns errors.IndexOutOfBounds if index < 0 or index > len(l). Returns errors.Empty if index > 0 and List is empty.

Jump to

Keyboard shortcuts

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