hs

package
v0.14.4 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2025 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func At

func At[T any](values []T, at int) T

func Eq

func Eq[T comparable](a, b T) bool

func Loc

func Loc[T any](values []T, start int, end int) []T

Loc return a slice from values, it accept negative index for start and end.

Loc([1,2,3], 1, -1) --> return [2]

if end is too large, it is equivlent to the len(values).

Types

type Vec

type Vec[T any] []T

Vec is simpler slice, mostly you don't need this.

Use *Vec instead of Vec

The zero value is hard to use thus...

func Make

func Make[T any](len, cap int) *Vec[T]

func New

func New[T any](data []T) *Vec[T]

func NewWith

func NewWith[T any](data ...T) *Vec[T]

func Repeat

func Repeat[T any](v T, count int) *Vec[T]

func (*Vec[T]) Append

func (v *Vec[T]) Append(data ...T) *Vec[T]

func (*Vec[T]) At

func (v *Vec[T]) At(index int) T

At is similar to Get but accept negative index. -1 will locate the last element.

func (*Vec[T]) BinarySearch

func (v *Vec[T]) BinarySearch(target T, cmp func(a, b T) int) (pos int, ok bool)

BinarySearch searches for target in a sorted slice and returns the earliest position where target is found.

For more detail see: slices.BinarySearch

func (*Vec[T]) Clone

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

func (*Vec[T]) Data

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

func (*Vec[T]) Equal

func (v *Vec[T]) Equal(other *Vec[T], eq func(a T, b T) bool) bool

Equal compare each element, and return true if all the same. use hs.Eq for convenience.

func (*Vec[T]) Get

func (v *Vec[T]) Get(index int) T

func (*Vec[T]) IsSorted

func (v *Vec[T]) IsSorted(cmp func(a T, b T) int) bool

func (*Vec[T]) Len

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

func (*Vec[T]) Loc

func (v *Vec[T]) Loc(start, end int) *Vec[T]

Loc return the sub slice from the original vec.

func (*Vec[T]) Pipe

func (v *Vec[T]) Pipe(fn func(T) (T, bool)) *Vec[T]

Pipe create a new Vec, the new element depends on the results of fn

func (*Vec[T]) Reduce

func (v *Vec[T]) Reduce(initial T, fn func(a, b T) T) T

func (*Vec[T]) Reverse

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

Reverse reverses the elements of the slice in place.

func (*Vec[T]) Seq

func (v *Vec[T]) Seq() iter.Seq[T]

func (*Vec[T]) Set

func (v *Vec[T]) Set(i int, value T)

func (*Vec[T]) Slice deprecated

func (v *Vec[T]) Slice(start, end int) *Vec[T]

Slice is just an alias to Loc.

Deprecated: use Loc as it is shorter.

func (*Vec[T]) Sort

func (v *Vec[T]) Sort(cmp func(a T, b T) int) *Vec[T]

Sort sorts the slice x in ascending order as determined by the cmp function.

Jump to

Keyboard shortcuts

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