Documentation
¶
Index ¶
- type Unordered
- func (m *Unordered[K, V]) Clear()
- func (m *Unordered[K, V]) Copy() *Unordered[K, V]
- func (m *Unordered[K, V]) Each(fn func(key K, val V) bool)
- func (m *Unordered[K, V]) Get(key K) (V, bool)
- func (m *Unordered[K, V]) Insert(key K) (*V, bool)
- func (m *Unordered[K, V]) Load() float32
- func (m *Unordered[K, V]) Lookup(key K) *V
- func (m *Unordered[K, V]) MaxLoad(lf float32) error
- func (m *Unordered[K, V]) Put(key K, val V) bool
- func (m *Unordered[K, V]) Remove(key K) bool
- func (m *Unordered[K, V]) Reserve(n uintptr)
- func (m *Unordered[K, V]) Size() int
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Unordered ¶
type Unordered[K comparable, V any] struct { // contains filtered or unexported fields }
Unordered is a hashmap implementation, where the elements are organized into buckets depending on their hash values. Collisions are chained in a single linked list. An inserted value keeps its memory address, means an element in a bucket will not copied or swapped. That supports holding points instead of copy by value. see: `Insert` and `lookup`.
func New ¶
func New[K comparable, V any]() *Unordered[K, V]
New creates a ready to use `unordered` hashmap with default settings.
func NewWithHasher ¶
func NewWithHasher[K comparable, V any](hasher shared.HashFn[K]) *Unordered[K, V]
NewWithHasher same as `NewUnordered` but with a given hash function.
func (*Unordered[K, V]) Clear ¶
func (m *Unordered[K, V]) Clear()
Clear removes all key-value pairs from the hashmap.
func (*Unordered[K, V]) Each ¶
Each calls 'fn' on every key-value pair in the hash map in no particular order. If 'fn' returns true, the iteration stops.
func (*Unordered[K, V]) Insert ¶
Insert returns a pointer to a zero allocated value. These pointer is valid until the key is part of the hashmap. Note, use `Put` for small values.
func (*Unordered[K, V]) Lookup ¶
func (m *Unordered[K, V]) Lookup(key K) *V
Lookup returns a pointer to the stored value for this key or nil if not found. The pointer is valid until the key is part of the hashmap. Note, use `Get` for small values.
func (*Unordered[K, V]) MaxLoad ¶
MaxLoad forces resizing if the ratio is reached. Useful values are in range [0.7-1.0]. Returns ErrOutOfRange if `lf` is less than or equal zero.
func (*Unordered[K, V]) Put ¶
Put adds the given key-value pair to the hashmap. If the key already exists its value will be overwritten with the new value. Returns true, if the element is a new item in the hashmap.
func (*Unordered[K, V]) Remove ¶
Remove removes the specified key-value pair from the hashmap. Returns true, if the element was in the hashmap.