ds

package
v0.0.21 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ArrayStack

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

func NewArrayStack

func NewArrayStack[T any]() *ArrayStack[T]

func (*ArrayStack[T]) Empty

func (m *ArrayStack[T]) Empty() bool

func (*ArrayStack[T]) Peek

func (m *ArrayStack[T]) Peek() (value T, exist bool)

func (*ArrayStack[T]) Pop

func (m *ArrayStack[T]) Pop() (value T, exist bool)

func (*ArrayStack[T]) Push

func (m *ArrayStack[T]) Push(value T)

func (*ArrayStack[T]) Size

func (m *ArrayStack[T]) Size() int

func (*ArrayStack[T]) String

func (m *ArrayStack[T]) String() string

type Cache

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

func NewCache

func NewCache[T any](opt *CacheOpt) *Cache[T]

func (*Cache[T]) Delete

func (c *Cache[T]) Delete(key string)

func (*Cache[T]) Get

func (c *Cache[T]) Get(key string) (value T, loaded bool)

func (*Cache[T]) Set

func (c *Cache[T]) Set(key string, value T)

func (*Cache[T]) SetWithExpire

func (c *Cache[T]) SetWithExpire(key string, value T, expire time.Duration)

type CacheOpt

type CacheOpt struct {
	Expire  time.Duration
	Cleanup time.Duration
}

type DestroyFunc

type DestroyFunc[V any] func(ctx context.Context, value V) error

type HashSet

type HashSet[T comparable] map[T]struct{}

func NewHashSet

func NewHashSet[T comparable](items ...T) HashSet[T]

Create a new Set with element type T

func (HashSet[T]) Append

func (s HashSet[T]) Append(items ...T)

func (HashSet[T]) Contains

func (s HashSet[T]) Contains(value T) (exist bool)

func (HashSet[T]) Difference

func (s HashSet[T]) Difference(s1 Set[T]) Set[T]

Difference 返回两个集合的对称差集

func (HashSet[T]) Intersection

func (s HashSet[T]) Intersection(s1 Set[T]) Set[T]

Intersection 返回两个集合的交集

func (HashSet[T]) Len

func (s HashSet[T]) Len() int

func (HashSet[T]) Remove

func (s HashSet[T]) Remove(values ...T) bool

func (HashSet[T]) String

func (s HashSet[T]) String() string

func (HashSet[T]) SymmetricDifference

func (s HashSet[T]) SymmetricDifference(s1 Set[T]) Set[T]

Difference 返回两个集合的差集

func (HashSet[T]) Union

func (s HashSet[T]) Union(s1 Set[T]) Set[T]

Union 返回两个集合的并集

func (HashSet[T]) Values

func (s HashSet[T]) Values() (values []T)

type IDFunc

type IDFunc[K any] func(key K) string

type LinkStack

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

func NewLinkStack

func NewLinkStack[T any]() *LinkStack[T]

func (*LinkStack[T]) Empty

func (m *LinkStack[T]) Empty() bool

func (*LinkStack[T]) Peek

func (m *LinkStack[T]) Peek() (value T, exist bool)

func (*LinkStack[T]) Pop

func (m *LinkStack[T]) Pop() (value T, exist bool)

func (*LinkStack[T]) Push

func (m *LinkStack[T]) Push(value T)

func (*LinkStack[T]) Size

func (m *LinkStack[T]) Size() int

type Map

type Map[K comparable, V any] interface {
	// 存储
	Store(K, V)
	// 读取
	Load(K) (V, bool)
	// 删除
	Delete(K) bool
	// 交换
	Swap(key K, newValue V) (old V, loaded bool)
	// 遍历,当iterator返回false时,遍历终止
	Range(iterator func(K, V) bool)
	// 读取或将值存储
	LoadOrStore(key K, newValue V) (value V, loaded bool)
	// 读取并删除
	LoadAndDelete(K) (value V, loaded bool)
	// 对比并交换
	// 对比当前map中key对应的value是否等于old,如果相等则将key对应的value替换为newValue
	CompareAndSwap(key K, old, newValue V) bool
	// 对比并删除
	// 对比当前map中key对应的value是否等于value,如果相等则删除
	CompareAndDelete(key K, value V) bool
	CompareFnAndSwap(key K, fn func(V, V) bool, old, newValue V) bool
	CompareFnAndDelete(key K, fn func(V, V) bool, old V) bool
}

type MutexMap

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

func NewMutexMap

func NewMutexMap[K comparable, V any]() *MutexMap[K, V]

func (*MutexMap[K, V]) CompareAndDelete

func (m *MutexMap[K, V]) CompareAndDelete(key K, old V) bool

func (*MutexMap[K, V]) CompareAndSwap

func (m *MutexMap[K, V]) CompareAndSwap(key K, old, new V) bool

func (*MutexMap[K, V]) CompareFnAndDelete

func (m *MutexMap[K, V]) CompareFnAndDelete(key K, fn func(V, V) bool, old V) bool

func (*MutexMap[K, V]) CompareFnAndSwap

func (m *MutexMap[K, V]) CompareFnAndSwap(key K, fn func(V, V) bool, old, new V) bool

func (*MutexMap[K, V]) Delete

func (m *MutexMap[K, V]) Delete(key K) bool

func (*MutexMap[K, V]) Load

func (m *MutexMap[K, V]) Load(key K) (value V, ok bool)

func (*MutexMap[K, V]) LoadAndDelete

func (m *MutexMap[K, V]) LoadAndDelete(key K) (value V, loaded bool)

func (*MutexMap[K, V]) LoadOrStore

func (m *MutexMap[K, V]) LoadOrStore(key K, new V) (actual V, loaded bool)

func (*MutexMap[K, V]) Range

func (m *MutexMap[K, V]) Range(iterator func(key K, value V) bool)

func (*MutexMap[K, V]) Store

func (m *MutexMap[K, V]) Store(key K, value V)

func (*MutexMap[K, V]) Swap

func (m *MutexMap[K, V]) Swap(key K, value V) (pre V, loaded bool)

type NewFunc

type NewFunc[K, V any] func(ctx context.Context, key K) (V, error)

type Pool

type Pool[K, V any] struct {
	New        NewFunc[K, V]
	Identifier IDFunc[K]
	Destroy    DestroyFunc[V]
	// contains filtered or unexported fields
}

func (*Pool[K, V]) Get

func (p *Pool[K, V]) Get(ctx context.Context, key K) (value V, err error)

func (*Pool[K, V]) GetWithCtx

func (p *Pool[K, V]) GetWithCtx(ctx context.Context, key K) (value V, err error)

func (*Pool[K, V]) Put

func (p *Pool[K, V]) Put(key K) (err error)

func (*Pool[K, V]) PutWithCtx

func (p *Pool[K, V]) PutWithCtx(ctx context.Context, key K) (err error)

type Set

type Set[T comparable] interface {
	fmt.Stringer
	// 集合长度
	Len() int
	// 添加元素
	Append(...T)
	// 移除元素
	Remove(...T) bool
	// 判断元素是否存在
	Contains(T) bool
	// 集合元素的切片
	Values() []T
	// 并集
	Union(Set[T]) Set[T]
	// 交集
	Intersection(Set[T]) Set[T]
	// 差集
	Difference(Set[T]) Set[T]
	// 对称差集
	SymmetricDifference(Set[T]) Set[T]
}

type Stack

type Stack[T any] interface {
	Push(T)
	Pop() (T, bool)
	Peek() (T, bool)
	Empty() bool
	Size() int
}

type SyncMap

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

Generic wrapper for sync.Map

func NewSyncMap

func NewSyncMap[K comparable, V any]() *SyncMap[K, V]

func (*SyncMap[K, V]) CompareAndDelete

func (m *SyncMap[K, V]) CompareAndDelete(key K, old V) bool

func (*SyncMap[K, V]) CompareAndSwap

func (m *SyncMap[K, V]) CompareAndSwap(key K, old, new V) bool

func (*SyncMap[K, V]) CompareFnAndDelete

func (m *SyncMap[K, V]) CompareFnAndDelete(key K, fn func(V, V) bool, old V) bool

func (*SyncMap[K, V]) CompareFnAndSwap

func (m *SyncMap[K, V]) CompareFnAndSwap(key K, fn func(V, V) bool, old, new V) bool

func (*SyncMap[K, V]) Delete

func (m *SyncMap[K, V]) Delete(key K) bool

func (*SyncMap[K, V]) Load

func (m *SyncMap[K, V]) Load(key K) (value V, ok bool)

func (*SyncMap[K, V]) LoadAndDelete

func (m *SyncMap[K, V]) LoadAndDelete(key K) (value V, loaded bool)

func (*SyncMap[K, V]) LoadOrStore

func (m *SyncMap[K, V]) LoadOrStore(key K, new V) (actual V, loaded bool)

func (*SyncMap[K, V]) Range

func (m *SyncMap[K, V]) Range(iterator func(key K, value V) bool)

func (*SyncMap[K, V]) Store

func (m *SyncMap[K, V]) Store(key K, value V)

func (*SyncMap[K, V]) Swap

func (m *SyncMap[K, V]) Swap(key K, value V) (pre V, loaded bool)

type SyncSet

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

func NewSyncSet

func NewSyncSet[T comparable](items ...T) *SyncSet[T]

Create a new Set with element type T

func (*SyncSet[T]) Append

func (s *SyncSet[T]) Append(values ...T)

添加元素

func (*SyncSet[T]) Contains

func (s *SyncSet[T]) Contains(v T) bool

判断元素是否存在

func (*SyncSet[T]) Difference

func (s *SyncSet[T]) Difference(s1 Set[T]) Set[T]

差集

func (*SyncSet[T]) Intersection

func (s *SyncSet[T]) Intersection(s1 Set[T]) Set[T]

交集

func (*SyncSet[T]) Len

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

集合长度

func (*SyncSet[T]) Remove

func (s *SyncSet[T]) Remove(values ...T) bool

移除元素

func (*SyncSet[T]) String

func (s *SyncSet[T]) String() string

func (*SyncSet[T]) SymmetricDifference

func (s *SyncSet[T]) SymmetricDifference(s1 Set[T]) Set[T]

对称差集

func (*SyncSet[T]) Union

func (s *SyncSet[T]) Union(s1 Set[T]) Set[T]

并集

func (*SyncSet[T]) Values

func (s *SyncSet[T]) Values() []T

集合元素的切片

Jump to

Keyboard shortcuts

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