Documentation ¶
Index ¶
- Constants
- type ConcurrentMap
- func (c *ConcurrentMap[KEY, VAL]) At(key KEY) (VAL, bool)
- func (c *ConcurrentMap[KEY, VAL]) Data() map[KEY]VAL
- func (c *ConcurrentMap[KEY, VAL]) Len() int
- func (c *ConcurrentMap[KEY, VAL]) Remove(key KEY) bool
- func (c *ConcurrentMap[KEY, VAL]) Reset()
- func (c *ConcurrentMap[KEY, VAL]) Set(key KEY, val VAL)
- func (c *ConcurrentMap[KEY, VAL]) SetIfAbsent(key KEY, val VAL) bool
- func (c *ConcurrentMap[KEY, VAL]) SetIfPresent(key KEY, val VAL) bool
Constants ¶
const ShardCount = 128
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ConcurrentMap ¶
type ConcurrentMap[KEY comparable, VAL any] struct { // contains filtered or unexported fields }
ConcurrentMap is a sharded, thread-safe mapping of keys to values.
func NewConcurrentMap ¶
func NewConcurrentMap[KEY comparable, VAL any]() *ConcurrentMap[KEY, VAL]
NewConcurrentMap creates a new ConcurrentMap.
func (*ConcurrentMap[KEY, VAL]) At ¶
func (c *ConcurrentMap[KEY, VAL]) At(key KEY) (VAL, bool)
At returns the value for the given key and a bool indicating whether or not the given key exists in the map. If the given key does not exist, then the zero-value of VAL and false are returned.
func (*ConcurrentMap[KEY, VAL]) Data ¶
func (c *ConcurrentMap[KEY, VAL]) Data() map[KEY]VAL
Data returns the contents of all ConcurrentMap shards as a map[KEY]VAL.
func (*ConcurrentMap[KEY, VAL]) Len ¶
func (c *ConcurrentMap[KEY, VAL]) Len() int
Len returns the number of keys in the map.
func (*ConcurrentMap[KEY, VAL]) Remove ¶
func (c *ConcurrentMap[KEY, VAL]) Remove(key KEY) bool
Remove deletes the element with the specified key from the map, if it exists. A boolean is returned indicating whether or not any deletion was necessary.
func (*ConcurrentMap[KEY, VAL]) Reset ¶
func (c *ConcurrentMap[KEY, VAL]) Reset()
func (*ConcurrentMap[KEY, VAL]) Set ¶
func (c *ConcurrentMap[KEY, VAL]) Set(key KEY, val VAL)
Set inserts the given val at the specified key, or overrides the current value for that key if there is one.
func (*ConcurrentMap[KEY, VAL]) SetIfAbsent ¶
func (c *ConcurrentMap[KEY, VAL]) SetIfAbsent(key KEY, val VAL) bool
SetIfAbsent inserts the given val at the specified key, so long as the specified key does not already exist in the map. A bool is returned indicating whether or not the insert took place.
func (*ConcurrentMap[KEY, VAL]) SetIfPresent ¶
func (c *ConcurrentMap[KEY, VAL]) SetIfPresent(key KEY, val VAL) bool
SetIfPresent inserts the given val at the specified key, so long as the specified key already exists in the map. A bool is returned indicating whether or not the insert took place.