Documentation ¶
Index ¶
- Constants
- func BinarySearch[V constraints.Ordered](arr []constraints2.CompareKey[V], x constraints2.CompareKey[V]) int
- func Cast[T1S ~[]T1, T2S ~[]T2, T1, T2 any](s T1S) T2S
- func Classify[S ~[]T, T any, K comparable, V any](s S, getKV func(T) (K, V)) map[K][]V
- func Contains[S ~[]T, T comparable](s S, v T) booldeprecated
- func ContainsByKey[S ~[]E, E cmp.EqualKey[K], K comparable](s S, v K) bool
- func Copy[S ~[]T, T any](s S) S
- func Deduplicate[S ~[]T, T comparable](slice S) S
- func Difference[S ~[]T, T comparable](a, b S) (S, S)
- func DifferenceByKey[S ~[]E, E cmp.EqualKey[T], T comparable](a, b S) (S, S)
- func DifferenceSet[S ~[]T, T comparable](a S, b S) S
- func DifferenceSetByKey[S ~[]E, E cmp.EqualKey[T], T comparable](a S, b S) S
- func Every[S ~[]T, T any](slice S, fn func(T) bool) bool
- func Filter[S ~[]T, T any](fn func(T) bool, src S) S
- func FilterPlace[S ~[]T, T any](slices S, fn func(T) bool) S
- func ForEach[S ~[]T, T any](s S, handle func(idx int, v T))
- func ForEachIndex[S ~[]T, T any](s S, handle func(i int))
- func ForEachValue[S ~[]T, T any](s S, handle func(v T))
- func GrowSlice(et *reflect.Type, old reflect.Slice, cap int) reflect.Slice
- func GuardSlice(buf *[]byte, n int)
- func HasCoincide[S ~[]T, T comparable](s1, s2 S) bool
- func HasCoincideByKey[S ~[]E, E cmp.EqualKey[T], T comparable](s1, s2 S) bool
- func Intersection[S ~[]T, T comparable](a S, b S) S
- func IntersectionByKey[S ~[]E, E cmp.EqualKey[T], T comparable](a S, b S) S
- func IntersectionMap[S ~[]T, T comparable](a S, b S) map[T]struct{}
- func Map[T1S ~[]T1, T1, T2 any](s T1S, fn func(T1) T2) []T2
- func Max[S ~[]T, T constraints.Ordered](s S) T
- func Mean[S ~[]T, T constraints.Number](data S) float64
- func Median[S ~[]T, T constraints.Number](data S) T
- func Min[S ~[]T, T constraints.Ordered](s S) T
- func OrderIterBy[S ~[]T, T any](s S, cmp types.Comparator[T]) iter.Seq[T]
- func OrderedArrayIntersection[S ~[]T, T constraints.Ordered](a S, b S) S
- func PtrToSlicePtr(s unsafe.Pointer, l int, c int) unsafe.Pointer
- func Reduce[S ~[]T, T any](slices S, fn func(T, T) T) T
- func Remove[S ~[]T, T any](slices S, i int) S
- func RemoveDuplicates[S ~[]T, T comparable](s S) S
- func RemoveDuplicatesByKey[S ~[]E, E cmp.EqualKey[T], T comparable](s S) S
- func RemoveDuplicatesByKeyRetainBehind[S ~[]E, E cmp.EqualKey[T], T comparable](s S) S
- func RemoveOutliersMean[S ~[]T, T constraints.Number](data S) float64
- func Reverse[S ~[]T, T any](s S) S
- func ReverseForEach[S ~[]T, T any](s S, handle func(idx int, v T))
- func Some[S ~[]T, T any](slice S, fn func(T) bool) bool
- func Swap[S ~[]T, T any](s S, i, j int)
- func ThreeDimensionalSlice[S ~[][][]T, T any](s S, rowStart, rowEnd, colStart, colEnd, sliceStart, sliceEnd int) S
- func ToMap[S ~[]T, T any, K comparable, V any](s S, getKV func(T) (K, V)) map[K]V
- func ToPtrs[S ~[]T, T any](s S) []*T
- func TwoDimensionalSlice[S ~[][]T, T any](s S, rowStart, rowEnd, colStart, colEnd int) S
- func Union[S ~[]T, T comparable](a S, b S) S
- func UnionAndIntersectionAndDifference[S ~[]T, T comparable](a, b S) (S, S, S, S)
- func UnionByKey[S ~[]E, E cmp.EqualKey[T], T comparable](a S, b S) S
- func Zip[S ~[]T, T any](s1, s2 S) [][2]T
- type Collector
Constants ¶
View Source
const SmallArrayLen = 32
Variables ¶
This section is empty.
Functions ¶
func BinarySearch ¶
func BinarySearch[V constraints.Ordered](arr []constraints2.CompareKey[V], x constraints2.CompareKey[V]) int
BinarySearch 二分查找
func Classify ¶
func Classify[S ~[]T, T any, K comparable, V any](s S, getKV func(T) (K, V)) map[K][]V
将切片按照某个key分类
func Contains
deprecated
func Contains[S ~[]T, T comparable](s S, v T) bool
Deprecated: use std slices.Contains
func ContainsByKey ¶
func ContainsByKey[S ~[]E, E cmp.EqualKey[K], K comparable](s S, v K) bool
func DifferenceByKey ¶
func DifferenceByKey[S ~[]E, E cmp.EqualKey[T], T comparable](a, b S) (S, S)
取差集,通过循环比较key
func DifferenceSetByKey ¶
func DifferenceSetByKey[S ~[]E, E cmp.EqualKey[T], T comparable](a S, b S) S
指定key取差集,返回为A-B
func FilterPlace ¶ added in v0.1.12
func ForEachValue ¶
func ForEachValue[S ~[]T, T any](s S, handle func(v T))
func GuardSlice ¶
func HasCoincide ¶
func HasCoincide[S ~[]T, T comparable](s1, s2 S) bool
没有泛型,范例,实际需根据不同类型各写一遍,用CmpKey,基本类型又用不了,go需要能给基本类型实现方法不能给外部类型实现方法 1.20以后字段均是comparable的结构体也是comparable的 判断是否有重合元素
func HasCoincideByKey ¶
func HasCoincideByKey[S ~[]E, E cmp.EqualKey[T], T comparable](s1, s2 S) bool
func IntersectionByKey ¶
func IntersectionByKey[S ~[]E, E cmp.EqualKey[T], T comparable](a S, b S) S
默认保留前一个的,靠前的元素
func IntersectionMap ¶
func IntersectionMap[S ~[]T, T comparable](a S, b S) map[T]struct{}
func Max ¶
func Max[S ~[]T, T constraints.Ordered](s S) T
func Mean ¶ added in v0.3.1
func Mean[S ~[]T, T constraints.Number](data S) float64
Calculate the Mean of a slice of floats
func Median ¶ added in v0.3.1
func Median[S ~[]T, T constraints.Number](data S) T
Calculate the Median of a slice of floats
func Min ¶
func Min[S ~[]T, T constraints.Ordered](s S) T
func OrderIterBy ¶ added in v0.3.4
func OrderIterBy[S ~[]T, T any](s S, cmp types.Comparator[T]) iter.Seq[T]
func OrderedArrayIntersection ¶
func OrderedArrayIntersection[S ~[]T, T constraints.Ordered](a S, b S) S
有序数组取交集
func PtrToSlicePtr ¶ added in v0.3.1
func RemoveDuplicates ¶
func RemoveDuplicates[S ~[]T, T comparable](s S) S
func RemoveDuplicatesByKey ¶
func RemoveDuplicatesByKey[S ~[]E, E cmp.EqualKey[T], T comparable](s S) S
默认保留先遍历到的
func RemoveDuplicatesByKeyRetainBehind ¶
func RemoveDuplicatesByKeyRetainBehind[S ~[]E, E cmp.EqualKey[T], T comparable](s S) S
func RemoveOutliersMean ¶ added in v0.3.1
func RemoveOutliersMean[S ~[]T, T constraints.Number](data S) float64
Remove outliers using the MAD method and calculate the Mean of the remaining data
func ReverseForEach ¶
func ThreeDimensionalSlice ¶ added in v0.3.1
func ToMap ¶
func ToMap[S ~[]T, T any, K comparable, V any](s S, getKV func(T) (K, V)) map[K]V
将切片转换为map
func TwoDimensionalSlice ¶ added in v0.3.1
func UnionAndIntersectionAndDifference ¶
func UnionAndIntersectionAndDifference[S ~[]T, T comparable](a, b S) (S, S, S, S)
交集和差集,返回A∪B A∩B,A-B,B-A
Types ¶
Click to show internal directories.
Click to hide internal directories.