Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Shard ¶
type Shard[K comparable, V any] struct { sync.RWMutex // compose from sync.RWMutex // contains filtered or unexported fields }
Shard represents a single partition of a ShardedMap. Each shard is an independent, lock-protected map that stores a subset of keys.
type ShardedMap ¶
type ShardedMap[K comparable, V any] []*Shard[K, V]
ShardedMap is a map abstraction composed of multiple shards. It provides concurrent access to key-value pairs with reduced lock contention.
func NewShardedMap ¶
func NewShardedMap[K comparable, V any](nshards int) ShardedMap[K, V]
NewShardedMap creates and returns a ShardedMap with the specified number of shards. Each shard is initialized and protected with its own read-write mutex.
func (ShardedMap[K, V]) Get ¶
func (m ShardedMap[K, V]) Get(key K) V
Get retrieves the value associated with the given key. A read lock is acquired on the appropriate shard.
func (ShardedMap[K, V]) Keys ¶
func (m ShardedMap[K, V]) Keys() []K
Keys returns all keys from all shards as a single slice. Each shard is read concurrently, and keys are aggregated safely.
func (ShardedMap[K, V]) Set ¶
func (m ShardedMap[K, V]) Set(key K, value V)
Set inserts or updates the value associated with the given key. A write lock is acquired on the appropriate shard.