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 ¶
- type Iterator
- type Vector
- func (v *Vector[T]) Clear()
- func (v *Vector[T]) Collect(elems ...T)
- func (v *Vector[T]) Del(i int) (*T, error)
- func (v *Vector[T]) Dequeue() (*T, error)
- func (v *Vector[T]) Enqueue(elem T)
- func (v *Vector[T]) FromIterator(iter iterator.Iterator[T]) error
- func (v Vector[T]) Get(i int) (*T, error)
- func (v *Vector[T]) Ins(i int, value T) error
- func (v *Vector[T]) IntoIterator() iterator.Iterator[T]
- func (v Vector[T]) Peek() (*T, error)
- func (v Vector[T]) PeekBack() (*T, error)
- func (v Vector[T]) PeekFront() (*T, error)
- func (v *Vector[T]) Pop() (*T, error)
- func (v *Vector[T]) PopBack() (*T, error)
- func (v *Vector[T]) PopFront() (*T, error)
- func (v *Vector[T]) Push(elem T)
- func (v *Vector[T]) PushBack(item T)
- func (v *Vector[T]) PushFront(item T)
- func (v *Vector[T]) Reserve(additional int)
- func (v *Vector[T]) Set(i int, value T) error
- func (v *Vector[T]) Truncate()
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Iterator ¶
Iterator provides an iterator over the items in a Vector.
type Vector ¶
type Vector[T any] []T
Vector is a slice of contiguous data.
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 ¶
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 ¶
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 ¶
FromIterator appends the vector with the contents of an iterator. This method implements part of the FromIterator interface.
func (Vector[T]) Get ¶
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 ¶
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 ¶
IntoIterator returns an iterator over the items in the Vector. This method implements the IntoIterator interface.
func (Vector[T]) Peek ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
Reserve allocates an additional amount of space in the vector for more elements. The values at these indices are zero-initialized.