unordered

package
v0.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 18, 2025 License: MIT Imports: 2 Imported by: 0

Documentation

Index

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]) Copy

func (m *Unordered[K, V]) Copy() *Unordered[K, V]

Copy returns a copy of this hashmap.

func (*Unordered[K, V]) Each

func (m *Unordered[K, V]) Each(fn func(key K, val V) bool)

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]) Get

func (m *Unordered[K, V]) Get(key K) (V, bool)

Get returns the value stored for this key, or false if not found.

func (*Unordered[K, V]) Insert

func (m *Unordered[K, V]) Insert(key K) (*V, bool)

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]) Load

func (m *Unordered[K, V]) Load() float32

Load return the current load of the hashmap.

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

func (m *Unordered[K, V]) MaxLoad(lf float32) error

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

func (m *Unordered[K, V]) Put(key K, val V) bool

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

func (m *Unordered[K, V]) Remove(key K) bool

Remove removes the specified key-value pair from the hashmap. Returns true, if the element was in the hashmap.

func (*Unordered[K, V]) Reserve

func (m *Unordered[K, V]) Reserve(n uintptr)

Reserve sets the number of buckets to the most appropriate to contain at least n elements. If n is lower than that, the function may have no effect.

func (*Unordered[K, V]) Size

func (m *Unordered[K, V]) Size() int

Size returns the number of items in the hashmap.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL