Documentation
¶
Index ¶
- Constants
- func MapShardKey(key uint64) uint64
- type Map
- func (smap *Map[V]) Get(key uint64) (value V, ok bool)
- func (smap *Map[V]) Len() int64
- func (smap *Map[V]) Mem() int64
- func (smap *Map[V]) RealLen() int64
- func (smap *Map[V]) RealMem() int64
- func (smap *Map[V]) Remove(key uint64) (freedBytes int64, hit bool)
- func (smap *Map[V]) Rnd() (value V, ok bool)
- func (smap *Map[V]) Set(key uint64, value V)
- func (smap *Map[V]) Shard(key uint64) *Shard[V]
- func (smap *Map[V]) WalkShards(ctx context.Context, fn func(key uint64, shard *Shard[V]))
- type Shard
- func (shard *Shard[V]) Clear()
- func (shard *Shard[V]) Get(key uint64) (val V, ok bool)
- func (shard *Shard[V]) GetRand() (val V, ok bool)
- func (shard *Shard[V]) ID() uint64
- func (shard *Shard[V]) Len() int64
- func (shard *Shard[V]) Remove(key uint64) (freedBytes int64, hit bool)
- func (shard *Shard[V]) Set(key uint64, new V)
- func (shard *Shard[V]) Walk(ctx context.Context, fn func(uint64, V) bool, lockRead bool)
- func (shard *Shard[V]) Weight() int64
- type Value
Constants ¶
const ActiveShards uint64 = 2047 // 2047 active shards
const NumOfShards uint64 = 2049 // 2048 total shards (one for collisions)
Variables ¶
This section is empty.
Functions ¶
func MapShardKey ¶
MapShardKey calculates the shard index for a given key.
Types ¶
type Map ¶
type Map[V Value] struct { // contains filtered or unexported fields }
Map is a sharded concurrent map for high-performance caches.
func NewMap ¶
NewMap creates a new sharded map with preallocated shards and a default per-shard map capacity.
func (*Map[V]) Get ¶
Get fetches a value and its releaser from the correct shard. found==false means the value is absent.
func (*Map[V]) Remove ¶
Remove deletes a value by key, returning how much memory was freed and a pointer to its LRU/list element.
func (*Map[V]) Set ¶
Set inserts or updates a value in the correct shard. Returns a releaser for ref counting.
type Shard ¶
type Shard[V Value] struct { *sync.RWMutex // Shard-level RWMutex for concurrency // contains filtered or unexported fields }
Shard is a single partition of the sharded map. Each shard is an independent concurrent map with its own lock and refCounted pool for releasers.
func (*Shard[V]) Get ¶
Get retrieves a value and returns a releaser for it, incrementing its refCount. Returns (value, releaser, true) if found; otherwise (zero, nil, false).
func (*Shard[V]) Remove ¶
Remove removes a value from the shard, decrements counters, and may trigger full resource cleanup. Returns (memory_freed, pointer_to_list_element, was_found).
func (*Shard[V]) Set ¶
Set inserts or updates a value by key, resets refCount, and updates counters. Returns a releaser for the inserted value.