Documentation ¶
Index ¶
- func Combinations[T any](a []T) [][]T
- func CombinationsPari[T any](a, b []T, aCount, bCount int) [][]T
- func Contains[V comparable](slice []V, value V) bool
- func ContainsAny[V any](slice []V, values V) bool
- func Copy[V any](slice []V) []V
- func CopyMatrix[V any](slice [][]V) [][]V
- func Del[V any](slice *[]V, index int)
- func Distinct[V any](slice []V) []V
- func Filter[T any](a []T, filterHandle func(a T) bool) []T
- func GetEndPart[V any](slice []V, n int) []V
- func GetIndex[V comparable](slice []V, value V) int
- func GetIndexAny[V any](slice []V, values V) int
- func GetPart[V any](slice []V, start, end int) []V
- func GetStartPart[V any](slice []V, n int) []V
- func GetValue[V any](slice []V, i int) (v V)
- func GetValueHandle[V any](slice []V, i int, handle func(v V))
- func Insert[V any](slice *[]V, index int, value V)
- func IsIntersect[T any](a, b []T) bool
- func IsIntersectWithCheck[T any](a, b []T, checkHandle func(a, b T) bool) bool
- func LimitedCombinations[T any](a []T, minSize, maxSize int) [][]T
- func Mapping[T any, R any](a []T, mappingHandle func(a T) R) []R
- func Merge[V any](slices ...[]V) []V
- func Move[V any](slice *[]V, index, to int)
- func NextLoop[V any](slice []V, i int) (next int, value V)
- func PrevLoop[V any](slice []V, i int) (prev int, value V)
- func Reverse[V any](slice []V)
- func Shuffle[V any](slice []V)
- func SubWithCheck[T any](a, b []T, checkHandle func(a, b T) bool) []T
- func Swap[V any](slice []V, i, j int)
- func ToMap[K comparable, V any](slice []V, key func(V) K) map[K]V
- func ToSet[V comparable](slice []V) map[V]struct{}
- type Priority
- func (slf *Priority[V]) Action(action func(items []*PriorityItem[V]) []*PriorityItem[V])
- func (slf *Priority[V]) Append(v V, priority int)
- func (slf *Priority[V]) Appends(priority int, vs ...V)
- func (slf *Priority[V]) Cap() int
- func (slf *Priority[V]) Clear()
- func (slf *Priority[V]) Get(index int) *PriorityItem[V]
- func (slf *Priority[V]) GetPriority(index int) int
- func (slf *Priority[V]) GetValue(index int) V
- func (slf *Priority[V]) Len() int
- func (slf *Priority[V]) Range(action func(index int, item *PriorityItem[V]) bool)
- func (slf *Priority[V]) RangePriority(action func(index int, priority int) bool)
- func (slf *Priority[V]) RangeValue(action func(index int, value V) bool)
- func (slf *Priority[V]) Set(index int, value V, priority int)
- func (slf *Priority[V]) SetPriority(index int, priority int)
- func (slf *Priority[V]) SetValue(index int, value V)
- func (slf *Priority[V]) String() string
- type PriorityItem
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Combinations ¶ added in v0.0.20
func Combinations[T any](a []T) [][]T
Combinations 获取给定数组的所有组合,包括重复元素的组合
func CombinationsPari ¶ added in v0.0.21
CombinationsPari 从给定的两个数组中按照特定数量得到所有组合后,再将两个数组的组合进行组合
- 例如从数组 A 中得到所有数量为2的组合,从数组 B 中得到所有数量为3的组合,再将两个组合进行组合,得到所有数量为5的组合
func Contains ¶ added in v0.0.15
func Contains[V comparable](slice []V, value V) bool
Contains 判断数组是否包含某个元素
func ContainsAny ¶ added in v0.0.15
ContainsAny 判断数组是否包含某个元素
func GetEndPart ¶ added in v0.0.14
GetEndPart 获取数组的后 n 个元素
func GetIndex ¶ added in v0.0.20
func GetIndex[V comparable](slice []V, value V) int
GetIndex 判断数组是否包含某个元素,如果包含则返回索引
func GetIndexAny ¶ added in v0.0.20
GetIndexAny 判断数组是否包含某个元素,如果包含则返回索引
func GetStartPart ¶ added in v0.0.14
GetStartPart 获取数组的前 n 个元素
func GetValueHandle ¶ added in v0.0.30
GetValueHandle 获取特定索引的元素,并通过 handle 进入传入,如果索引超出范围则不会进入 handle
func IsIntersectWithCheck ¶ added in v0.0.20
IsIntersectWithCheck 判断两个切片是否有交集
func LimitedCombinations ¶ added in v0.0.20
LimitedCombinations 获取给定数组的所有组合,且每个组合的成员数量限制在指定范围内
func ToMap ¶ added in v0.0.5
func ToMap[K comparable, V any](slice []V, key func(V) K) map[K]V
ToMap 将数组转换为 map
Types ¶
type Priority ¶ added in v0.0.30
type Priority[V any] struct { // contains filtered or unexported fields }
Priority 是一个优先级切片
func NewPriority ¶ added in v0.0.30
NewPriority 创建一个优先级切片
func (*Priority[V]) Action ¶ added in v0.0.30
func (slf *Priority[V]) Action(action func(items []*PriorityItem[V]) []*PriorityItem[V])
Action 直接操作切片,如果返回值不为 nil,则替换切片
func (*Priority[V]) Get ¶ added in v0.0.30
func (slf *Priority[V]) Get(index int) *PriorityItem[V]
Get 获取元素
func (*Priority[V]) GetPriority ¶ added in v0.0.30
GetPriority 获取元素优先级
func (*Priority[V]) Range ¶ added in v0.0.30
func (slf *Priority[V]) Range(action func(index int, item *PriorityItem[V]) bool)
Range 遍历切片,如果返回值为 false,则停止遍历
func (*Priority[V]) RangePriority ¶ added in v0.0.30
RangePriority 遍历切片优先级,如果返回值为 false,则停止遍历
func (*Priority[V]) RangeValue ¶ added in v0.0.30
RangeValue 遍历切片值,如果返回值为 false,则停止遍历
func (*Priority[V]) SetPriority ¶ added in v0.0.30
SetPriority 设置元素优先级
type PriorityItem ¶ added in v0.0.30
type PriorityItem[V any] struct { // contains filtered or unexported fields }
PriorityItem 是一个优先级切片元素
func NewPriorityItem ¶ added in v0.0.30
func NewPriorityItem[V any](v V, priority int) *PriorityItem[V]
NewPriorityItem 创建一个优先级切片元素
func (*PriorityItem[V]) Next ¶ added in v0.0.30
func (p *PriorityItem[V]) Next() *PriorityItem[V]
Next 返回下一个元素
func (*PriorityItem[V]) Prev ¶ added in v0.0.30
func (p *PriorityItem[V]) Prev() *PriorityItem[V]
Prev 返回上一个元素
func (*PriorityItem[V]) Priority ¶ added in v0.0.30
func (p *PriorityItem[V]) Priority() int
Priority 返回元素优先级