vector

package
v0.0.10 Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AggregateError added in v0.0.8

func AggregateError(errVector ErrVector, sep string) error

func Copy added in v0.0.5

func Copy[T any](dst *Vector[T], src Vector[T]) int

func CopyAt added in v0.0.5

func CopyAt[T any](dst *Vector[T], src Vector[T], at int) int

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 DedupInplaceBy[T any](vec *Vector[T], cmp func(lhs T, rhs T) bool)

func DedupInplaceByKey added in v0.0.5

func DedupInplaceByKey[T any, K comparable](vec *Vector[T], key func(T) K)

func Fold added in v0.0.5

func Fold[T any](vec Vector[T], init T, f func(acc T, elem T) T) T

func Fold2 added in v0.0.5

func Fold2[T, P any](vec Vector[T], init P, f func(acc P, elem T) P) P

func MapWithErrors added in v0.0.8

func MapWithErrors[T any, R any](vec Vector[T], f func(T) (R, error)) (Vector[R], Vector[error])

func Sort added in v0.0.5

func Sort[T constraints.Ordered](vec *Vector[T])

func SortBy added in v0.0.7

func SortBy[T constraints.Ordered](vec *Vector[T], less func(a, b int) bool)

Types

type AggregatedError added in v0.0.8

type AggregatedError struct {
	// contains filtered or unexported fields
}

func (AggregatedError) Error added in v0.0.8

func (e AggregatedError) Error() string

type ErrVector added in v0.0.8

type ErrVector = Vector[error]

type Vector

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

func Chunks added in v0.0.5

func Chunks[T any](vec Vector[T], size int) (Vector[*Vector[T]], error)

func Concat added in v0.0.5

func Concat[T any](head Vector[T], tails ...Vector[T]) Vector[T]

func Cycle added in v0.0.5

func Cycle[T any](vec Vector[T], num int) Vector[T]

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 DedupBy added in v0.0.5

func DedupBy[T any](vec Vector[T], cmp func(lhs T, rhs T) bool) Vector[T]

func DedupByKey added in v0.0.5

func DedupByKey[T any, K comparable](vec Vector[T], key func(T) K) Vector[T]

func FromSlice

func FromSlice[T any](xs []T) Vector[T]

func FromValues

func FromValues[T any](xs ...T) Vector[T]

func Map

func Map[T any, R any](vec Vector[T], f func(T) R) Vector[R]

func MapFilter

func MapFilter[T any, R any](vec Vector[T], f func(T) option.Option[R]) Vector[R]

func Repeat added in v0.0.5

func Repeat[T any](init T, num int) Vector[T]

func Window added in v0.0.5

func Window[T any](vec Vector[T], size int) (Vector[*Vector[T]], error)

func WithCapacity

func WithCapacity[T any](cap int) Vector[T]

func (*Vector[T]) Back added in v0.0.5

func (vec *Vector[T]) Back() T

Back does not perform boundary check

func (*Vector[T]) Capacity

func (vec *Vector[T]) Capacity() int

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]) Empty

func (vec *Vector[T]) Empty() bool

func (*Vector[T]) Extend added in v0.0.5

func (vec *Vector[T]) Extend(other Vector[T])

func (*Vector[T]) ExtendBy added in v0.0.5

func (vec *Vector[T]) ExtendBy(elem T, num int)

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

func (vec *Vector[T]) FillRange(x T, from int, to int)

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]) ForEach

func (vec *Vector[T]) ForEach(f func(T))

func (*Vector[T]) Get added in v0.0.5

func (vec *Vector[T]) Get(i int) T

Get does not perform boundary check

func (Vector[T]) Head added in v0.0.5

func (vec Vector[T]) Head() option.Option[T]

func (*Vector[T]) Insert added in v0.0.5

func (vec *Vector[T]) Insert(idx int, x T)

Insert inserts an element at position, shifting all the elements after it to the right

func (*Vector[T]) Partition added in v0.0.5

func (vec *Vector[T]) Partition(f func(elem T) bool) int

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]) Push

func (vec *Vector[T]) Push(x T)

func (*Vector[T]) Reserve

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

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]) Set added in v0.0.5

func (vec *Vector[T]) Set(i int, x T)

Set does not perform boundary check

func (*Vector[T]) ShiftLeft added in v0.0.5

func (vec *Vector[T]) ShiftLeft(distance uint)

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

func (vec *Vector[T]) ShiftRangeLeft(position uint, distance uint)

ShiftRangeLeft moves all the elements within range [position, size) to the left

func (*Vector[T]) ShiftRangeRight added in v0.0.5

func (vec *Vector[T]) ShiftRangeRight(position int, distance uint)

func (*Vector[T]) ShrinkToFit

func (vec *Vector[T]) ShrinkToFit()

func (*Vector[T]) Size

func (vec *Vector[T]) Size() int

func (*Vector[T]) Swap added in v0.0.5

func (vec *Vector[T]) Swap(i int, j int)

Swap does not perform boundary check

func (Vector[T]) Tail added in v0.0.5

func (vec Vector[T]) Tail() Vector[T]

func (Vector[T]) ToSlice

func (vec Vector[T]) ToSlice() []T

func (*Vector[T]) TryPop

func (vec *Vector[T]) TryPop() option.Option[T]

Jump to

Keyboard shortcuts

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