slice

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2023 License: MIT Imports: 4 Imported by: 0

Documentation

Index

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

func CombinationsPari[T any](a, b []T, aCount, bCount int) [][]T

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

func ContainsAny[V any](slice []V, values V) bool

ContainsAny 判断数组是否包含某个元素

func Copy

func Copy[V any](slice []V) []V

Copy 复制特定切片

func CopyMatrix

func CopyMatrix[V any](slice [][]V) [][]V

CopyMatrix 复制二维数组

func Del

func Del[V any](slice *[]V, index int)

Del 删除特定索引的元素

func Distinct added in v0.0.15

func Distinct[V any](slice []V) []V

Distinct 去重

func Filter added in v0.0.31

func Filter[T any](a []T, filterHandle func(a T) bool) []T

Filter 过滤切片中的元素

  • filterHandle 返回 true 表示需要保留

func GetEndPart added in v0.0.14

func GetEndPart[V any](slice []V, n int) []V

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

func GetIndexAny[V any](slice []V, values V) int

GetIndexAny 判断数组是否包含某个元素,如果包含则返回索引

func GetPart added in v0.0.14

func GetPart[V any](slice []V, start, end int) []V

GetPart 获取指定区间的元素

func GetStartPart added in v0.0.14

func GetStartPart[V any](slice []V, n int) []V

GetStartPart 获取数组的前 n 个元素

func GetValue added in v0.0.30

func GetValue[V any](slice []V, i int) (v V)

GetValue 获取特定索引的元素,如果索引超出范围则返回零值

func GetValueHandle added in v0.0.30

func GetValueHandle[V any](slice []V, i int, handle func(v V))

GetValueHandle 获取特定索引的元素,并通过 handle 进入传入,如果索引超出范围则不会进入 handle

func Insert

func Insert[V any](slice *[]V, index int, value V)

Insert 在特定索引插入元素

func IsIntersect added in v0.0.20

func IsIntersect[T any](a, b []T) bool

IsIntersect 判断两个切片是否有交集

func IsIntersectWithCheck added in v0.0.20

func IsIntersectWithCheck[T any](a, b []T, checkHandle func(a, b T) bool) bool

IsIntersectWithCheck 判断两个切片是否有交集

func LimitedCombinations added in v0.0.20

func LimitedCombinations[T any](a []T, minSize, maxSize int) [][]T

LimitedCombinations 获取给定数组的所有组合,且每个组合的成员数量限制在指定范围内

func Mapping added in v0.1.4

func Mapping[T any, R any](a []T, mappingHandle func(a T) R) []R

Mapping 将切片中的元素进行转换

  • mappingHandle 返回转换后的元素

func Merge added in v0.0.8

func Merge[V any](slices ...[]V) []V

Merge 合并多个数组

func Move

func Move[V any](slice *[]V, index, to int)

Move 移动特定索引

func NextLoop

func NextLoop[V any](slice []V, i int) (next int, value V)

NextLoop 返回 i 的下一个数组成员,当 i 达到数组长度时从 0 开始

  • 当 i 为 -1 时将返回第一个元素

func PrevLoop added in v0.0.5

func PrevLoop[V any](slice []V, i int) (prev int, value V)

PrevLoop 返回 i 的上一个数组成员,当 i 为 0 时从数组末尾开始

  • 当 i 为 -1 时将返回最后一个元素

func Reverse added in v0.0.5

func Reverse[V any](slice []V)

Reverse 反转数组

func Shuffle added in v0.0.5

func Shuffle[V any](slice []V)

Shuffle 随机打乱数组

func SubWithCheck added in v0.0.20

func SubWithCheck[T any](a, b []T, checkHandle func(a, b T) bool) []T

SubWithCheck 获取移除指定元素后的切片

  • checkHandle 返回 true 表示需要移除

func Swap added in v0.0.5

func Swap[V any](slice []V, i, j int)

Swap 交换数组中的两个元素

func ToMap added in v0.0.5

func ToMap[K comparable, V any](slice []V, key func(V) K) map[K]V

ToMap 将数组转换为 map

func ToSet added in v0.0.5

func ToSet[V comparable](slice []V) map[V]struct{}

ToSet 将数组转换为 set

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

func NewPriority[V any](lengthAndCap ...int) *Priority[V]

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]) Append added in v0.0.30

func (slf *Priority[V]) Append(v V, priority int)

Append 添加元素

func (*Priority[V]) Appends added in v0.0.30

func (slf *Priority[V]) Appends(priority int, vs ...V)

Appends 添加元素

func (*Priority[V]) Cap added in v0.0.30

func (slf *Priority[V]) Cap() int

Cap 返回切片容量

func (*Priority[V]) Clear added in v0.0.30

func (slf *Priority[V]) Clear()

Clear 清空切片

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

func (slf *Priority[V]) GetPriority(index int) int

GetPriority 获取元素优先级

func (*Priority[V]) GetValue added in v0.0.30

func (slf *Priority[V]) GetValue(index int) V

GetValue 获取元素值

func (*Priority[V]) Len added in v0.0.30

func (slf *Priority[V]) Len() int

Len 返回切片长度

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

func (slf *Priority[V]) RangePriority(action func(index int, priority int) bool)

RangePriority 遍历切片优先级,如果返回值为 false,则停止遍历

func (*Priority[V]) RangeValue added in v0.0.30

func (slf *Priority[V]) RangeValue(action func(index int, value V) bool)

RangeValue 遍历切片值,如果返回值为 false,则停止遍历

func (*Priority[V]) Set added in v0.0.30

func (slf *Priority[V]) Set(index int, value V, priority int)

Set 设置元素

func (*Priority[V]) SetPriority added in v0.0.30

func (slf *Priority[V]) SetPriority(index int, priority int)

SetPriority 设置元素优先级

func (*Priority[V]) SetValue added in v0.0.30

func (slf *Priority[V]) SetValue(index int, value V)

SetValue 设置元素值

func (*Priority[V]) String added in v0.0.30

func (slf *Priority[V]) String() string

String 返回切片字符串

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 返回元素优先级

func (*PriorityItem[V]) Value added in v0.0.30

func (p *PriorityItem[V]) Value() V

Value 返回元素值

Jump to

Keyboard shortcuts

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