Documentation ¶
Index ¶
- type ConcurrentHashMap
- func (m *ConcurrentHashMap[K, V]) Clear()
- func (m *ConcurrentHashMap[K, V]) Count() int
- func (m *ConcurrentHashMap[K, V]) Get(key K) (V, bool)
- func (m *ConcurrentHashMap[K, V]) GetShard(key K) *ConcurrentMapShared[K, V]
- func (m *ConcurrentHashMap[K, V]) Has(key K) bool
- func (m *ConcurrentHashMap[K, V]) IsEmpty() bool
- func (m *ConcurrentHashMap[K, V]) Items() map[K]V
- func (m *ConcurrentHashMap[K, V]) Iter() <-chan Tuple[K, V]deprecated
- func (m *ConcurrentHashMap[K, V]) IterBuffered() <-chan Tuple[K, V]
- func (m *ConcurrentHashMap[K, V]) IterCb(fn IterCb[K, V])
- func (m *ConcurrentHashMap[K, V]) Keys() []K
- func (m *ConcurrentHashMap[K, V]) MSet(data map[K]V)
- func (m *ConcurrentHashMap[K, V]) MarshalJSON() ([]byte, error)
- func (m *ConcurrentHashMap[K, V]) Pop(key K) (v V, exists bool)
- func (m *ConcurrentHashMap[K, V]) Remove(key K)
- func (m *ConcurrentHashMap[K, V]) RemoveCb(key K, cb RemoveCb[K, V]) bool
- func (m *ConcurrentHashMap[K, V]) Set(key K, value V)
- func (m *ConcurrentHashMap[K, V]) SetIfAbsent(key K, value V) bool
- func (m *ConcurrentHashMap[K, V]) UnmarshalJSON(b []byte) (err error)
- func (m *ConcurrentHashMap[K, V]) Upsert(key K, value V, cb UpsertCb[V]) (res V)
- type ConcurrentMapShared
- type IterCb
- type RemoveCb
- type Stringer
- type TreeMap
- type Tuple
- type UpsertCb
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ConcurrentHashMap ¶ added in v1.12.3
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 v1.12.4
func NewHashMap[K comparable, V any]() ConcurrentHashMap[K, V]
func NewStringMap ¶ added in v1.12.4
func NewStringMap[V any]() ConcurrentHashMap[string, V]
NewStringMap Creates a new concurrent map.
func NewStringer ¶ added in v1.12.3
func NewStringer[K Stringer, V any]() ConcurrentHashMap[K, V]
NewStringer Creates a new concurrent map.
func NewWithCustomShardingFunction ¶ added in v1.12.3
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 v1.12.3
func (m *ConcurrentHashMap[K, V]) Clear()
Clear removes all items from map.
func (*ConcurrentHashMap[K, V]) Count ¶ added in v1.12.3
func (m *ConcurrentHashMap[K, V]) Count() int
Count returns the number of elements within the map.
func (*ConcurrentHashMap[K, V]) Get ¶ added in v1.12.3
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 v1.12.3
func (m *ConcurrentHashMap[K, V]) GetShard(key K) *ConcurrentMapShared[K, V]
GetShard returns shard under given key
func (*ConcurrentHashMap[K, V]) Has ¶ added in v1.12.3
func (m *ConcurrentHashMap[K, V]) Has(key K) bool
Has Looks up an item under specified key
func (*ConcurrentHashMap[K, V]) IsEmpty ¶ added in v1.12.3
func (m *ConcurrentHashMap[K, V]) IsEmpty() bool
IsEmpty checks if map is empty.
func (*ConcurrentHashMap[K, V]) Items ¶ added in v1.12.3
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
v1.12.3
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 v1.12.3
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 v1.12.3
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 v1.12.3
func (m *ConcurrentHashMap[K, V]) Keys() []K
Keys returns all keys as []string
func (*ConcurrentHashMap[K, V]) MSet ¶ added in v1.12.3
func (m *ConcurrentHashMap[K, V]) MSet(data map[K]V)
func (*ConcurrentHashMap[K, V]) MarshalJSON ¶ added in v1.12.3
func (m *ConcurrentHashMap[K, V]) MarshalJSON() ([]byte, error)
MarshalJSON Reviles ConcurrentHashMap "private" variables to json marshal.
func (*ConcurrentHashMap[K, V]) Pop ¶ added in v1.12.3
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 v1.12.3
func (m *ConcurrentHashMap[K, V]) Remove(key K)
Remove removes an element from the map.
func (*ConcurrentHashMap[K, V]) RemoveCb ¶ added in v1.12.3
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 v1.12.3
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 v1.12.3
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 v1.12.3
func (m *ConcurrentHashMap[K, V]) UnmarshalJSON(b []byte) (err error)
UnmarshalJSON Reverse process of Marshal.
func (*ConcurrentHashMap[K, V]) Upsert ¶ added in v1.12.3
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 v1.12.3
type ConcurrentMapShared[K comparable, V any] struct { // contains filtered or unexported fields }
ConcurrentMapShared A "thread" safe string to anything map.
type IterCb ¶ added in v1.12.3
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 ¶ added in v1.12.3
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 v1.12.3
type Stringer interface { fmt.Stringer comparable }
type TreeMap ¶
type TreeMap[K comparable, V any] struct { // contains filtered or unexported fields }
type Tuple ¶ added in v1.12.3
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,