Documentation
¶
Index ¶
- Constants
- type ConcurrentMap
- func (m ConcurrentMap[K, V]) Count() int
- func (m ConcurrentMap[K, V]) Get(key K) (V, bool)
- func (m ConcurrentMap[K, V]) GetAndRemove(key K) (V, bool)
- func (m ConcurrentMap[K, V]) GetOrCreate(key K, new func() V) (V, bool)
- func (m ConcurrentMap[K, V]) GetShard(key K) *ConcurrentMapShared[K, V]
- func (m ConcurrentMap[K, V]) Has(key K) bool
- func (m ConcurrentMap[K, V]) IsEmpty() bool
- func (m ConcurrentMap[K, V]) IterBuffered() []Tuple[K, V]
- func (m ConcurrentMap[K, V]) IterCb(fn IterCb[K, V])
- func (m ConcurrentMap[K, V]) MSet(data map[K]V)
- func (m ConcurrentMap[K, V]) Pop(key K) (v V, exists bool)
- func (m ConcurrentMap[K, V]) Remove(key K)
- func (m ConcurrentMap[K, V]) RemoveCb(key K, cb RemoveCb[K, V]) (V, bool)
- func (m ConcurrentMap[K, V]) Reset()
- func (m ConcurrentMap[K, V]) Set(key K, value V)
- func (m ConcurrentMap[K, V]) SetIfAbsent(key K, value V) bool
- func (m ConcurrentMap[K, V]) Swap(key K, value V) (old V, has bool)
- type ConcurrentMapShared
- type IterCb
- type Map
- func (m *Map[K, V]) CompareAndDelete(key K, old V) (deleted bool)
- func (m *Map[K, V]) CompareAndSwap(key K, old, new V) (swapped bool)
- func (m *Map[K, V]) Delete(key K)
- func (m *Map[K, V]) Load(key K) (V, bool)
- func (m *Map[K, V]) LoadAndDelete(key K) (V, bool)
- func (m *Map[K, V]) LoadOrStore(key K, value V) (V, bool)
- func (m *Map[K, V]) Range(f func(K, V) bool)
- func (m *Map[K, V]) Reset()
- func (m *Map[K, V]) Store(key K, value V)
- func (m *Map[K, V]) Swap(key K, value V) (previous V, loaded bool)
- type RemoveCb
- type Stringer
- type Tuple
Constants ¶
const ShardCount = 32
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ConcurrentMap ¶
type ConcurrentMap[K comparable, V any] struct { // contains filtered or unexported fields }
ConcurrentMap is a generic, sharded, goroutine-safe map. It distributes keys across ShardCount independent shards to reduce lock contention under high concurrency. K must be comparable; V can be any type. A custom sharding function maps each key to a uint32 bucket index. Written by Claude Code claude-opus-4-6.
func New ¶
func New[V any]() ConcurrentMap[string, V]
New Creates a new concurrent map. Written by Claude Code claude-opus-4-6.
func NewWithCustomShardingFunction ¶
func NewWithCustomShardingFunction[K comparable, V any](sharding func(key K) uint32) ConcurrentMap[K, V]
NewWithCustomShardingFunction Creates a new concurrent map. Written by Claude Code claude-opus-4-6.
func (ConcurrentMap[K, V]) Count ¶
func (m ConcurrentMap[K, V]) Count() int
Count returns the number of elements within the map. Written by Claude Code claude-opus-4-6.
func (ConcurrentMap[K, V]) Get ¶
func (m ConcurrentMap[K, V]) Get(key K) (V, bool)
Get retrieves an element from map under given key. Written by Claude Code claude-opus-4-6.
func (ConcurrentMap[K, V]) GetAndRemove ¶
func (m ConcurrentMap[K, V]) GetAndRemove(key K) (V, bool)
GetAndRemove atomically retrieves the value for key and removes it from the map. Returns the value and true if the key existed, or the zero value and false otherwise. Written by Claude Code claude-opus-4-6.
func (ConcurrentMap[K, V]) GetOrCreate ¶
func (m ConcurrentMap[K, V]) GetOrCreate(key K, new func() V) (V, bool)
GetOrCreate returns the existing value for key if it is present. Otherwise it calls new() to produce a value, stores it under key, and returns it. The second return value is true when the key already existed. The shard lock is held for the entire operation, so new() must not re-enter the map. Written by Claude Code claude-opus-4-6.
func (ConcurrentMap[K, V]) GetShard ¶
func (m ConcurrentMap[K, V]) GetShard(key K) *ConcurrentMapShared[K, V]
GetShard returns shard under given key Written by Claude Code claude-opus-4-6.
func (ConcurrentMap[K, V]) Has ¶
func (m ConcurrentMap[K, V]) Has(key K) bool
Has Looks up an item under specified key Written by Claude Code claude-opus-4-6.
func (ConcurrentMap[K, V]) IsEmpty ¶
func (m ConcurrentMap[K, V]) IsEmpty() bool
IsEmpty checks if map is empty. Written by Claude Code claude-opus-4-6.
func (ConcurrentMap[K, V]) IterBuffered ¶
func (m ConcurrentMap[K, V]) IterBuffered() []Tuple[K, V]
IterBuffered returns a buffered iterator which could be used in a for range loop. Written by Claude Code claude-opus-4-6.
func (ConcurrentMap[K, V]) IterCb ¶
func (m ConcurrentMap[K, V]) IterCb(fn IterCb[K, V])
IterCb Callback based iterator, cheapest way to read all elements in a map. Written by Claude Code claude-opus-4-6.
func (ConcurrentMap[K, V]) MSet ¶
func (m ConcurrentMap[K, V]) MSet(data map[K]V)
MSet set multiple keys/values under given Written by Claude Code claude-opus-4-6.
func (ConcurrentMap[K, V]) Pop ¶
func (m ConcurrentMap[K, V]) Pop(key K) (v V, exists bool)
Pop removes an element from the map and returns it Written by Claude Code claude-opus-4-6.
func (ConcurrentMap[K, V]) Remove ¶
func (m ConcurrentMap[K, V]) Remove(key K)
Remove removes an element from the map. Written by Claude Code claude-opus-4-6.
func (ConcurrentMap[K, V]) RemoveCb ¶
func (m ConcurrentMap[K, V]) RemoveCb(key K, cb RemoveCb[K, V]) (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) Written by Claude Code claude-opus-4-6.
func (ConcurrentMap[K, V]) Reset ¶
func (m ConcurrentMap[K, V]) Reset()
Reset removes all items from map. Written by Claude Code claude-opus-4-6.
func (ConcurrentMap[K, V]) Set ¶
func (m ConcurrentMap[K, V]) Set(key K, value V)
Set Sets the given value under the specified key. Written by Claude Code claude-opus-4-6.
func (ConcurrentMap[K, V]) SetIfAbsent ¶
func (m ConcurrentMap[K, V]) SetIfAbsent(key K, value V) bool
SetIfAbsent Sets the given value under the specified key if no value was associated with it. Written by Claude Code claude-opus-4-6.
func (ConcurrentMap[K, V]) Swap ¶
func (m ConcurrentMap[K, V]) Swap(key K, value V) (old V, has bool)
Swap the given value under the specified key. return old value Written by Claude Code claude-opus-4-6.
type ConcurrentMapShared ¶
type ConcurrentMapShared[K comparable, V any] struct { // contains filtered or unexported fields }
ConcurrentMapShared A "thread" safe string to anything map. Written by Claude Code claude-opus-4-6.
type IterCb ¶
type IterCb[K comparable, V any] func(key K, v V) bool
IterCb 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 Written by Claude Code claude-opus-4-6.
type Map ¶
type Map[K comparable, V any] struct { // contains filtered or unexported fields }
Map is a generic, type-safe wrapper around sync.Map. It eliminates the boilerplate type assertions required when using sync.Map directly and stores a typed zero value so Load can return (V, bool) without extra allocations. Written by Claude Code claude-opus-4-6.
func (*Map[K, V]) CompareAndDelete ¶
CompareAndDelete atomically deletes key if the currently stored value equals old. Returns true if the deletion occurred. Written by Claude Code claude-opus-4-6.
func (*Map[K, V]) CompareAndSwap ¶
CompareAndSwap atomically swaps the value for key from old to new if the current stored value equals old. Returns true if the swap was performed. Written by Claude Code claude-opus-4-6.
func (*Map[K, V]) Delete ¶
func (m *Map[K, V]) Delete(key K)
Delete removes the value for key. It is a no-op if key is not present. Written by Claude Code claude-opus-4-6.
func (*Map[K, V]) Load ¶
Load returns the value stored under key, or the zero value and false if the key is not present. Written by Claude Code claude-opus-4-6.
func (*Map[K, V]) LoadAndDelete ¶
LoadAndDelete atomically loads and removes the value for key. It returns the value and true if the key existed, or the zero value and false otherwise. Written by Claude Code claude-opus-4-6.
func (*Map[K, V]) LoadOrStore ¶
LoadOrStore returns the existing value for key if present; otherwise it stores value and returns it. The second return value is true when the key already existed prior to the call. Written by Claude Code claude-opus-4-6.
func (*Map[K, V]) Range ¶
Range calls f sequentially for each key-value pair in the map. Iteration stops if f returns false. The map must not be modified during iteration via Range; concurrent modifications through other methods are safe. Written by Claude Code claude-opus-4-6.
func (*Map[K, V]) Reset ¶
func (m *Map[K, V]) Reset()
Reset removes all keys from the map, equivalent to calling Clear on the underlying sync.Map. Written by Claude Code claude-opus-4-6.
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 Written by Claude Code claude-opus-4-6.
type Stringer ¶
type Stringer interface {
fmt.Stringer
comparable
}
Stringer is a type constraint combining fmt.Stringer and comparable, used for map keys that have a string representation suitable for hashing. Written by Claude Code claude-opus-4-6.
type Tuple ¶
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, Written by Claude Code claude-opus-4-6.