vec

package
v0.0.0-...-7a9c835 Latest Latest
Warning

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

Go to latest
Published: May 7, 2024 License: MIT Imports: 3 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Vec

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

func New

func New[T any](conf ...VecConf[T]) *Vec[T]

func (*Vec[T]) BinarySearch

func (v *Vec[T]) BinarySearch(target T) (int, bool)

BinarySearch searches for target in a sorted slice and returns the position where target is found, or the position where target would appear in the sort order;

it also returns a bool saying whether the target is really found in the slice.

The slice must be sorted in increasing order.

func (*Vec[T]) BinarySearchFunc

func (v *Vec[T]) BinarySearchFunc(target T, cmp func(val T, target T) int) (int, bool)

func (*Vec[T]) Cap

func (v *Vec[T]) Cap() int

func (*Vec[T]) Clear

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

Clear the vector and shrink 1/4 the capacity.

func (*Vec[T]) Clip

func (v *Vec[T]) Clip() *Vec[T]

Clip removes unused capacity

func (*Vec[T]) Clone

func (v *Vec[T]) Clone() *Vec[T]

func (*Vec[T]) CloneToSlice

func (v *Vec[T]) CloneToSlice() []T

func (*Vec[T]) CmpEqual

func (v *Vec[T]) CmpEqual(v1, v2 T) bool

func (*Vec[T]) CmpLess

func (v *Vec[T]) CmpLess(v1, v2 T) bool

func (*Vec[T]) Compact

func (v *Vec[T]) Compact() *Vec[T]

Compact removes all identical adjacent elements. Only the first element of each group of equal elements is preserved. Must be sorted, Called after sorting.

func (*Vec[T]) CompactFunc

func (v *Vec[T]) CompactFunc(eq func(T, T) bool)

Compact removes all identical adjacent elements. Only the first element of each group of equal elements is preserved. Must be sorted, Called after sorting.

func (*Vec[T]) Compare

func (v *Vec[T]) Compare(other Vec[T]) int

returns 0 the result is 0 if len(s1) == len(s2), -1 if len(s1) < len(s2), and +1 if len(s1) > len(s2).

func (*Vec[T]) CompareFunc

func (v *Vec[T]) CompareFunc(other Vec[T], cmpLess, cmpEqual func(T, T) bool) int

func (*Vec[T]) ConpareAndRemove

func (v *Vec[T]) ConpareAndRemove(i int, val T) (e T, ok bool)

ConpareAndRemove removes the element at index i if it is equal to val.

func (*Vec[T]) Contains

func (v *Vec[T]) Contains(val T) bool

func (*Vec[T]) ContainsFunc

func (v *Vec[T]) ContainsFunc(cmp func(v T) (matched bool)) bool

func (*Vec[T]) Cut

func (v *Vec[T]) Cut(i, j int) (e []T)

Cut removes the elements in the interval [i, j).

func (*Vec[T]) Delete

func (v *Vec[T]) Delete(i, j int)

func (*Vec[T]) Equal

func (v *Vec[T]) Equal(i, j int) bool

func (*Vec[T]) EqualSlice

func (v *Vec[T]) EqualSlice(other []T) bool

func (*Vec[T]) EqualSliceFunc

func (v *Vec[T]) EqualSliceFunc(other []T, eq func(T, T) bool) bool

func (*Vec[T]) EqualVec

func (v *Vec[T]) EqualVec(other Vec[T]) bool

func (*Vec[T]) EqualVecFunc

func (v *Vec[T]) EqualVecFunc(other Vec[T], eq func(T, T) bool) bool

func (*Vec[T]) First

func (v *Vec[T]) First() (e T, ok bool)

func (*Vec[T]) Get

func (v *Vec[T]) Get(i int) (e T, ok bool)

func (*Vec[T]) Grow

func (v *Vec[T]) Grow(n int) *Vec[T]

After Grow(n), at least n elements can be appended to the slice without another allocation.

func (*Vec[T]) Insert

func (v *Vec[T]) Insert(i int, val ...T) *Vec[T]

Insert into constraints.Ordered position.

if i < 0 or i out of range, panic.

func (*Vec[T]) IsEmpty

func (v *Vec[T]) IsEmpty() bool

func (*Vec[T]) IsSorted

func (v *Vec[T]) IsSorted() bool

func (*Vec[T]) IsSortedFunc

func (v *Vec[T]) IsSortedFunc(cmpLess, cmpEqual func(T, T) bool) bool

func (*Vec[T]) Last

func (v *Vec[T]) Last() (e T, ok bool)

func (*Vec[T]) Len

func (v *Vec[T]) Len() int

func (*Vec[T]) Less

func (v *Vec[T]) Less(i, j int) bool

func (*Vec[T]) Max

func (v *Vec[T]) Max() T

func (*Vec[T]) MaxFunc

func (v *Vec[T]) MaxFunc(cmpLess, cmpEqual func(T, T) bool) T

func (*Vec[T]) Min

func (v *Vec[T]) Min() T

func (*Vec[T]) MinFunc

func (v *Vec[T]) MinFunc(cmpLess, cmpEqual func(T, T) bool) T

func (*Vec[T]) Pop

func (v *Vec[T]) Pop() (e T, ok bool)

Pop removes the last element and returns it.

func (*Vec[T]) Push

func (v *Vec[T]) Push(val ...T) *Vec[T]

Push appends an element to the end.

func (*Vec[T]) Range

func (v *Vec[T]) Range(cbk func(i int, val T) (Continue bool))

func (*Vec[T]) Remove

func (v *Vec[T]) Remove(i int) (e T, ok bool)

func (*Vec[T]) Replace

func (v *Vec[T]) Replace(i int, j int, val ...T)

func (*Vec[T]) Reverse

func (v *Vec[T]) Reverse() *Vec[T]

Reverse reverses the elements of the vec in place.

func (*Vec[T]) Search

func (v *Vec[T]) Search(target T) (index int)

func (*Vec[T]) SearchAll

func (v *Vec[T]) SearchAll(target T) (indexs []int)

func (*Vec[T]) SearchAllFunc

func (v *Vec[T]) SearchAllFunc(cbk func(v T) (Matched bool)) (indexs []int)

func (*Vec[T]) SearchFunc

func (v *Vec[T]) SearchFunc(cbk func(v T) (Matched bool)) (index int)

func (*Vec[T]) Set

func (v *Vec[T]) Set(i int, val T) (ok bool)

func (*Vec[T]) SetCmpEqual

func (v *Vec[T]) SetCmpEqual(cmpEqual func(T, T) bool) *Vec[T]

func (*Vec[T]) SetCmpLess

func (v *Vec[T]) SetCmpLess(cmpLess func(T, T) bool) *Vec[T]

func (*Vec[T]) Slice

func (v *Vec[T]) Slice() []T

func (*Vec[T]) SliceCut

func (v *Vec[T]) SliceCut(i, j int) []T

SliceCut returns a slice of the vector.

func (*Vec[T]) Sort

func (v *Vec[T]) Sort() *Vec[T]

Sort sorts a vec of any ordered type in ascending order.

When sorting floating-point numbers, NaNs are ordered before other values.

func (*Vec[T]) SortFunc

func (v *Vec[T]) SortFunc(cmpLess, cmpEqual func(T, T) bool) *Vec[T]

func (*Vec[T]) SortStable

func (v *Vec[T]) SortStable() *Vec[T]

SortStableFunc sorts the vec x while keeping the original order of equal elements, using cmp to compare elements in the same way as SortFunc.

func (*Vec[T]) SortStableFunc

func (v *Vec[T]) SortStableFunc(cmpLess, cmpEqual func(T, T) bool) *Vec[T]

func (*Vec[T]) SplitOff

func (v *Vec[T]) SplitOff(i int) *Vec[T]

SplitOff splits the vector into two at the given index.

if i < 0 or i out of range, return false.

data dont overwrite each other.

func (*Vec[T]) Swap

func (v *Vec[T]) Swap(i, j int)

type VecConf

type VecConf[T any] func(v *Vec[T])

func WithCmpEqual

func WithCmpEqual[T any](cmpEqual func(v1, v2 T) bool) VecConf[T]

func WithCmpLess

func WithCmpLess[T any](cmpLess func(v1, v2 T) bool) VecConf[T]

Jump to

Keyboard shortcuts

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