Documentation ¶
Index ¶
- Constants
- func BinarySearch[V constraints.Ordered](arr []constraints2.OrderKey[V], x constraints2.OrderKey[V]) int
- func Contains[S ~[]V, V comparable](slices S, v V) bool
- func Deduplicate[S ~[]T, T comparable](slices S) S
- func Difference[S ~[]T, T comparable](a, b S) (S, S)
- func DifferenceByKey[S ~[]_interface.CmpKey[T], T comparable](a, b S) (S, S)
- func DifferenceSet[S ~[]T, T comparable](a S, b S) S
- func DifferenceSetByKey[S ~[]_interface.CmpKey[T], T comparable](a S, b S) S
- func ForEach[S ~[]V, V any](slices S, handle func(idx int, v V))
- func ForEachIndex[S ~[]V, V any](slices S, handle func(i int))
- func ForEachValue[S ~[]V, V any](slices S, handle func(v V))
- func HasCoincide[S ~[]T, T comparable](s1, s2 S) bool
- func HasCoincideByKey[S ~[]_interface.CmpKey[T], T comparable](s1, s2 S) bool
- func In[S ~[]V, V comparable](v V, slices S) bool
- func InByKey[S ~[]constraints.CmpKey[K], K comparable](key K, slices S) bool
- func Intersection[S ~[]T, T comparable](a S, b S) S
- func IntersectionAndDifference[S ~[]T, T comparable](a, b S) (S, S, S)
- func IntersectionByKey[S ~[]_interface.CmpKey[T], T comparable](a S, b S) S
- func IntersectionMap[S ~[]T, T comparable](a S, b S) map[T]struct{}
- func Join[S ~[]V, V any](slices S, toString func(v V) string, sep string) string
- func JoinByIndex[S ~[]V, V any](slices S, toString func(i int) string, sep string) string
- func Map[S ~[]T, T any, V any](slices S, fn func(T) V) []V
- func Max[S ~[]T, T constraints.Number](slices S) T
- func Min[S ~[]T, T constraints.Number](slices S) T
- func OrderedArrayIntersection[S ~[]T, T constraints.Ordered](a S, b S) S
- func Reduce[S ~[]T, T any](slices S, fn func(T, T) T) T
- func RemoveDuplicates[S ~[]T, T comparable](s S) S
- func RemoveDuplicatesByKey[S ~[]_interface.CmpKey[T], T comparable](s S) S
- func Reverse[S ~[]T, T any](slices S) S
- func ReverseForEach[S ~[]V, V any](slices S, handle func(idx int, v V))
- func SlicesClassify[S ~[]T, T any, K comparable, V any](slices S, getKV func(T) (K, V)) map[K][]V
- func SlicesToMap[S ~[]T, T any, K comparable, V any](slices S, getKV func(T) (K, V)) map[K]V
- func Sort[T constraints.Ordered](s []T)
- func Stream(array any) stream
- func Swap[S ~[]V, V any](slices S, i, j int)
- func Union[S ~[]T, T comparable](a S, b S) S
- func UnionByKey[S ~[]_interface.CmpKey[T], T comparable](a S, b S) S
- type Array
- type ComparableSlices
- type CompareFunc
- type Index
- type MapSlices
- type Slices
- func (slices Slices[T]) Every(fn func(T) bool) bool
- func (slices Slices[T]) Filter(fn func(T) bool) []T
- func (slices Slices[T]) ForEach(fn func(T))
- func (slices Slices[T]) Len() int
- func (slices Slices[T]) Reduce(fn func(T, T) T) T
- func (slices Slices[T]) Some(fn func(T) bool) bool
- func (slices Slices[T]) Zip(s []T) [][2]T
Constants ¶
View Source
const SmallArrayLen = 64
Variables ¶
This section is empty.
Functions ¶
func BinarySearch ¶
func BinarySearch[V constraints.Ordered](arr []constraints2.OrderKey[V], x constraints2.OrderKey[V]) int
BinarySearch 二分查找
func Contains ¶
func Contains[S ~[]V, V comparable](slices S, v V) bool
func DifferenceByKey ¶
func DifferenceByKey[S ~[]_interface.CmpKey[T], T comparable](a, b S) (S, S)
取差集,通过循环比较key
func DifferenceSetByKey ¶
func DifferenceSetByKey[S ~[]_interface.CmpKey[T], T comparable](a S, b S) S
指定key取差集,返回为A-B
func ForEachIndex ¶
遍历切片,参数为下标,利用闭包实现遍历
func ForEachValue ¶
func ForEachValue[S ~[]V, V any](slices S, handle func(v V))
func HasCoincide ¶
func HasCoincide[S ~[]T, T comparable](s1, s2 S) bool
没有泛型,范例,实际需根据不同类型各写一遍,用CmpKey,基本类型又用不了,go需要能给基本类型实现方法不能给外部类型实现方法 1.20以后字段均是comparable的结构体也是comparable的 判断是否有重合元素
func HasCoincideByKey ¶
func HasCoincideByKey[S ~[]_interface.CmpKey[T], T comparable](s1, s2 S) bool
func In ¶
func In[S ~[]V, V comparable](v V, slices S) bool
func InByKey ¶
func InByKey[S ~[]constraints.CmpKey[K], K comparable](key K, slices S) bool
func IntersectionAndDifference ¶
func IntersectionAndDifference[S ~[]T, T comparable](a, b S) (S, S, S)
并集和差集,返回AUB,A-B,B-A
func IntersectionByKey ¶
func IntersectionByKey[S ~[]_interface.CmpKey[T], T comparable](a S, b S) S
func IntersectionMap ¶
func IntersectionMap[S ~[]T, T comparable](a S, b S) map[T]struct{}
func JoinByIndex ¶
func Max ¶
func Max[S ~[]T, T constraints.Number](slices S) T
func Min ¶
func Min[S ~[]T, T constraints.Number](slices S) T
func OrderedArrayIntersection ¶
func OrderedArrayIntersection[S ~[]T, T constraints.Ordered](a S, b S) S
有序数组取交集
func RemoveDuplicates ¶
func RemoveDuplicates[S ~[]T, T comparable](s S) S
func RemoveDuplicatesByKey ¶
func RemoveDuplicatesByKey[S ~[]_interface.CmpKey[T], T comparable](s S) S
func ReverseForEach ¶
func SlicesClassify ¶
func SlicesClassify[S ~[]T, T any, K comparable, V any](slices S, getKV func(T) (K, V)) map[K][]V
将切片按照某个key分类
func SlicesToMap ¶
func SlicesToMap[S ~[]T, T any, K comparable, V any](slices S, getKV func(T) (K, V)) map[K]V
将切片转换为map
func Sort ¶
func Sort[T constraints.Ordered](s []T)
func UnionByKey ¶
func UnionByKey[S ~[]_interface.CmpKey[T], T comparable](a S, b S) S
Types ¶
type ComparableSlices ¶
type ComparableSlices[T comparable] []T
func (ComparableSlices[T]) Deduplicate ¶
func (slices ComparableSlices[T]) Deduplicate() ComparableSlices[T]
去重
type CompareFunc ¶
type Index ¶
type Index[T any, O comparable] struct { sync.RWMutex // contains filtered or unexported fields }
Index 索引
func NewIndex ¶
func NewIndex[T any, O comparable]() *Index[T, O]
Source Files ¶
Click to show internal directories.
Click to hide internal directories.