vector

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: 4

Documentation

Overview

vector provides the Vector data structure.

A Vector is a slice of contiguous memory. It is implemented as a generic slice type alias. Given that this data structure is held in contiguous memory, careful design is required to use vectors in concurrent applications.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Iterator

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

Iterator provides an iterator over the items in a Vector.

func (*Iterator[T]) Next

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

Next returns the next item in the iterator. This method implements the iterator.Iterator interface. Returns nil, errors.IndexOutOfBounds after the last item.

func (*Iterator[T]) Prev

func (iter *Iterator[T]) Prev() (*T, error)

Prev returns the previous item in the iterator This method implements the iterator.Reverse interface. Returns nil, errors.IndexOutOfBounds after the first item.

type Vector

type Vector[T any] []T

Vector is a slice of contiguous data.

func New

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

New creates a new Vector

func (*Vector[T]) Clear

func (v *Vector[T]) Clear()

Clear sets all items in the vector to T's zero value.

func (*Vector[T]) Collect

func (v *Vector[T]) Collect(elems ...T)

Collect appends the vector with a variable number of items. This method implements the gollections.Collect interface.

func (*Vector[T]) Del

func (v *Vector[T]) Del(i int) (*T, error)

Del removes and returns the element at the specified index, returning errors.IndexOutOfBounds if i < 0 or i > len(v). This method implements part of the gollections.Array interface.

func (*Vector[T]) Dequeue

func (v *Vector[T]) Dequeue() (*T, error)

Dequeue returns and removes an element from the front of the vector. This method implements the gollections.Queue interface.

func (*Vector[T]) Enqueue

func (v *Vector[T]) Enqueue(elem T)

Enqueue appends an element to the back of the vector. This method implements the gollections.Queue interface.

func (*Vector[T]) FromIterator

func (v *Vector[T]) FromIterator(iter iterator.Iterator[T]) error

FromIterator appends the vector with the contents of an iterator. This method implements part of the FromIterator interface.

func (Vector[T]) Get

func (v Vector[T]) Get(i int) (*T, error)

Get returns a pointer to the item at index i. Returns nil, errors.IndexOutOfBounds if i < 0 or i > len(v). This method implements part of the gollections.Array interface.

func (*Vector[T]) Ins

func (v *Vector[T]) Ins(i int, value T) error

Ins inserts an item directly at index i. Returns errors.IndexOutOfBounds if i < 0 or i > len(v). This method implements part of the gollections.Array interface.

func (*Vector[T]) IntoIterator

func (v *Vector[T]) IntoIterator() iterator.Iterator[T]

IntoIterator returns an iterator over the items in the Vector. This method implements the IntoIterator interface.

func (Vector[T]) Peek

func (v Vector[T]) Peek() (*T, error)

Peek returns a pointer to the element at the front of the vector; simply an alias to Front. This method implements part of the gollections.Stack interface.

func (Vector[T]) PeekBack

func (v Vector[T]) PeekBack() (*T, error)

PeekBack returns a pointer to the last item in the vector. Returns nil, errors.Empty if the vector is empty. This method implements part of the gollections.Deque interface.

func (Vector[T]) PeekFront

func (v Vector[T]) PeekFront() (*T, error)

PeekFront returns a pointer to the first item in the vector. Returns nil, errors.Empty if the vector is empty. This method implements part of the gollections.Deque interface.

func (*Vector[T]) Pop

func (v *Vector[T]) Pop() (*T, error)

Pop removes and returns an element from the front of the vector; simply an alias to PopFront. This method implements part of the gollections.Stack interface.

func (*Vector[T]) PopBack

func (v *Vector[T]) PopBack() (*T, error)

PopBack removes and returns an item from the back of the Vector. Returns nil, errors.Empty if the Vector is empty. This method implements part of the gollections.Deque interface.

func (*Vector[T]) PopFront

func (v *Vector[T]) PopFront() (*T, error)

PopFront removes and returns an item from the front of the Vector. Returns nil, errors.Empty if the Vector is empty. This method implements part of the gollections.Deque interface.

func (*Vector[T]) Push

func (v *Vector[T]) Push(elem T)

Push inserts an element at the front of the vector; simply an alias to PushFront. This method implements part of the gollections.Stack interface.

func (*Vector[T]) PushBack

func (v *Vector[T]) PushBack(item T)

PushBack appends the Vector with an item. This method implements part of the gollections.Deque interface.

func (*Vector[T]) PushFront

func (v *Vector[T]) PushFront(item T)

PushFront prepends the Vector with an item. This method implements part of the gollections.Deque interface.

func (*Vector[T]) Reserve

func (v *Vector[T]) Reserve(additional int)

Reserve allocates an additional amount of space in the vector for more elements. The values at these indices are zero-initialized.

func (*Vector[T]) Set

func (v *Vector[T]) Set(i int, value T) error

Set sets the item at index i to value. Returns errors.IndexOutOfBounds if i < 0 or i > len(v). This method implements part of the gollections.Array interface

func (*Vector[T]) Truncate

func (v *Vector[T]) Truncate()

Truncate reconstructs an empty vector.

Jump to

Keyboard shortcuts

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