Documentation ¶
Index ¶
- func Copy[T any](dst *Vector[T], src Vector[T]) int
- func CopyAt[T any](dst *Vector[T], src Vector[T], at int) int
- func DedupInplace[T comparable](vec *Vector[T])
- func DedupInplaceBy[T any](vec *Vector[T], cmp func(lhs T, rhs T) bool)
- func DedupInplaceByKey[T any, K comparable](vec *Vector[T], key func(T) K)
- func Fold[T any](vec Vector[T], init T, f func(acc T, elem T) T) T
- func Fold2[T, P any](vec Vector[T], init P, f func(acc P, elem T) P) P
- func Sort[T constraints.Ordered](vec *Vector[T])
- type Vector
- func Chunks[T any](vec Vector[T], size int) (Vector[*Vector[T]], error)
- func Concat[T any](head Vector[T], tails ...Vector[T]) Vector[T]
- func Cycle[T any](vec Vector[T], num int) Vector[T]
- func Dedup[T comparable](vec Vector[T]) Vector[T]
- func DedupBy[T any](vec Vector[T], cmp func(lhs T, rhs T) bool) Vector[T]
- func DedupByKey[T any, K comparable](vec Vector[T], key func(T) K) Vector[T]
- func FromSlice[T any](xs []T) Vector[T]
- func FromValues[T any](xs ...T) Vector[T]
- func Map[T any, R any](vec Vector[T], f func(T) R) Vector[R]
- func MapFilter[T any, R any](vec Vector[T], f func(T) option.Option[R]) Vector[R]
- func Repeat[T any](init T, num int) Vector[T]
- func Window[T any](vec Vector[T], size int) (Vector[*Vector[T]], error)
- func WithCapacity[T any](cap int) Vector[T]
- func (vec *Vector[T]) Back() T
- func (vec *Vector[T]) Capacity() int
- func (vec *Vector[T]) Clear()
- func (vec *Vector[T]) Empty() bool
- func (vec *Vector[T]) Extend(other Vector[T])
- func (vec *Vector[T]) ExtendBy(elem T, num int)
- func (vec *Vector[T]) Fill(x T)
- func (vec *Vector[T]) FillRange(x T, from int, to int)
- func (vec *Vector[T]) ForEach(f func(T))
- func (vec *Vector[T]) Get(i int) T
- func (vec Vector[T]) Head() option.Option[T]
- func (vec *Vector[T]) Insert(idx int, x T)
- func (vec *Vector[T]) Partition(f func(elem T) bool) int
- func (vec *Vector[T]) Pop() T
- func (vec *Vector[T]) Push(x T)
- func (vec *Vector[T]) Reserve(additional int)
- func (vec *Vector[T]) ResetSize()
- func (vec *Vector[T]) Set(i int, x T)
- func (vec *Vector[T]) ShiftLeft(distance uint)
- func (vec *Vector[T]) ShiftRangeLeft(position uint, distance uint)
- func (vec *Vector[T]) ShiftRangeRight(position int, distance uint)
- func (vec *Vector[T]) ShrinkToFit()
- func (vec *Vector[T]) Size() int
- func (vec *Vector[T]) Swap(i int, j int)
- func (vec Vector[T]) Tail() Vector[T]
- func (vec Vector[T]) ToSlice() []T
- func (vec *Vector[T]) TryPop() option.Option[T]
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DedupInplace ¶ added in v0.0.5
func DedupInplace[T comparable](vec *Vector[T])
DedupInplace will modify the given vector
func DedupInplaceBy ¶ added in v0.0.5
func DedupInplaceByKey ¶ added in v0.0.5
func DedupInplaceByKey[T any, K comparable](vec *Vector[T], key func(T) K)
func Sort ¶ added in v0.0.5
func Sort[T constraints.Ordered](vec *Vector[T])
Types ¶
type Vector ¶
type Vector[T any] struct { // contains filtered or unexported fields }
func Dedup ¶ added in v0.0.5
func Dedup[T comparable](vec Vector[T]) Vector[T]
Dedup removes the duplicate contiguous elements, e.g. [1, 2, 2, 2, 3, 3, 4] dedup to: [1, 2, 3, 4] but for [1, 2, 3, 2, 3, 2] dedup has no effect
func DedupByKey ¶ added in v0.0.5
func DedupByKey[T any, K comparable](vec Vector[T], key func(T) K) Vector[T]
func FromValues ¶
func WithCapacity ¶
func (*Vector[T]) Back ¶ added in v0.0.5
func (vec *Vector[T]) Back() T
Back does not perform boundary check
func (*Vector[T]) Clear ¶ added in v0.0.5
func (vec *Vector[T]) Clear()
Clear deallocate all the elements and reset the vector size to 0; Slower than ResetSize, but sometimes can be the desirable option.
func (*Vector[T]) Fill ¶ added in v0.0.5
func (vec *Vector[T]) Fill(x T)
Fill sets every element in the vector to x
func (*Vector[T]) FillRange ¶ added in v0.0.5
FillRange sets the elements in the given range to x If the given range is out of bound, it adjusts it to within [0, size) Note the range is exclusive: [from, to)
func (*Vector[T]) Insert ¶ added in v0.0.5
Insert inserts an element at position, shifting all the elements after it to the right
func (*Vector[T]) Partition ¶ added in v0.0.5
Partition changes the positions of the elements in the given vector: those that pass f are moved to the head positions; those that fail to the tail positions. Partition is NOT stable - it doesn't maintain the element order in each partition. Returns the partition cursor: the index of the first element of the second partition, (it contains all the elements failing f)
func (*Vector[T]) Pop ¶ added in v0.0.5
func (vec *Vector[T]) Pop() T
Pop will panic if the vector is empty
func (*Vector[T]) ResetSize ¶ added in v0.0.5
func (vec *Vector[T]) ResetSize()
ResetSize resets the vector size to 0 (effectively making all the elements unavailable) It will not cause deallocation (i.e., it is faster than deallocation, aka Clear()) To trigger the deletion of all the elements (GC), use Clear()
func (*Vector[T]) ShiftLeft ¶ added in v0.0.5
ShiftLeft moves all the elements to the left, e.g. given [1, 2, 3], distance = 3 result in [0, 0, 0, 1, 2, 3] * the original positions are filled by the default value of T
func (*Vector[T]) ShiftRangeLeft ¶ added in v0.0.5
ShiftRangeLeft moves all the elements within range [position, size) to the left
func (*Vector[T]) ShiftRangeRight ¶ added in v0.0.5
func (*Vector[T]) ShrinkToFit ¶
func (vec *Vector[T]) ShrinkToFit()