Documentation
¶
Index ¶
- type HasherFunc
- type Map
- func (m *Map[K, V]) Copy() *Map[K, V]
- func (m *Map[K, V]) Delete(key K) (prev V, deleted bool)
- func (m *Map[K, V]) Get(key K) (value V, ok bool)
- func (m *Map[K, V]) GetValue(key K) (value V)
- func (m *Map[K, V]) Keys() []K
- func (m *Map[K, V]) Len() int
- func (m *Map[K, V]) Scan(iter func(key K, value V) bool)
- func (m *Map[K, V]) Set(key K, value V) (V, bool)
- func (m *Map[K, V]) Values() []V
- type SyncMap
- func (m *SyncMap[K, V]) Delete(key K) (prev V, ok bool)
- func (m *SyncMap[K, V]) DeleteIf(key K, condition func(existing V) bool) (prev V, ok bool)
- func (m *SyncMap[K, V]) Get(key K) (val V, ok bool)
- func (m *SyncMap[K, V]) GetOrCreate(key K, supplier func(K) V) (value V, created bool)
- func (m *SyncMap[K, V]) GetOrLoad(key K) (val V, ok bool)
- func (m *SyncMap[K, V]) GetOrLoadCreate(key K, supplier func(K) V) (val V, created bool)
- func (m *SyncMap[K, V]) GetValue(key K) V
- func (m *SyncMap[K, V]) Load(key K) (val V, ok bool)
- func (m *SyncMap[K, V]) LoadOrCreate(key K, supplier func(K) V) (value V, created bool)
- func (m *SyncMap[K, V]) Put(key K, value V) (prev V, ok bool)
- func (m *SyncMap[K, V]) PutIf(key K, value V, condition func(prev V, prevExists bool) bool) (prev V, prevExists, ok bool)
- func (m *SyncMap[K, V]) PutIfAbsent(key K, value V) (prev V, ok bool)
- func (m *SyncMap[K, V]) Range(iter func(key K, value V) bool)
- func (m *SyncMap[K, V]) Scan(iter func(key K, value V) bool)
- func (m *SyncMap[K, V]) ScanUnsafe(iter func(key K, value V) bool)
- func (m *SyncMap[K, V]) Store(key K, value V) (prev V, ok bool)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type HasherFunc ¶
type Map ¶
type Map[K comparable, V any] struct { // contains filtered or unexported fields }
Map is a hashmap. Like map[string]interface{}
func New ¶
func New[K comparable, V any](cap int, hasher HasherFunc[K]) *Map[K, V]
New returns a new Map. Like map[string]interface{}
func (*Map[K, V]) Copy ¶
Copy the smapet. This is a copy-on-write operation and is very fast because it only performs a shadow copy.
func (*Map[K, V]) Delete ¶
Delete deletes a value for a key. Returns the deleted value, or false when no value was assigned.
func (*Map[K, V]) Get ¶
Get returns a value for a key. Returns false when no value has been assign for key.
func (*Map[K, V]) Scan ¶
Scan iterates over all key/values. It's not safe to call or Set or Delete while scanning.
type SyncMap ¶
type SyncMap[K comparable, V any] struct { // contains filtered or unexported fields }
SyncMap is a thread-safe version of Map. It achieves this by sharding into "x" number of shards each with a spinlock and an instance of Map. Shards are determined by key hash. The key is only ever hashed once per operation. Map code is embedded only to reduce the hash operation count.
func NewSyncMap ¶
func NewSyncMap[K comparable, V any](numShards, initialCapacity int, hasher HasherFunc[K]) *SyncMap[K, V]
func (*SyncMap[K, V]) Get ¶
Get is volatile and extremely fast. It's possible to have a small window where it misses. When it does miss calling Load