Documentation
¶
Index ¶
- Variables
- type ConcurrentMap
- func (m ConcurrentMap[K, V]) Clear()
- func (m ConcurrentMap[K, V]) Count() int
- func (m ConcurrentMap[K, V]) Delete(key K)
- func (m ConcurrentMap[K, V]) Load(key K) (V, bool)
- func (m ConcurrentMap[K, V]) LoadAndDelete(key K) (V, bool)
- func (m ConcurrentMap[K, V]) LoadOrStore(key K, value V) (actual V, loaded bool)
- func (m ConcurrentMap[K, V]) MarshalJSON() ([]byte, error)
- func (m ConcurrentMap[K, V]) ParallelRange(f func(key K, value V))
- func (m ConcurrentMap[K, V]) Range(f func(key K, value V) bool)
- func (m ConcurrentMap[K, V]) Store(key K, value V)
- func (m *ConcurrentMap[K, V]) UnmarshalJSON(b []byte) error
- type ConcurrentMapShared
- type Stringer
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 }
Map ConcurrentMap is a thread-safe map partitioned into shards to reduce lock contention.
func New ¶
func New[V any]() ConcurrentMap[string, V]
func NewStringer ¶
func NewStringer[K Stringer, V any]() ConcurrentMap[K, V]
func NewWithCustomShardingFunction ¶
func NewWithCustomShardingFunction[K comparable, V any](sharding func(key K) uint32) ConcurrentMap[K, V]
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]) Delete ¶
func (m ConcurrentMap[K, V]) Delete(key K)
Delete deletes the value for a key.
func (ConcurrentMap[K, V]) Load ¶
func (m ConcurrentMap[K, V]) Load(key K) (V, bool)
Load returns the value stored in the map for a key, or the zero value if no value is present. The ok result indicates whether value was found in the map. Fast path (no mutex): key found in read snapshot. Slow path (mutex): key is in dirty only; increments miss counter.
func (ConcurrentMap[K, V]) LoadAndDelete ¶
func (m ConcurrentMap[K, V]) LoadAndDelete(key K) (V, bool)
LoadAndDelete deletes the value for a key, returning the previous value if any. The loaded result reports whether the key was present. Fast path (no mutex): key found in read snapshot and successfully CAS-deleted. Slow path (mutex): key is in dirty only, or read was amended.
func (ConcurrentMap[K, V]) LoadOrStore ¶
func (m ConcurrentMap[K, V]) LoadOrStore(key K, value V) (actual V, loaded bool)
LoadOrStore returns the existing value for the key if present. Otherwise, it stores and returns the given value. The loaded result is true if the value was loaded, false if stored.
func (ConcurrentMap[K, V]) MarshalJSON ¶
func (m ConcurrentMap[K, V]) MarshalJSON() ([]byte, error)
func (ConcurrentMap[K, V]) ParallelRange ¶
func (m ConcurrentMap[K, V]) ParallelRange(f func(key K, value V))
ParallelRange calls f concurrently - one goroutine per shard - for every key-value pair in the map. f must be safe for concurrent calls from multiple goroutines. Unlike Range, there is no early-exit.
func (ConcurrentMap[K, V]) Range ¶
func (m ConcurrentMap[K, V]) Range(f func(key K, value V) bool)
Range calls f sequentially for each key and value present in the map. If f returns false, Range stops the iteration. Range promotes each shard's dirty map to read before iterating, then releases the lock - writers are not blocked during the iteration itself.
func (ConcurrentMap[K, V]) Store ¶
func (m ConcurrentMap[K, V]) Store(key K, value V)
Operations Store sets the value for a key. Fast path (no mutex): key is already in the read snapshot and not expunged. Slow path (mutex): new key, or key was expunged and must be re-added to dirty.
func (*ConcurrentMap[K, V]) UnmarshalJSON ¶
func (m *ConcurrentMap[K, V]) UnmarshalJSON(b []byte) error
type ConcurrentMapShared ¶
type ConcurrentMapShared[K comparable, V any] struct { // contains filtered or unexported fields }
ConcurrentMapShared is one cache-line-padded shard. Layout (64-bit): mu=8, read=8, dirty=8, misses=8 → 32 bytes → 32 pad → 64 total.
type Stringer ¶
type Stringer interface {
fmt.Stringer
comparable
}