slices

package
v1.3.2 Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2023 License: MIT Imports: 5 Imported by: 2

Documentation

Index

Constants

View Source
const SmallArrayLen = 64

Variables

This section is empty.

Functions

func BinarySearch

func BinarySearch[V constraints.Ordered](arr []_interface.OrderKey[V], x _interface.OrderKey[V]) int

BinarySearch 二分查找

func Contains

func Contains[S ~[]T, T comparable](arr S, sub T) bool

func Deduplicate added in v1.1.0

func Deduplicate[S ~[]T, T comparable](slices S) S

去重

func Difference

func Difference[S ~[]T, T comparable](a S, b S) S

取差集

func Difference2

func Difference2[S ~[]T, T comparable](a, b S) S

取差集

func DifferenceByKey added in v1.1.0

func DifferenceByKey[S ~[]_interface.CmpKey[T], T comparable](a S, b S) S

func DifferenceByKey2 added in v1.1.0

func DifferenceByKey2[S ~[]_interface.CmpKey[T], T comparable](a, b S) S

func ForEach added in v1.1.0

func ForEach[S ~[]T, T any](heap S, handle func(T))

func ForEachByIdx added in v1.1.0

func ForEachByIdx[S ~[]T, T any](heap S, handle func(i int))

遍历切片,参数为下标,利用闭包实现遍历

func In

func In[S ~[]T, T comparable](a T, b S) bool

func InByKey added in v1.1.0

func InByKey[S ~[]_interface.CmpKey[T], T comparable](a T, b S) bool

func Intersection

func Intersection[S ~[]T, T comparable](a S, b S) S

取并集

func IntersectionByKey added in v1.1.0

func IntersectionByKey[S ~[]_interface.CmpKey[T], T comparable](a S, b S) S

func IsCoincide

func IsCoincide[S ~[]T, T comparable](s1, s2 S) bool

没有泛型,范例,实际需根据不同类型各写一遍,用CmpKey,基本类型又用不了,go需要能给基本类型实现方法不能给外部类型实现方法 1.20以后字段均是comparable的结构体也是comparable的

func IsCoincideByKey added in v1.1.0

func IsCoincideByKey[S ~[]_interface.CmpKey[T], T comparable](s1, s2 S) bool

func Map

func Map[S ~[]T, T any, V any](slices S, fn func(T) V) []V

func Max

func Max[S ~[]T, T constraints.Number](s S) T

func Min

func Min[S ~[]T, T constraints.Number](s S) T

func OrderedArrayIntersection

func OrderedArrayIntersection[S ~[]T, T constraints.Ordered](a S, b S) S

有序数组取交集

func Reduce

func Reduce[S ~[]T, T any](slices S, fn func(T, T) T) T

func RemoveDuplicates

func RemoveDuplicates[S ~[]T, T comparable](s S) S

func RemoveDuplicatesByKey added in v1.1.0

func RemoveDuplicatesByKey[S ~[]_interface.CmpKey[T], T comparable](s S) S

func Reverse added in v1.1.0

func Reverse[S ~[]T, T any](runes S) S

func SlicesToMap

func SlicesToMap[S ~[]T, T any, K comparable, V any](slices S, getKV func(T) (K, V)) map[K]V

func Sort

func Sort[T comparable](slices []T)

TODO

func Stream added in v1.1.0

func Stream(array any) stream

func Swap

func Swap[S ~[]T, T any](heap S, i, j int)

func Union

func Union[S ~[]T, T comparable](a S, b S) S

取并集

func UnionByKey added in v1.1.0

func UnionByKey[S ~[]_interface.CmpKey[T], T comparable](a S, b S) S

Types

type Array

type Array[S, T any] []S

学学kotlin的定义

func (Array[S, T]) Map

func (a Array[S, T]) Map(fn func(S) T) []T

type ComparableSlices added in v1.1.0

type ComparableSlices[T comparable] []T

func (ComparableSlices[T]) Deduplicate added in v1.1.0

func (slices ComparableSlices[T]) Deduplicate() ComparableSlices[T]

去重

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]

func (*Index[T, O]) Add

func (i *Index[T, O]) Add(idx O, res T)

func (*Index[T, O]) Get

func (i *Index[T, O]) Get(idx O) T

func (*Index[T, O]) Remove

func (i *Index[T, O]) Remove(idx O)

func (*Index[T, O]) Set

func (i *Index[T, O]) Set(idx O, v T)

type MapSlices added in v1.1.0

type MapSlices[T, V any] Slices[T]

func (MapSlices[T, V]) Map added in v1.1.0

func (slices MapSlices[T, V]) Map(fn func(T) V) []V

type Slices

type Slices[T any] []T

func (Slices[T]) Every

func (slices Slices[T]) Every(fn func(T) bool) bool

func (Slices[T]) Filter

func (slices Slices[T]) Filter(fn func(T) bool) []T

func (Slices[T]) ForEach

func (slices Slices[T]) ForEach(fn func(T))

func (Slices[T]) Len

func (slices Slices[T]) Len() int

func (Slices[T]) Reduce

func (slices Slices[T]) Reduce(fn func(T, T) T) T

func (Slices[T]) Some

func (slices Slices[T]) Some(fn func(T) bool) bool

func (Slices[T]) Zip

func (slices Slices[T]) Zip(s []T) [][2]T

Jump to

Keyboard shortcuts

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