Documentation
¶
Overview ¶
Package vector provides a simple vector implementation.
Index ¶
- func Equal[T comparable](v1, v2 *Vector[T]) bool
- type Vector
- func (v *Vector[T]) All() iter.Seq2[int, T]
- func (v *Vector[T]) Back() (value T, ok bool)
- func (v *Vector[T]) Backward() iter.Seq2[int, T]
- func (v *Vector[T]) Cap() int
- func (v *Vector[T]) Clear()
- func (v *Vector[T]) Clip()
- func (v *Vector[T]) Empty() bool
- func (v *Vector[T]) Front() (value T, ok bool)
- func (v *Vector[T]) Get(i int) (value T, ok bool)
- func (v *Vector[T]) Grow(n int)
- func (v *Vector[T]) Insert(i int, vals ...T)
- func (v *Vector[T]) Len() int
- func (v *Vector[T]) PopBack() (T, bool)
- func (v *Vector[T]) PushBack(val T)
- func (v *Vector[T]) Remove(i int)
- func (v *Vector[T]) RemoveRange(i, j int)
- func (v *Vector[T]) Resize(n int)
- func (v *Vector[T]) Set(i int, value T)
- func (v *Vector[T]) Values() iter.Seq[T]
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Equal ¶
func Equal[T comparable](v1, v2 *Vector[T]) bool
Equal reports whether two vectors are equal.
Types ¶
type Vector ¶
type Vector[T any] struct { // contains filtered or unexported fields }
Vector represent a growable collection of elements that are stored contiguously in memory.
func NewWithCapacity ¶
NewWithCapacity creates and initializes a new Vector with a specified capacity
func (*Vector[T]) Backward ¶
Backward returns an iterator over index-value pairs in the vector, traversing it backward with decreasing indices.
func (*Vector[T]) Cap ¶
Cap returns the number of elements that the vector can hold without further allocation.
func (*Vector[T]) Clip ¶
func (v *Vector[T]) Clip()
Clip reduces the capacity of the vector as much as possible.
func (*Vector[T]) Grow ¶
Grow increases the capacity of the vector, if necessary, to guarantee space for another n elements. After Grow(n), at least n elements can be appended to the vector without another allocation.
If n is negative, Grow panics.
func (*Vector[T]) Insert ¶
Insert inserts the values vals... into v at index i.
Insert panics if i is out of range. This function is O(v.Len() + len(vals))
func (*Vector[T]) PopBack ¶
PopBack removes and returns the last element from the vector. If the vector is empty, it returns a zero value and false.
func (*Vector[T]) PushBack ¶
func (v *Vector[T]) PushBack(val T)
PushBack adds an element to the end of the vector
func (*Vector[T]) Remove ¶
Remove removes the element at index i from v.
Remove panics if i is out of range.
func (*Vector[T]) RemoveRange ¶
RemoveRange removes the elements with indices in range [i, j) from v. Removing an empty range (i >= j) is a no-op.
RemoveRange panics if either i or j is out of range.
func (*Vector[T]) Resize ¶
Resize changes the size of the vector to n. If n is less than the current size, the vector is truncated to the first n elements. If n is greater than the current size, the vector is grown to n elements, with the additional elements initialized to zero.
If n is negative, Resize panics.