Documentation
¶
Index ¶
- Constants
- type Map
- func (m *Map[T]) Add(key uintptr, value T) bool
- func (m *Map[T]) CAS(key uintptr, from, to T) bool
- func (m *Map[T]) Delete(hashedKey uintptr)
- func (m *Map[T]) FillRate() float64
- func (m *Map[T]) Get(key uintptr) (value T, ok bool)
- func (m *Map[T]) GetOrAdd(key uintptr, value T) (actual T, loaded bool)
- func (m *Map[T]) Grow(newSize uintptr)
- func (m *Map[T]) Len() int
- func (m *Map[T]) Set(key uintptr, value T)
- func (m *Map[T]) String() string
- func (m *Map[T]) Visit(fn func(key uintptr, value T) error) error
Constants ¶
const DefaultSize = 8
DefaultSize is the default size for a zero allocated map
const MaxFillRate = float64(0.5)
MaxFillRate is the maximum fill rate for the slice before a resize will happen.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Map ¶ added in v1.0.0
type Map[T any] struct { // contains filtered or unexported fields }
Map implements a read optimized hash map.
func (*Map[T]) Add ¶ added in v1.0.0
Add sets the value under the specified key to the map if it does not exist yet. If a resizing operation is happening concurrently while calling Set, the item might show up in the map only after the resize operation is finished. Returns true if the item was inserted or false if it existed.
func (*Map[T]) CAS ¶ added in v1.0.0
CAS performs a compare and swap operation sets the value under the specified key to the map. An existing item for this key will be overwritten.
func (*Map[T]) GetOrAdd ¶ added in v1.0.0
GetOrAdd returns the existing value for the key if present. Otherwise, it stores and returns the given value. The loaded result is true if the value was loaded, false if stored.
func (*Map[T]) Grow ¶ added in v1.0.0
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.
func (*Map[T]) Set ¶ added in v1.0.0
Set sets the value under the specified key to the map. An existing item for this key will be overwritten. If a resizing operation is happening concurrently while calling Set, the item might show up in the map only after the resize operation is finished.