ds

package
v2.0.2 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2023 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package ds queue copy from https://github.com/eapache/queue/blob/master/queue.go

Package ds BuiltinSet copy from https://github.com/chen3feng/stl4go/blob/master/builtin_set.go

Package ds stack copy from https://github.com/chen3feng/stl4go/blob/master/stack.go

Index

Constants

This section is empty.

Variables

View Source
var ErrorNotFound = errors.New("not found")

Functions

func FpPartial

func FpPartial[T1, T2, R any](f func(a T1, b T2) R, arg1 T1) func(T2) R

FpPartial returns new function that, when called, has its first argument set to the provided value.

func FpPartial1

func FpPartial1[T1, T2, R any](f func(T1, T2) R, arg1 T1) func(T2) R

FpPartial1 returns new function that, when called, has its first argument set to the provided value.

func FpPartial2

func FpPartial2[T1, T2, T3, R any](f func(T1, T2, T3) R, arg1 T1) func(T2, T3) R

FpPartial2 returns new function that, when called, has its first argument set to the provided value.

func FpPartial3

func FpPartial3[T1, T2, T3, T4, R any](f func(T1, T2, T3, T4) R, arg1 T1) func(T2, T3, T4) R

FpPartial3 returns new function that, when called, has its first argument set to the provided value.

func FpPartial4

func FpPartial4[T1, T2, T3, T4, T5, R any](f func(T1, T2, T3, T4, T5) R, arg1 T1) func(T2, T3, T4, T5) R

FpPartial4 returns new function that, when called, has its first argument set to the provided value.

func FpPartial5

func FpPartial5[T1, T2, T3, T4, T5, T6, R any](f func(T1, T2, T3, T4, T5, T6) R, arg1 T1) func(T2, T3, T4, T5, T6) R

FpPartial5 returns new function that, when called, has its first argument set to the provided value

func ListIter

func ListIter[T any](a DList[T], iterate func(a DList[T], node T))

ListIter 迭代元素

func ListIterAllOk

func ListIterAllOk[T any](a DList[T], iterate func(a DList[T], node T) bool) bool

ListIterAllOk Returns true if all of the values pass the predicate truth test

func ListPartition

func ListPartition[T any](a DList[T], iterate func(a DList[T], node T) bool) (DList[T], DList[T])

ListPartition Split list into two lists: one whose elements all satisfy predicate and one whose elements all do not satisfy predicate

func MapConvertKeyToSlice

func MapConvertKeyToSlice[T comparable, V any](a map[T]V) []T

MapConvertKeyToSlice 提取map的key

func MapConvertValueToSlice

func MapConvertValueToSlice[T comparable, V any](a map[T]V) []V

MapConvertValueToSlice 提取map的值

func MapConvertZipSliceToMap

func MapConvertZipSliceToMap[T comparable, V any](a []T, b []V) (map[T]V, error)

MapConvertZipSliceToMap 两个slice,一个key,一个value转换为map

func MapEqualCounter

func MapEqualCounter[V comparable](c map[V]int, other map[V]int) bool

func MapIter

func MapIter[K comparable, V any](a map[K]V, iterate func(a map[K]V, k K, v V))

MapIter 只是迭代元素

func MapIterAllOk

func MapIterAllOk[K comparable, V any](a map[K]V, iterate func(a map[K]V, k K, v V) bool) bool

MapIterAllOk Returns true if all of the values pass the predicate truth test

func MapIterFilter

func MapIterFilter[K comparable, V any](a map[K]V, iterate func(a map[K]V, k K, v V) bool) map[K]V

MapIterFilter Looks through each value in the map, returning a map of all the values that pass a truth test (predicate).

func MapIterMapKVCopy

func MapIterMapKVCopy[K comparable, V any](a map[K]V, iterate func(a map[K]V, k K, v V) (K, V)) map[K]V

MapIterMapKVCopy Produces a new map by mapping each key, value in map through a transformation function (iterate).

func MapIterMapKVInPlace

func MapIterMapKVInPlace[K comparable, V any](a map[K]V, iterate func(a map[K]V, k K, v V) V) map[K]V

MapIterMapKVInPlace Map每个kv进行map映射

func MapIterPartition

func MapIterPartition[K comparable, V any](a map[K]V, iterate func(a map[K]V, k K, v V) bool) (map[K]V, map[K]V)

MapIterPartition Split map into two maps: one whose elements all satisfy predicate and one whose elements all do not satisfy predicate

func MapOpMerge

func MapOpMerge[K comparable, V any](m1 map[K]V, m2 map[K]V) map[K]V

MapOpMerge 合并两个map,如果key重复则以第二个元素中的key为主

func MapOpRemoveEmptyString

func MapOpRemoveEmptyString[K comparable](m map[K]string) map[K]string

MapOpRemoveEmptyString 删除空字符串的

func SetIter

func SetIter[T comparable](a BuiltinSet[T], iterate func(a BuiltinSet[T], node T))

SetIter 迭代元素

func SetIterAllOk

func SetIterAllOk[T comparable](a BuiltinSet[T], iterate func(a BuiltinSet[T], node T) bool) bool

SetIterAllOk Returns true if all of the values pass the predicate truth test

func SetPartition

func SetPartition[T comparable](a BuiltinSet[T], iterate func(a BuiltinSet[T], node T) bool) (BuiltinSet[T], BuiltinSet[T])

SetPartition Split set into two sets: one whose elements all satisfy predicate and one whose elements all do not satisfy predicate

func SetToSlice

func SetToSlice[K comparable](u BuiltinSet[K]) []K

SetToSlice convert from set to slice

func SliceCmpAbsEqual

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

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

func SliceCmpAbsSub

func SliceCmpAbsSub[T comparable](a []T, b []T) int

SliceCmpAbsSub 判断b切片是否是a切片的子集,严格比较

func SliceCmpLogicEqual

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

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

func SliceCmpLogicSub

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

SliceCmpLogicSub 判断b切片是否是a切片的子集

func SliceCmpTwoDiff

func SliceCmpTwoDiff[T comparable](a []T, b []T) ([]T, []T)

SliceCmpTwoDiff 显示两个切片的区别

func SliceConvertToInt

func SliceConvertToInt(data interface{}) ([]int, error)

SliceConvertToInt 切片集合统一转换为[]int

func SliceConvertToInt64

func SliceConvertToInt64(data interface{}) ([]int64, error)

SliceConvertToInt64 切片集合统一转换为[]int64

func SliceConvertToString

func SliceConvertToString(data interface{}) ([]string, error)

SliceConvertToString 切片集合统一转换为[]string

func SliceExclude

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

SliceExclude 判断元素是否不在slice中

func SliceGetCopy

func SliceGetCopy[T any](data []T, ns ...int) []T

SliceGetCopy 复制切片

func SliceGetFilter

func SliceGetFilter[T any](a []T, filter func(i int) bool) []T

SliceGetFilter 过滤slice

func SliceGetTail

func SliceGetTail[T any](data []T, d ...T) T

SliceGetTail 获取切片最后一个元素,如果没有则用默认值

func SliceGroupByHandler

func SliceGroupByHandler[K comparable, V any](data []V, getKeyHandler func(int) K) map[K][]V

SliceGroupByHandler 对切片进行分类

func SliceGroupToCounter

func SliceGroupToCounter[V comparable](data []V) map[V]int

SliceGroupToCounter 对切片按照元素进行计数

func SliceGroupToMap

func SliceGroupToMap[V comparable](data []V) map[V][]V

SliceGroupToMap 对切片按照元素进行分类, 结果以map形式返回

func SliceGroupToSlices

func SliceGroupToSlices[V ttypes.Ordered](data []V) [][]V

SliceGroupToSlices 对切片按照元素进行分类,结果以二维数组形式返回

func SliceInclude

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

SliceInclude 判断元素是否在slice中

func SliceIncludeBinarySearch

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

SliceIncludeBinarySearch 二分搜索

func SliceIncludeIndex

func SliceIncludeIndex[T comparable](a []T, b T) int

SliceIncludeIndex 获取元素在切片中的下标,如果不存在返回-1

func SliceIncludeIndexUnpack

func SliceIncludeIndexUnpack[T comparable](a T, others ...T) int

SliceIncludeIndexUnpack 获取元素在切片中的下标,如果不存在返回-1

func SliceIncludeUnpack

func SliceIncludeUnpack[T comparable](a T, others ...T) bool

SliceIncludeUnpack 判断第一个元素是否在后续元素集合中

func SliceIter

func SliceIter[T any](a []T, iterate func(a []T, i int))

SliceIter 只是迭代元素

func SliceIterAllOk

func SliceIterAllOk[T any](a []T, iterate func(a []T, i int) bool) bool

SliceIterAllOk Returns true if all of the values pass the predicate truth test

func SliceIterFilter

func SliceIterFilter[T any](a []T, iterate func(a []T, i int) bool) []T

SliceIterFilter Looks through each value in the slice, returning a slice of all the values that pass a truth test (predicate).

func SliceIterMapCopy

func SliceIterMapCopy[T any](a []T, iterate func(a []T, i int) T) []T

SliceIterMapCopy Produces a new slice by mapping each value in list through a transformation function (iterate).

func SliceIterMapInPlace

func SliceIterMapInPlace[T any](a []T, iterate func(a []T, i int) T) []T

SliceIterMapInPlace Slice每个元素进行map映射

func SliceIterPartition

func SliceIterPartition[T any](a []T, iterate func(a []T, i int) bool) ([]T, []T)

SliceIterPartition Split slice into two slices: one whose elements all satisfy predicate and one whose elements all do not satisfy predicate

func SliceMax

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

SliceMax 求数组的最大值

func SliceMaxN

func SliceMaxN[T ttypes.Ordered](data []T, n int) []T

SliceMaxN 返回切片中最大N个元素

func SliceMaxNWithOrder

func SliceMaxNWithOrder[T ttypes.Ordered](data []T, n int) []T

SliceMaxNWithOrder 按序返回切片中最大的N个元素

func SliceMaxUnpack

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

SliceMaxUnpack 求最大值

func SliceMin

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

SliceMin 求数组的最小值

func SliceMinN

func SliceMinN[T ttypes.Ordered](data []T, n int) []T

SliceMinN 获取切片中最小的N个元素

func SliceMinNWithOrder

func SliceMinNWithOrder[T ttypes.Ordered](data []T, n int) []T

SliceMinNWithOrder 有序返回切片中最小的N个元素

func SliceMinUnpack

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

SliceMinUnpack 求最小值

func SliceOpInsert

func SliceOpInsert[T any](data *[]T, i int, x ...T)

SliceOpInsert 把元素插入到data的指定位置

func SliceOpPopBack

func SliceOpPopBack[T any](data *[]T) (T, bool)

SliceOpPopBack 弹出切片最后一个元素

func SliceOpRemove

func SliceOpRemove[T comparable](data *[]T, b T)

SliceOpRemove 原地删除元素

func SliceOpRemoveIndex

func SliceOpRemoveIndex[T any](data *[]T, i int)

SliceOpRemoveIndex 删除某个索引位置的切片

func SliceOpRemoveMany

func SliceOpRemoveMany[T comparable](data *[]T, values []T)

SliceOpRemoveMany 从Slice集合中移除另外一个Slice中的元素

func SliceOpRemoveRange

func SliceOpRemoveRange[T any](data *[]T, i int, j int)

SliceOpRemoveRange 删除某个范围内的切片

func SliceOpReplace

func SliceOpReplace[T comparable](data []T, a T, b T)

SliceOpReplace 原地替换元素

func SliceOpReverse

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

SliceOpReverse 转置切片

func SliceOpReverseCopy

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

SliceOpReverseCopy 转置切片并复制

func SliceOpShuffle

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

SliceOpShuffle shuffle 切片

func SliceOpUnique

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

SliceOpUnique 去重切片

func StrHasPrefixInsensitive

func StrHasPrefixInsensitive(str string, subStr string) bool

StrHasPrefixInsensitive 判断str是以subStr开始, subStr不关注大小写

func StrHasSuffixInsensitive

func StrHasSuffixInsensitive(str string, subStr string) bool

StrHasSuffixInsensitive 判断str是以subStr结尾, subStr不关注大小写

func StrRemoveHead

func StrRemoveHead(s string, n int) string

StrRemoveHead 删除str起始n个元素

func StrRemoveTail

func StrRemoveTail(s string, n int) string

StrRemoveTail 删除str末尾n个元素

func StrSplitNth

func StrSplitNth(str string, sep string, total int, nth int) string

StrSplitNth 字符串分割按照sep分割,约定total个,返回第nth个元素 total == -1表示不关注total元素个数 nth == -1表示返回最后一个元素

Types

type Bitmap

type Bitmap struct {
	// contains filtered or unexported fields
}

Bitmap is a mapping from some domain (for example, a range of integers) to bits. It is also called a bit array or bitmap index

func New

func New(size uint64) *Bitmap

New creates a new bitmap

func NewFromData

func NewFromData(data []byte) *Bitmap

NewFromData creates a bitmap from the exported data

func (*Bitmap) Clear

func (b *Bitmap) Clear()

Clear clear the bitmap's data

func (*Bitmap) Data

func (b *Bitmap) Data() []byte

Data returns the bitmap's internal data slice

func (*Bitmap) IsSet

func (b *Bitmap) IsSet(pos uint64) bool

IsSet returns true if the position pos is 1

func (*Bitmap) Resize

func (b *Bitmap) Resize(size uint64)

Resize resizes the bitmap with the passed size

func (*Bitmap) Set

func (b *Bitmap) Set(pos uint64) bool

Set sets 1 at position pos

func (*Bitmap) Size

func (b *Bitmap) Size() uint64

Size returns the bitmap's size in bit

func (*Bitmap) Unset

func (b *Bitmap) Unset(pos uint64) bool

Unset sets 0 at position pos

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](n ...int) BuiltinSet[K]

func SetFromSlice

func SetFromSlice[K comparable](ks []K) BuiltinSet[K]

SetFromSlice create a new BuiltinSet object with the initial content from slice.

func SetIterFilter

func SetIterFilter[T comparable](a BuiltinSet[T], iterate func(a BuiltinSet[T], node T) bool) BuiltinSet[T]

SetIterFilter Looks through each value in the set, returning a set of all the values that pass a truth test (predicate).

func SetIterMapCopy

func SetIterMapCopy[T comparable](a BuiltinSet[T], iterate func(a BuiltinSet[T], node T) T) BuiltinSet[T]

SetIterMapCopy Produces a new list by mapping each value in list through a transformation function (iterate).

func SetIterMapInPlace

func SetIterMapInPlace[T comparable](a BuiltinSet[T], iterate func(a BuiltinSet[T], node T) T) BuiltinSet[T]

SetIterMapInPlace Iterates over set, yielding each value in turn to an iterate function, Returns the set for chaining.

func SetOf

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

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

func SliceGroupToSet

func SliceGroupToSet[V comparable](data []V) BuiltinSet[V]

SliceGroupToSet 对切片按照元素进行分类,结果以Set形式返回

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 DList

type DList[T any] struct {
	// contains filtered or unexported fields
}

DList is a doubly linked list.

func ListIterFilter

func ListIterFilter[T any](a DList[T], iterate func(a DList[T], node T) bool) DList[T]

ListIterFilter Looks through each value in the list, returning a list of all the values that pass a truth test (predicate).

func ListIterMapCopy

func ListIterMapCopy[T any](a DList[T], iterate func(a DList[T], node T) T) DList[T]

ListIterMapCopy Produces a new list by mapping each value in list through a transformation function (iterate).

func ListIterMapInPlace

func ListIterMapInPlace[T any](a DList[T], iterate func(a DList[T], node T) T) DList[T]

ListIterMapInPlace Iterates over list, yielding each value in turn to an iterate function, Returns the list for chaining.

func ListOf

func ListOf[T any](vs ...T) DList[T]

ListOf make a new DList from a serial of values.

func (*DList[T]) Back

func (l *DList[T]) Back() T

Back returns the last element in the container.

func (*DList[T]) Clear

func (l *DList[T]) Clear()

Clear cleanup the list.

func (*DList[T]) ForEach

func (l *DList[T]) ForEach(cb func(val T))

ForEach iterate the list, apply each element to the cb callback function.

func (*DList[T]) ForEachIf

func (l *DList[T]) ForEachIf(cb func(val T) bool)

ForEachIf iterate the list, apply each element to the cb callback function, stop if cb returns false.

func (*DList[T]) ForEachMutable

func (l *DList[T]) ForEachMutable(cb func(val *T))

ForEachMutable iterate the list, apply pointer of each element to the cb callback function.

func (*DList[T]) ForEachMutableIf

func (l *DList[T]) ForEachMutableIf(cb func(val *T) bool)

ForEachMutableIf iterate the list, apply pointer of each element to the cb callback function, stop if cb returns false.

func (*DList[T]) Front

func (l *DList[T]) Front() T

Front returns the first element in the container.

func (*DList[T]) IsEmpty

func (l *DList[T]) IsEmpty() bool

IsEmpty return whether the list is empty.

func (*DList[T]) Iterate

func (l *DList[T]) Iterate() MutableIterator[T]

func (*DList[T]) Len

func (l *DList[T]) Len() int

Len return the length of the list.

func (*DList[T]) PopBack

func (l *DList[T]) PopBack() T

PopBack popups an element from the back of the list.

func (*DList[T]) PopFront

func (l *DList[T]) PopFront() T

PopFront popups an element from the front of the list.

func (*DList[T]) PushBack

func (l *DList[T]) PushBack(val T)

PushBack pushes an element at the back of the list.

func (*DList[T]) PushFront

func (l *DList[T]) PushFront(val T)

PushFront pushes an element at the front of the list.

func (*DList[T]) TryPopBack

func (l *DList[T]) TryPopBack() (T, bool)

TryPopBack tries to pop up an element from the back of the list.

func (*DList[T]) TryPopFront

func (l *DList[T]) TryPopFront() (T, bool)

TryPopFront tries to pop up an element from the front of the list.

type Element

type Element[K, V any] struct {
	Node[K, V]
	// contains filtered or unexported fields
}

Element is a kind of node with key-value data

type Iterator

type Iterator[T any] interface {
	IsNotEnd() bool // Whether it is point to the end of the range.
	MoveToNext()    // Let it point to the next element.
	Value() T       // Return the value of current element.
}

Iterator is the interface for container's iterator.

type MapCompareResult

type MapCompareResult int
const (
	LeftKeyMiss MapCompareResult = iota + 1
	RightKeyMiss
	AllKeyMiss
	NotEqual
	Equal
	LeftLargeThanRight
	LeftLessThanRight
)

func MapCmpFullComplexKey

func MapCmpFullComplexKey[T comparable, V any](a map[T]V, b map[T]V) MapCompareResult

MapCmpFullComplexKey 复杂值的全部比较

func MapCmpFullSimpleKey

func MapCmpFullSimpleKey[T comparable, V ttypes.Ordered](a map[T]V, b map[T]V) MapCompareResult

MapCmpFullSimpleKey 简单值的全部比较

func MapCmpWithComplexKey

func MapCmpWithComplexKey[T comparable, V any](a map[T]V, b map[T]V, key T) MapCompareResult

MapCmpWithComplexKey 复杂值的key比较

func MapCmpWithSimpleKey

func MapCmpWithSimpleKey[T comparable, V ttypes.Ordered](a map[T]V, b map[T]V, key T) MapCompareResult

MapCmpWithSimpleKey 简单值的key比较

type MapLocker

type MapLocker[K comparable, V any] struct {
	// contains filtered or unexported fields
}

MapLocker 带锁的map,用于简单的并发读写场景

func MapNewMapLocker

func MapNewMapLocker[K comparable, V any]() *MapLocker[K, V]

func (*MapLocker[K, V]) Contain

func (m *MapLocker[K, V]) Contain(key K) bool

func (*MapLocker[K, V]) Foreach

func (m *MapLocker[K, V]) Foreach(handler func(key K, value V))

func (*MapLocker[K, V]) Get

func (m *MapLocker[K, V]) Get(key K) (V, bool)

func (*MapLocker[K, V]) Set

func (m *MapLocker[K, V]) Set(key K, value V)

type MapRWLocker

type MapRWLocker[K comparable, V any] struct {
	// contains filtered or unexported fields
}

MapRWLocker 简单的读写锁map

func MapNewMapRWLocker

func MapNewMapRWLocker[K comparable, V any]() *MapRWLocker[K, V]

func (*MapRWLocker[K, V]) Contain

func (m *MapRWLocker[K, V]) Contain(key K) bool

func (*MapRWLocker[K, V]) Foreach

func (m *MapRWLocker[K, V]) Foreach(handler func(key K, value V))

func (*MapRWLocker[K, V]) Get

func (m *MapRWLocker[K, V]) Get(key K) (V, bool)

func (*MapRWLocker[K, V]) Set

func (m *MapRWLocker[K, V]) Set(key K, value V)

type MutableIterator

type MutableIterator[T any] interface {
	Iterator[T]
	Pointer() *T // Return the pointer to the value of current element.
}

MutableIterator is the interface for container's mutable iterator.

type Node

type Node[K, V any] struct {
	// contains filtered or unexported fields
}

Node is a list node

type Option

type Option func(option *Options)

Option is a function used to set Options

func WithMaxLevel

func WithMaxLevel(maxLevel int) Option

WithMaxLevel sets max level of Skiplist

type Options

type Options struct {
	// contains filtered or unexported fields
}

Options holds Skiplist's options

type Queue

type Queue[T any] struct {
	// contains filtered or unexported fields
}

Queue represents a single instance of the queue data structure.

func NewRing

func NewRing[T any]() *Queue[T]

NewRing constructs and returns a new Queue.

func (*Queue[T]) Add

func (q *Queue[T]) Add(elem T)

Add puts an element on the end of the queue.

func (*Queue[T]) Get

func (q *Queue[T]) Get(i int) T

Get returns the element at index i in the queue. If the index is invalid, the call will panic. This method accepts both positive and negative index values. Index 0 refers to the first element, and index -1 refers to the last.

func (*Queue[T]) Length

func (q *Queue[T]) Length() int

Length returns the number of elements currently stored in the queue.

func (*Queue[T]) Peek

func (q *Queue[T]) Peek() T

Peek returns the element at the head of the queue. This call panics if the queue is empty.

func (*Queue[T]) Remove

func (q *Queue[T]) Remove() T

Remove removes and returns the element from the front of the queue. If the queue is empty, the call will panic.

type SList

type SList[T any] struct {
	// contains filtered or unexported fields
}

SList is a singly linked list.

func SListOf

func SListOf[T any](values ...T) SList[T]

SListOf return a SList that contains values.

func (*SList[T]) Back

func (l *SList[T]) Back() T

Back returns the last element in the list.

func (*SList[T]) Clear

func (l *SList[T]) Clear()

Clear erases all elements from the container. After this call, Len() returns zero.

func (*SList[T]) ForEach

func (l *SList[T]) ForEach(cb func(T))

ForEach iterate the list, apply each element to the cb callback function.

func (*SList[T]) ForEachIf

func (l *SList[T]) ForEachIf(cb func(T) bool)

ForEachIf iterate the container, apply each element to the cb callback function, stop if cb returns false.

func (*SList[T]) ForEachMutable

func (l *SList[T]) ForEachMutable(cb func(*T))

ForEachMutable iterate the container, apply pointer of each element to the cb callback function.

func (*SList[T]) ForEachMutableIf

func (l *SList[T]) ForEachMutableIf(cb func(*T) bool)

ForEachMutableIf iterate the container, apply pointer of each element to the cb callback function, stop if cb returns false.

func (*SList[T]) Front

func (l *SList[T]) Front() T

Front returns the first element in the list.

func (*SList[T]) IsEmpty

func (l *SList[T]) IsEmpty() bool

IsEmpty checks if the container has no elements.

func (*SList[T]) Iterate

func (l *SList[T]) Iterate() MutableIterator[T]

Iterate returns an iterator to the whole container.

func (*SList[T]) Len

func (l *SList[T]) Len() int

Len returns the number of elements in the container.

func (*SList[T]) PopFront

func (l *SList[T]) PopFront() T

PopFront popups an element from the front of the list. The list must be non-empty!

func (*SList[T]) PushBack

func (l *SList[T]) PushBack(v T)

PushBack pushed an element to the tail of the list.

func (*SList[T]) PushFront

func (l *SList[T]) PushFront(v T)

PushFront pushed an element to the front of the list.

func (*SList[T]) Reverse

func (l *SList[T]) Reverse()

Reverse reverses the order of all elements in the container.

func (*SList[T]) Values

func (l *SList[T]) Values() []T

Values copies all elements in the container to a slice and return it.

type Skiplist

type Skiplist[K, V any] struct {
	// contains filtered or unexported fields
}

Skiplist is a kind of data structure which can search quickly by exchanging space for time

func NewSkipList

func NewSkipList[K, V any](cmp ttypes.CompareFn[K], opts ...Option) *Skiplist[K, V]

NewSkipList news a Skiplist

func (*Skiplist[K, V]) Get

func (sl *Skiplist[K, V]) Get(key K) (V, error)

Get returns the value associated with the passed key if the key is in the skiplist, otherwise returns error

func (*Skiplist[K, V]) Insert

func (sl *Skiplist[K, V]) Insert(key K, value V)

Insert inserts a key-value pair into the skiplist

func (*Skiplist[K, V]) Keys

func (sl *Skiplist[K, V]) Keys() []K

Keys returns all keys in the skiplist

func (*Skiplist[K, V]) Len

func (sl *Skiplist[K, V]) Len() int

Len returns the amount of key-value pair in the skiplist

func (*Skiplist[K, V]) Remove

func (sl *Skiplist[K, V]) Remove(key K) bool

Remove removes the key-value pair associated with the passed key and returns true if the key is in the skiplist, otherwise returns false

func (*Skiplist[K, V]) Traversal

func (sl *Skiplist[K, V]) Traversal(visitor func(k K, v V) bool)

Traversal traversals elements in the skiplist, it will stop until to the end or the visitor returns false

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 MapNewSortedMap

func MapNewSortedMap[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的有序行

type Stack

type Stack[T any] struct {
	// contains filtered or unexported fields
}

Stack s is a container adaptor that provides the functionality of a stack, a LIFO (last-in, first-out) data structure.

func NewStack

func NewStack[T any]() *Stack[T]

NewStack creates a new Stack object.

func NewStackCap

func NewStackCap[T any](capacity int) *Stack[T]

NewStackCap creates a new Stack object with the specified capacity.

func (*Stack[T]) Cap

func (s *Stack[T]) Cap() int

Cap returns the capacity of the stack.

func (*Stack[T]) Clear

func (s *Stack[T]) Clear()

Clear implements the Container interface.

func (*Stack[T]) IsEmpty

func (s *Stack[T]) IsEmpty() bool

IsEmpty implements the Container interface.

func (*Stack[T]) Len

func (s *Stack[T]) Len() int

Len implements the Container interface.

func (*Stack[T]) Pop

func (s *Stack[T]) Pop() T

Pop popups an element from the top of the stack. It must be called when IsEmpty() returned false, otherwise it will panic.

func (*Stack[T]) Push

func (s *Stack[T]) Push(t T)

Push pushes the element to the top of the stack.

func (*Stack[T]) Reset

func (s *Stack[T]) Reset()

func (*Stack[T]) Top

func (s *Stack[T]) Top() T

Top returns the top element in the stack. It must be called when s.IsEmpty() returned false, otherwise it will panic.

func (*Stack[T]) TryPop

func (s *Stack[T]) TryPop() (val T, ok bool)

TryPop tries to popup an element from the top of the stack.

type Tuple10E

type Tuple10E[A any, B any, C any, D any, E any, F any, G any, H any, I any, J any] struct {
	Tuple9E[A, B, C, D, E, F, G, H, I]
	E10 J
}

func NewTuple10E

func NewTuple10E[A any, B any, C any, D any, E any, F any, G any, H any, I any, J any](a A, b B, c C, d D, e E, f F, g G, h H, i I, j J) *Tuple10E[A, B, C, D, E, F, G, H, I, J]

func (*Tuple10E[A, B, C, D, E, F, G, H, I, J]) Unpack

func (t *Tuple10E[A, B, C, D, E, F, G, H, I, J]) Unpack() (A, B, C, D, E, F, G, H, I, J)

type Tuple2E

type Tuple2E[A any, B any] struct {
	E1 A
	E2 B
}

Tuple2E 自定义两个元素的Tuple

func NewTuple2E

func NewTuple2E[A any, B any](a A, b B) *Tuple2E[A, B]

func (*Tuple2E[A, B]) Unpack

func (t *Tuple2E[A, B]) Unpack() (A, B)

type Tuple3E

type Tuple3E[A any, B any, C any] struct {
	Tuple2E[A, B]
	E3 C
}

func NewTuple3E

func NewTuple3E[A any, B any, C any](a A, b B, c C) *Tuple3E[A, B, C]

func (*Tuple3E[A, B, C]) Unpack

func (t *Tuple3E[A, B, C]) Unpack() (A, B, C)

type Tuple4E

type Tuple4E[A any, B any, C any, D any] struct {
	Tuple3E[A, B, C]
	E4 D
}

func NewTuple4E

func NewTuple4E[A any, B any, C any, D any](a A, b B, c C, d D) *Tuple4E[A, B, C, D]

func (*Tuple4E[A, B, C, D]) Unpack

func (t *Tuple4E[A, B, C, D]) Unpack() (A, B, C, D)

type Tuple5E

type Tuple5E[A any, B any, C any, D any, E any] struct {
	Tuple4E[A, B, C, D]
	E5 E
}

func NewTuple5E

func NewTuple5E[A any, B any, C any, D any, E any](a A, b B, c C, d D, e E) *Tuple5E[A, B, C, D, E]

func (*Tuple5E[A, B, C, D, E]) Unpack

func (t *Tuple5E[A, B, C, D, E]) Unpack() (A, B, C, D, E)

type Tuple6E

type Tuple6E[A any, B any, C any, D any, E any, F any] struct {
	Tuple5E[A, B, C, D, E]
	E6 F
}

func NewTuple6E

func NewTuple6E[A any, B any, C any, D any, E any, F any](a A, b B, c C, d D, e E, f F) *Tuple6E[A, B, C, D, E, F]

func (*Tuple6E[A, B, C, D, E, F]) Unpack

func (t *Tuple6E[A, B, C, D, E, F]) Unpack() (A, B, C, D, E, F)

type Tuple7E

type Tuple7E[A any, B any, C any, D any, E any, F any, G any] struct {
	Tuple6E[A, B, C, D, E, F]
	E7 G
}

func NewTuple7E

func NewTuple7E[A any, B any, C any, D any, E any, F any, G any](a A, b B, c C, d D, e E, f F, g G) *Tuple7E[A, B, C, D, E, F, G]

func (*Tuple7E[A, B, C, D, E, F, G]) Unpack

func (t *Tuple7E[A, B, C, D, E, F, G]) Unpack() (A, B, C, D, E, F, G)

type Tuple8E

type Tuple8E[A any, B any, C any, D any, E any, F any, G any, H any] struct {
	Tuple7E[A, B, C, D, E, F, G]
	E8 H
}

func NewTuple8E

func NewTuple8E[A any, B any, C any, D any, E any, F any, G any, H any](a A, b B, c C, d D, e E, f F, g G, h H) *Tuple8E[A, B, C, D, E, F, G, H]

func (*Tuple8E[A, B, C, D, E, F, G, H]) Unpack

func (t *Tuple8E[A, B, C, D, E, F, G, H]) Unpack() (A, B, C, D, E, F, G, H)

type Tuple9E

type Tuple9E[A any, B any, C any, D any, E any, F any, G any, H any, I any] struct {
	Tuple8E[A, B, C, D, E, F, G, H]
	E9 I
}

func NewTuple9E

func NewTuple9E[A any, B any, C any, D any, E any, F any, G any, H any, I any](a A, b B, c C, d D, e E, f F, g G, h H, i I) *Tuple9E[A, B, C, D, E, F, G, H, I]

func (*Tuple9E[A, B, C, D, E, F, G, H, I]) Unpack

func (t *Tuple9E[A, B, C, D, E, F, G, H, I]) Unpack() (A, B, C, D, E, F, G, H, I)

type WaitFor

type WaitFor[T comparable] struct {
	// contains filtered or unexported fields
}

WaitFor holds the data to add and the time it should be added

type WaitForPriorityQueue

type WaitForPriorityQueue[T comparable] struct {
	// contains filtered or unexported fields
}

WaitForPriorityQueue implements a priority queue for WaitFor items.

WaitForPriorityQueue implements heap.Interface. The item occurring next in time (i.e., the item with the smallest readyAt) is at the root (index 0). Peek returns this minimum item at index 0. Pop returns the minimum item after it has been removed from the queue and placed at index Len()-1 by container/heap. Push adds an item at index Len(), and container/heap percolates it into the correct location.

func NewWaitForPriorityQueue

func NewWaitForPriorityQueue[T comparable]() *WaitForPriorityQueue[T]

func (*WaitForPriorityQueue[T]) Len

func (pq *WaitForPriorityQueue[T]) Len() int

func (*WaitForPriorityQueue[T]) Peek

func (pq *WaitForPriorityQueue[T]) Peek() *WaitFor[T]

Peek returns the item at the beginning of the queue, without removing the item or otherwise mutating the queue. It is safe to call directly.

func (*WaitForPriorityQueue[T]) Pop

func (pq *WaitForPriorityQueue[T]) Pop() *WaitFor[T]

Pop 弹出优先级队列元素

func (*WaitForPriorityQueue[T]) Push

func (pq *WaitForPriorityQueue[T]) Push(entry *WaitFor[T], ignore bool)

Push adds the entry to the priority queue, or updates the readyAt if it already exists in the queue

Jump to

Keyboard shortcuts

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