structure

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2023 License: MIT Imports: 6 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InArray added in v1.1.8

func InArray[T comparable](arr []T, key T) bool

Types

type ConcurrentMap

type ConcurrentMap[Key KeyType, Val any] struct {
	// contains filtered or unexported fields
}

ConcurrentMap represents safe concurrent map container

func NewConcurrentMap

func NewConcurrentMap[Key KeyType, T any]() *ConcurrentMap[Key, T]

func (*ConcurrentMap[Key, T]) Del added in v1.1.5

func (container *ConcurrentMap[Key, T]) Del(key Key)

Del remove keys from container

func (*ConcurrentMap[Key, T]) Find

func (container *ConcurrentMap[Key, T]) Find(key Key) (item T, err error)

Find returns item if key is not exist, returns not found error

func (*ConcurrentMap[Key, T]) Get

func (container *ConcurrentMap[Key, T]) Get(key Key) (item T, exist bool)

Get return item and exist

func (*ConcurrentMap[Key, T]) Iterator added in v1.1.8

func (container *ConcurrentMap[Key, T]) Iterator(fn func(key Key, val T))

func (*ConcurrentMap[Key, T]) Len added in v1.1.8

func (container *ConcurrentMap[Key, T]) Len() int

func (*ConcurrentMap[Key, T]) Set

func (container *ConcurrentMap[Key, T]) Set(key Key, value T)

Set sets map item

type DelayQueue added in v1.2.0

type DelayQueue struct {
	Data chan interface{} // 通过channel的方式输出数据,保证有序性
	// contains filtered or unexported fields
}

DelayQueue 延时队列

func NewDelayQueue added in v1.2.0

func NewDelayQueue(size int) *DelayQueue

func (*DelayQueue) Close added in v1.2.0

func (dq *DelayQueue) Close()

Close 关闭

func (*DelayQueue) Offer added in v1.2.0

func (dq *DelayQueue) Offer(elem interface{}, expiration int64)

Offer 插入一个数据以及设置其出列的时间

func (*DelayQueue) Poll added in v1.2.0

func (dq *DelayQueue) Poll(nowF func() int64)

Poll 根据时间函数读取队列数据

type KeyType added in v1.1.5

type KeyType interface {
	int | int16 | int32 | int64 | string
}

type LockFreeMap added in v1.1.9

type LockFreeMap[Key KeyType, Val any] struct {
	// contains filtered or unexported fields
}

func NewLockFreeMap added in v1.1.9

func NewLockFreeMap[Key KeyType, T any]() *LockFreeMap[Key, T]

func (*LockFreeMap[Key, T]) Del added in v1.1.9

func (container *LockFreeMap[Key, T]) Del(key Key)

Del remove keys from container

func (*LockFreeMap[Key, T]) Find added in v1.1.9

func (container *LockFreeMap[Key, T]) Find(key Key) (item T, err error)

Find returns item if key is not exist, returns not found error

func (*LockFreeMap[Key, T]) Get added in v1.1.9

func (container *LockFreeMap[Key, T]) Get(key Key) (item T, exist bool)

Get return item and exist

func (*LockFreeMap[Key, T]) Iterator added in v1.1.9

func (container *LockFreeMap[Key, T]) Iterator(fn func(key Key, val T))

func (*LockFreeMap[Key, T]) Len added in v1.1.9

func (container *LockFreeMap[Key, T]) Len() int

func (*LockFreeMap[Key, T]) Set added in v1.1.9

func (container *LockFreeMap[Key, T]) Set(key Key, value T)

Set sets map item

type Map added in v1.1.9

type Map[Key KeyType, Val any] interface {
	Get(key Key) (item Val, exist bool)
	Set(key Key, value Val)
	Del(key Key)
	Iterator(fn func(key Key, val Val))
	Len() int
}

type Queue added in v1.1.7

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

Queue represents a queue of any object

func NewQueue added in v1.1.7

func NewQueue[T any](size int) *Queue[T]

NewQueue returns a new queue with the given size

func (*Queue[T]) Empty added in v1.1.7

func (queue *Queue[T]) Empty() bool

Empty returns true if the queue is empty

func (*Queue[T]) Length added in v1.1.7

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

Length returns the length of queue

func (*Queue[T]) Offer added in v1.1.7

func (queue *Queue[T]) Offer(items ...T)

Offer push the active fd to the queue, it will be deposed when queue is full

func (*Queue[T]) Polling added in v1.1.7

func (queue *Queue[T]) Polling(stopCh <-chan struct{}, handler func(item T))

Polling poll with callback function

type Sharding added in v1.1.7

type Sharding[T any] []T

func NewSharding added in v1.1.7

func NewSharding[T any](size int, constructor func() T) Sharding[T]

func (Sharding[T]) GetShard added in v1.1.7

func (shard Sharding[T]) GetShard(num int) T

func (Sharding[T]) Iterator added in v1.1.7

func (shard Sharding[T]) Iterator(iterator func(T))

type Singleton added in v1.1.7

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

func NewSingleton added in v1.1.7

func NewSingleton[T any](constructor func() T) *Singleton[T]

func (*Singleton[T]) Get added in v1.1.7

func (s *Singleton[T]) Get() T

Jump to

Keyboard shortcuts

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