concurrent

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2025 License: Apache-2.0 Imports: 8 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ConcurrentHashMap added in v0.1.14

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

ConcurrentHashMap A "thread" safe map of type string:Anything. To avoid lock bottlenecks this map is dived to several (__SHARD_COUNT) map shards.

func NewHashMap added in v0.1.14

func NewHashMap[K comparable, V any]() ConcurrentHashMap[K, V]

func NewStringMap added in v0.1.14

func NewStringMap[V any]() ConcurrentHashMap[string, V]

NewStringMap Creates a new concurrent map.

func NewStringer added in v0.1.14

func NewStringer[K Stringer, V any]() ConcurrentHashMap[K, V]

NewStringer Creates a new concurrent map.

func NewWithCustomShardingFunction added in v0.1.14

func NewWithCustomShardingFunction[K comparable, V any](sharding func(key K) uint32) ConcurrentHashMap[K, V]

NewWithCustomShardingFunction Creates a new concurrent map.

func (*ConcurrentHashMap[K, V]) Clear added in v0.1.14

func (m *ConcurrentHashMap[K, V]) Clear()

Clear removes all items from map.

func (*ConcurrentHashMap[K, V]) Count added in v0.1.14

func (m *ConcurrentHashMap[K, V]) Count() int

Count returns the number of elements within the map.

func (*ConcurrentHashMap[K, V]) Get added in v0.1.14

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

Get retrieves an element from map under given key.

func (*ConcurrentHashMap[K, V]) GetShard added in v0.1.14

func (m *ConcurrentHashMap[K, V]) GetShard(key K) *ConcurrentMapShared[K, V]

GetShard returns shard under given key

func (*ConcurrentHashMap[K, V]) Has added in v0.1.14

func (m *ConcurrentHashMap[K, V]) Has(key K) bool

Has Looks up an item under specified key

func (*ConcurrentHashMap[K, V]) IsEmpty added in v0.1.14

func (m *ConcurrentHashMap[K, V]) IsEmpty() bool

IsEmpty checks if map is empty.

func (*ConcurrentHashMap[K, V]) Items added in v0.1.14

func (m *ConcurrentHashMap[K, V]) Items() map[K]V

Items returns all items as map[string]V

func (*ConcurrentHashMap[K, V]) Iter deprecated added in v0.1.14

func (m *ConcurrentHashMap[K, V]) Iter() <-chan Tuple[K, V]

Iter returns an iterator which could be used in a for range loop.

Deprecated: using IterBuffered() will get a better performence

func (*ConcurrentHashMap[K, V]) IterBuffered added in v0.1.14

func (m *ConcurrentHashMap[K, V]) IterBuffered() <-chan Tuple[K, V]

IterBuffered returns a buffered iterator which could be used in a for range loop.

func (*ConcurrentHashMap[K, V]) IterCb added in v0.1.14

func (m *ConcurrentHashMap[K, V]) IterCb(fn IterCb[K, V])

Callback based iterator, cheapest way to read all elements in a map.

func (*ConcurrentHashMap[K, V]) Keys added in v0.1.14

func (m *ConcurrentHashMap[K, V]) Keys() []K

Keys returns all keys as []string

func (*ConcurrentHashMap[K, V]) MSet added in v0.1.14

func (m *ConcurrentHashMap[K, V]) MSet(data map[K]V)

func (*ConcurrentHashMap[K, V]) MarshalJSON added in v0.1.14

func (m *ConcurrentHashMap[K, V]) MarshalJSON() ([]byte, error)

MarshalJSON Reviles ConcurrentHashMap "private" variables to json marshal.

func (*ConcurrentHashMap[K, V]) Pop added in v0.1.14

func (m *ConcurrentHashMap[K, V]) Pop(key K) (v V, exists bool)

Pop removes an element from the map and returns it

func (*ConcurrentHashMap[K, V]) Remove added in v0.1.14

func (m *ConcurrentHashMap[K, V]) Remove(key K)

Remove removes an element from the map.

func (*ConcurrentHashMap[K, V]) RemoveCb added in v0.1.14

func (m *ConcurrentHashMap[K, V]) RemoveCb(key K, cb RemoveCb[K, V]) bool

RemoveCb locks the shard containing the key, retrieves its current value and calls the callback with those params If callback returns true and element exists, it will remove it from the map Returns the value returned by the callback (even if element was not present in the map)

func (*ConcurrentHashMap[K, V]) Set added in v0.1.14

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

Set Sets the given value under the specified key.

func (*ConcurrentHashMap[K, V]) SetIfAbsent added in v0.1.14

func (m *ConcurrentHashMap[K, V]) SetIfAbsent(key K, value V) bool

SetIfAbsent Sets the given value under the specified key if no value was associated with it.

func (*ConcurrentHashMap[K, V]) UnmarshalJSON added in v0.1.14

func (m *ConcurrentHashMap[K, V]) UnmarshalJSON(b []byte) (err error)

UnmarshalJSON Reverse process of Marshal.

func (*ConcurrentHashMap[K, V]) Upsert added in v0.1.14

func (m *ConcurrentHashMap[K, V]) Upsert(key K, value V, cb UpsertCb[V]) (res V)

Upsert Insert or Update - updates existing element or inserts a new one using UpsertCb

type ConcurrentMapShared added in v0.1.14

type ConcurrentMapShared[K comparable, V any] struct {
	sync.RWMutex // Read Write mutex, guards access to internal map.
	// contains filtered or unexported fields
}

ConcurrentMapShared A "thread" safe string to anything map.

type DailyOnce

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

func NewDailyOnce

func NewDailyOnce() *DailyOnce

func (*DailyOnce) Do

func (d *DailyOnce) Do(initFunc func())

获取数据(自动处理每日重置)

type IterCb added in v0.1.14

type IterCb[K comparable, V any] func(key K, v V)

Iterator callbacalled for every key,value found in maps. RLock is held for all calls for a given shard therefore callback sess consistent view of a shard, but not across the shards

type PeriodOnce

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

PeriodOnce 周期性懒加载锁

func CreatePeriodOnceWithHourAndMinute added in v0.0.19

func CreatePeriodOnceWithHourAndMinute(hour, minute int) *PeriodOnce

CreatePeriodOnceWithHourAndMinute 创建每日按时分初始化的周期性懒加载锁

func CreatePeriodOnceWithSecond added in v0.0.19

func CreatePeriodOnceWithSecond(seconds int) *PeriodOnce

CreatePeriodOnceWithSecond 创建间隔秒数初始化的周期性懒加载锁

func (*PeriodOnce) Do

func (o *PeriodOnce) Do(f func())

type RemoveCb added in v0.1.14

type RemoveCb[K any, V any] func(key K, v V, exists bool) bool

RemoveCb is a callback executed in a map.RemoveCb() call, while Lock is held If returns true, the element will be removed from the map

type Stringer added in v0.1.14

type Stringer interface {
	fmt.Stringer
	comparable
}

type TreeMap added in v0.1.14

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

func NewTreeMap added in v0.1.14

func NewTreeMap[K cmp.Ordered, V any]() *TreeMap[K, V]

func (*TreeMap[K, V]) Clear added in v0.1.14

func (m *TreeMap[K, V]) Clear()

func (*TreeMap[K, V]) Each added in v0.1.14

func (m *TreeMap[K, V]) Each(f func(key K, value V))

func (*TreeMap[K, V]) Get added in v0.1.14

func (m *TreeMap[K, V]) Get(k K) (v V, found bool)

func (*TreeMap[K, V]) Put added in v0.1.14

func (m *TreeMap[K, V]) Put(k K, v V)

func (*TreeMap[K, V]) Size added in v0.1.14

func (m *TreeMap[K, V]) Size() int

type Tuple added in v0.1.14

type Tuple[K comparable, V any] struct {
	Key K
	Val V
}

Tuple Used by the Iter & IterBuffered functions to wrap two variables together over a channel,

type UpsertCb added in v0.1.14

type UpsertCb[V any] func(exist bool, valueInMap V, newValue V) V

UpsertCb Callback to return new element to be inserted into the map It is called while lock is held, therefore it MUST NOT try to access other keys in same map, as it can lead to deadlock since Go sync.RWLock is not reentrant

Jump to

Keyboard shortcuts

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