Documentation ¶
Index ¶
- type HashMap
- func (m *HashMap[K, V]) Del(key K)
- func (m *HashMap[K, V]) Fillrate() uintptr
- func (m *HashMap[K, V]) ForEach(lambda func(K, V))
- func (m *HashMap[K, V]) Get(key K) (value V, ok bool)
- func (m *HashMap[K, V]) Grow(newSize uintptr)
- func (m *HashMap[K, V]) Len() uintptr
- func (m *HashMap[K, V]) Set(key K, value V)
- func (m *HashMap[K, V]) SetHasher(hs func(K) uintptr)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type HashMap ¶
type HashMap[K hashable, V any] struct { Datamap atomic.Pointer[hashMapData[K, V]] // atomic.Pointer for safe access even during resizing // contains filtered or unexported fields }
HashMap implements the concurrent hashmap
func (*HashMap[K, V]) Del ¶
func (m *HashMap[K, V]) Del(key K)
Del deletes the key from the map does nothing if key is absemt
func (*HashMap[K, V]) Fillrate ¶
func (m *HashMap[K, V]) Fillrate() uintptr
Fillrate returns the fill rate of the map as an percentage integer
func (*HashMap[K, V]) ForEach ¶
func (m *HashMap[K, V]) ForEach(lambda func(K, V))
ForEach iterates over key-value pairs and executes the lambda provided for each such pair
func (*HashMap[K, V]) Get ¶
func (m *HashMap[K, V]) Get(key K) (value V, ok bool)
Get retrieves an element from the map returns `false“ if element is absent
func (*HashMap[K, V]) Grow ¶
func (m *HashMap[K, V]) Grow(newSize uintptr)
Grow resizes the hashmap to a new size, gets rounded up to next power of 2 To double the size of the hashmap use newSize 0 This function returns immediately, the resize operation is done in a goroutine No resizing is done in case of another resize operation already being in progress Growth and map bucket policy is inspired from https://github.com/cornelk/hashmap
func (*HashMap[K, V]) Len ¶
func (m *HashMap[K, V]) Len() uintptr
Len returns the number of key-value pairs within the map
func (*HashMap[K, V]) Set ¶
func (m *HashMap[K, V]) Set(key K, value V)
Set tries to update an element if key is present else it inserts a new element If a resizing operation is happening concurrently while calling Set() then the item might show up in the map only after the resize operation is finished