Documentation
¶
Index ¶
- Variables
- type ConcurrentMap
- func (m ConcurrentMap[K, V]) Clear()
- func (m ConcurrentMap[K, V]) Count() int
- func (m ConcurrentMap[K, V]) Get(key K) (V, bool)
- func (m ConcurrentMap[K, V]) GetCb(key K, cb GetCb[V])
- func (m ConcurrentMap[K, V]) GetOrInsert(key K, cb InsertCb[V]) V
- func (m ConcurrentMap[K, V]) GetShard(key K) *SafeMap[K, V]
- func (m ConcurrentMap[K, V]) Has(key K) bool
- func (m ConcurrentMap[K, V]) IsEmpty() bool
- func (m ConcurrentMap[K, V]) Items() map[K]V
- func (m ConcurrentMap[K, V]) IterBuffered() <-chan Tuple[K, V]
- func (m ConcurrentMap[K, V]) IterCb(fn IterCb[K, V])
- func (m ConcurrentMap[K, V]) Keys() []K
- func (m ConcurrentMap[K, V]) MSet(data map[K]V)
- func (m ConcurrentMap[K, V]) MarshalJSON() ([]byte, error)
- func (m ConcurrentMap[K, V]) Pop(key K) (value V, exists bool)
- func (m ConcurrentMap[K, V]) Remove(key K)
- func (m ConcurrentMap[K, V]) RemoveCb(key K, cb RemoveCb[K, V]) (ok bool)
- func (m ConcurrentMap[K, V]) Set(key K, value V)
- func (m ConcurrentMap[K, V]) SetIfAbsent(key K, value V) (ok bool)
- func (m ConcurrentMap[K, V]) SetIfExists(key K, value V) (ok bool)
- func (m *ConcurrentMap[K, V]) UnmarshalJSON(b []byte) error
- func (m ConcurrentMap[K, V]) Upsert(key K, cb UpsertCb[V]) (result V)
- func (m ConcurrentMap[K, V]) Values() []V
- type GetCb
- type InsertCb
- type IterCb
- type RemoveCb
- type SafeMap
- func (s *SafeMap[K, V]) Clone() map[K]V
- func (s *SafeMap[K, V]) Count() int
- func (s *SafeMap[K, V]) Del(key K)
- func (s *SafeMap[K, V]) Find(fn func(key K, value V, exist bool), keys ...K)
- func (s *SafeMap[K, V]) Get(key K) (V, bool)
- func (s *SafeMap[K, V]) GetCb(key K, cb func(value V, exists bool))
- func (s *SafeMap[K, V]) MarshalJSON() ([]byte, error)
- func (s *SafeMap[K, V]) Set(key K, value V)
- func (s *SafeMap[K, V]) UnmarshalJSON(b []byte) (err error)
- func (s *SafeMap[K, V]) Update(fn func(map[K]V))
- func (s *SafeMap[K, V]) View(fn func(K, V))
- type ShardingFunc
- type Stringer
- type Tuple
- type UpsertCb
Constants ¶
This section is empty.
Variables ¶
var SHARD_COUNT = 32
Functions ¶
This section is empty.
Types ¶
type ConcurrentMap ¶
type ConcurrentMap[K comparable, V any] struct { // contains filtered or unexported fields }
A "thread" safe map of type string:Anything. To avoid lock bottlenecks this map is dived to several (SHARD_COUNT) map shards.
func NewStringer ¶
func NewStringer[K Stringer, V any]() ConcurrentMap[K, V]
Creates a new concurrent map.
func NewWithCustom ¶ added in v1.4.0
func NewWithCustom[K comparable, V any](sharding ShardingFunc[K, V]) ConcurrentMap[K, V]
Creates a new concurrent map.
func (ConcurrentMap[K, V]) Clear ¶
func (m ConcurrentMap[K, V]) Clear()
Clear removes all items from map.
func (ConcurrentMap[K, V]) Count ¶
func (m ConcurrentMap[K, V]) Count() int
Count returns the number of elements within the map.
func (ConcurrentMap[K, V]) Get ¶
func (m ConcurrentMap[K, V]) Get(key K) (V, bool)
Get retrieves an element from map under given key.
func (ConcurrentMap[K, V]) GetCb ¶ added in v1.3.0
func (m ConcurrentMap[K, V]) GetCb(key K, cb GetCb[V])
GetCb locks the shard containing the key, retrieves its current value and calls the callback with those params
func (ConcurrentMap[K, V]) GetOrInsert ¶
func (m ConcurrentMap[K, V]) GetOrInsert(key K, cb InsertCb[V]) V
GetOrInsert The method is used to retrieve the value corresponding to a key in ConcurrentMap. If the key does not exist, a new value will be inserted using the provided callback function.
func (ConcurrentMap[K, V]) GetShard ¶
func (m ConcurrentMap[K, V]) GetShard(key K) *SafeMap[K, V]
GetShard returns shard under given key
func (ConcurrentMap[K, V]) Has ¶
func (m ConcurrentMap[K, V]) Has(key K) bool
Looks up an item under specified key
func (ConcurrentMap[K, V]) IsEmpty ¶
func (m ConcurrentMap[K, V]) IsEmpty() bool
IsEmpty checks if map is empty.
func (ConcurrentMap[K, V]) Items ¶
func (m ConcurrentMap[K, V]) Items() map[K]V
Items returns all items as map[K]V
func (ConcurrentMap[K, V]) IterBuffered ¶
func (m ConcurrentMap[K, V]) IterBuffered() <-chan Tuple[K, V]
IterBuffered returns a Iter iterator which could be used in a for range loop.
func (ConcurrentMap[K, V]) IterCb ¶
func (m ConcurrentMap[K, V]) IterCb(fn IterCb[K, V])
Callback based iterator, cheapest way to read all elements in a map.
func (ConcurrentMap[K, V]) Keys ¶
func (m ConcurrentMap[K, V]) Keys() []K
Keys returns all keys as []K
func (ConcurrentMap[K, V]) MSet ¶
func (m ConcurrentMap[K, V]) MSet(data map[K]V)
func (ConcurrentMap[K, V]) MarshalJSON ¶
func (m ConcurrentMap[K, V]) MarshalJSON() ([]byte, error)
Reviles ConcurrentMap "private" variables to json marshal.
func (ConcurrentMap[K, V]) Pop ¶
func (m ConcurrentMap[K, V]) Pop(key K) (value V, exists bool)
Pop removes an element from the map and returns it
func (ConcurrentMap[K, V]) Remove ¶
func (m ConcurrentMap[K, V]) Remove(key K)
Remove removes an element from the map.
func (ConcurrentMap[K, V]) RemoveCb ¶
func (m ConcurrentMap[K, V]) RemoveCb(key K, cb RemoveCb[K, V]) (ok 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 (ConcurrentMap[K, V]) Set ¶
func (m ConcurrentMap[K, V]) Set(key K, value V)
Sets the given value under the specified key.
func (ConcurrentMap[K, V]) SetIfAbsent ¶
func (m ConcurrentMap[K, V]) SetIfAbsent(key K, value V) (ok bool)
Sets the given value under the specified key if no value was associated with it.
func (ConcurrentMap[K, V]) SetIfExists ¶ added in v1.4.0
func (m ConcurrentMap[K, V]) SetIfExists(key K, value V) (ok bool)
Sets the given value under the specified key if a value was associated with it.
func (*ConcurrentMap[K, V]) UnmarshalJSON ¶
func (m *ConcurrentMap[K, V]) UnmarshalJSON(b []byte) error
Reverse process of Marshal.
func (ConcurrentMap[K, V]) Upsert ¶
func (m ConcurrentMap[K, V]) Upsert(key K, cb UpsertCb[V]) (result V)
Insert or Update - updates existing element or inserts a new one using UpsertCb
func (ConcurrentMap[K, V]) Values ¶
func (m ConcurrentMap[K, V]) Values() []V
Values returns all Values as []V
type GetCb ¶ added in v1.3.0
GetCb is a callback executed in a map.GetCb() call, while Lock is held If returns true, the element will be inserted into the map
type IterCb ¶
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 RemoveCb ¶
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 SafeMap ¶
type SafeMap[K comparable, V any] struct { // contains filtered or unexported fields }
func NewSafe ¶ added in v1.4.0
func NewSafe[K comparable, V any]() *SafeMap[K, V]
NewSafe 创建一个新的键和值类型为 K 和 V 的 SafeMap 类型指针
func (*SafeMap[K, V]) MarshalJSON ¶
func (*SafeMap[K, V]) UnmarshalJSON ¶
Reverse process of Marshal.
type ShardingFunc ¶
type ShardingFunc[K comparable, V any] func(key K) uint32
type Stringer ¶
type Stringer interface { fmt.Stringer comparable }
type Tuple ¶
type Tuple[K comparable, V any] struct { Key K Val V }
Used by the Iter & IterBuffered functions to wrap two variables together over a channel,