ds

package
v1.0.0-pre4 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2022 License: MIT Imports: 4 Imported by: 5

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BinarySearch

func BinarySearch[T ttypes.Ordered](data []T, value T) int

BinarySearch 二分搜索

func Max

func Max[T ttypes.Ordered](data ...T) T

Max 求最大值

func Min

func Min[T ttypes.Ordered](data ...T) T

Min 求最小值

func SliceAbsoluteEqual

func SliceAbsoluteEqual[T comparable](a []T, b []T) bool

SliceAbsoluteEqual 判断两个slice是否一样,严格按照顺序比较

func SliceCopy

func SliceCopy[T any](data []T) []T

SliceCopy 复制切片

func SliceFilter

func SliceFilter[T any](a []T, filter func(v T) bool) []T

SliceFilter 过滤slice

func SliceLogicalEqual

func SliceLogicalEqual[T comparable](a []T, b []T) bool

SliceLogicalEqual 判断两个Slice是否逻辑一样,和顺序无关

func SliceMap

func SliceMap[T any](a []T, handler func(v *T))

SliceMap 对slice中的元素执行操作

func SliceMax

func SliceMax[T ttypes.Ordered](data []T) T

SliceMax 求数组的最大值

func SliceMin

func SliceMin[T ttypes.Ordered](data []T) T

SliceMin 求数组的最小值

func SliceReverse

func SliceReverse[T any](data []T)

SliceReverse 转置切片

func SliceUnique

func SliceUnique[T comparable](data []T) []T

SliceUnique 去重切片

Types

type BuiltinSet

type BuiltinSet[K comparable] map[K]struct{}

BuiltinSet is an associative container that contains an unordered set of unique objects of type K.

func NewSet

func NewSet[K comparable]() BuiltinSet[K]

func SetOf

func SetOf[K comparable](ks ...K) BuiltinSet[K]

SetOf creates a new BuiltinSet object with the initial content from ks.

func (BuiltinSet[K]) Clear

func (s BuiltinSet[K]) Clear()

Clear implements the Container interface.

func (BuiltinSet[K]) Delete

func (s BuiltinSet[K]) Delete(k K)

Delete deletes an element from the set. It returns nothing, so it's faster than Remove.

func (BuiltinSet[K]) Difference

func (s BuiltinSet[K]) Difference(other BuiltinSet[K]) BuiltinSet[K]

Difference returns a new set with elements in the set that are not in other.

func (BuiltinSet[K]) ForEach

func (s BuiltinSet[K]) ForEach(cb func(k K))

ForEach implements the Set interface.

func (BuiltinSet[K]) ForEachIf

func (s BuiltinSet[K]) ForEachIf(cb func(k K) bool)

ForEachIf implements the Container interface.

func (BuiltinSet[K]) Has

func (s BuiltinSet[K]) Has(k K) bool

Has implements the Set interface.

func (BuiltinSet[K]) Insert

func (s BuiltinSet[K]) Insert(k K) bool

Insert implements the Set interface.

func (BuiltinSet[K]) InsertN

func (s BuiltinSet[K]) InsertN(ks ...K) int

InsertN implements the Set interface.

func (BuiltinSet[K]) Intersection

func (s BuiltinSet[K]) Intersection(other BuiltinSet[K]) BuiltinSet[K]

Intersection returns a new set with elements common to the set and other.

func (BuiltinSet[K]) IsDisjointOf

func (s BuiltinSet[K]) IsDisjointOf(other BuiltinSet[K]) bool

IsDisjointOf return True if the set has no elements in common with other. Sets are disjoint if and only if their intersection is the empty set.

func (BuiltinSet[K]) IsEmpty

func (s BuiltinSet[K]) IsEmpty() bool

IsEmpty implements the Container interface.

func (BuiltinSet[K]) IsSubsetOf

func (s BuiltinSet[K]) IsSubsetOf(other BuiltinSet[K]) bool

IsSubsetOf tests whether every element in the set is in other.

func (BuiltinSet[K]) IsSupersetOf

func (s BuiltinSet[K]) IsSupersetOf(other BuiltinSet[K]) bool

IsSupersetOf tests whether every element in other is in the set.

func (BuiltinSet[K]) Keys

func (s BuiltinSet[K]) Keys() []K

Keys return a copy of all keys as a slice.

func (BuiltinSet[K]) Len

func (s BuiltinSet[K]) Len() int

Len implements the Container interface.

func (BuiltinSet[K]) Remove

func (s BuiltinSet[K]) Remove(k K) bool

Remove implements the Set interface.

func (BuiltinSet[K]) RemoveN

func (s BuiltinSet[K]) RemoveN(ks ...K) int

RemoveN implements the Set interface.

func (BuiltinSet[K]) String

func (s BuiltinSet[K]) String() string

String implements the fmt.Stringer interface.

func (BuiltinSet[K]) Union

func (s BuiltinSet[K]) Union(other BuiltinSet[K]) BuiltinSet[K]

Union returns a new set with elements from the set and other.

func (BuiltinSet[K]) Update

func (s BuiltinSet[K]) Update(other BuiltinSet[K])

Update adds all elements from other to set. set |= other.

type CounterMap

type CounterMap[K comparable] map[K]int

func NewCounterMap

func NewCounterMap[K comparable](data []K) CounterMap[K]

func (CounterMap[K]) Equal

func (c CounterMap[K]) Equal(other CounterMap[K]) bool

type GroupMap

type GroupMap[K comparable, V any] map[K][]V

func NewGroupMap

func NewGroupMap[K comparable, V any](data []V, getKeyHandler func(V) K) GroupMap[K, V]

type ListNode

type ListNode[T any] struct {
	Data *T
	Next *ListNode[T]
	Pre  *ListNode[T]
}

func (*ListNode[T]) Pop

func (list *ListNode[T]) Pop() *ListNode[T]

func (*ListNode[T]) PushBack

func (list *ListNode[T]) PushBack(data *ListNode[T])

func (*ListNode[T]) PushFront

func (list *ListNode[T]) PushFront(data *ListNode[T])

type SortedMap

type SortedMap[K ttypes.Ordered, V any] struct {
	ReverseOpt bool
	Tuples     []ttypes.Tuple[K, V]
	RawMap     map[K]V
}

SortedMap 有序Map,底层维护了有序切片 如果需要对map进行修改需要执行Rebuild来维护有序行,否则会导致不一致

func NewSortedMap

func NewSortedMap[K ttypes.Ordered, V any](data map[K]V, reverseOpts ...bool) SortedMap[K, V]

func (*SortedMap[K, V]) Rebuild

func (s *SortedMap[K, V]) Rebuild()

Rebuild 重新构建有序Map,一般用于map修改后再次维护tuples的有序行

Jump to

Keyboard shortcuts

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