flat

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 Flat

type Flat[K comparable, V any] struct {
	// contains filtered or unexported fields
}

Flat is a open addressing hashmap implementation which uses linear probing to solve conflicts.

func New

func New[K comparable, V any]() *Flat[K, V]

New creates a new ready to use flat hashmap.

Note: This hashmap has a zero memory overhead per bucket and uses therefore the golang default variable initialization representation as tracking. This means in details a Get, Put or Remove call fails, if the key is:

  • 0 (int, uint, uint64, ...)
  • 0.0 (float32, float64)
  • "" (string)

func NewWithHasher

func NewWithHasher[K comparable, V any](empty K, hasher shared.HashFn[K]) *Flat[K, V]

NewWithHasher constructs a new hashmap with the given hasher. Furthermore the representation for a empty bucket can be set.

func (*Flat[K, V]) Clear

func (m *Flat[K, V]) Clear()

Clear removes all key-value pairs from the hashmap.

func (*Flat[K, V]) Copy

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

func (*Flat[K, V]) Each

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

Each calls 'fn' on every key-value pair in the hashmap in no particular order.

func (*Flat[K, V]) Get

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

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

func (*Flat[K, V]) Load

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

Load return the current load of the hashmap.

func (*Flat[K, V]) MaxLoad

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

MaxLoad forces resizing if the ratio is reached. Useful values are in range [0.5-0.7]. Returns ErrOutOfRange if `lf` is not in the open range (0.0,1.0).

func (*Flat[K, V]) Put

func (m *Flat[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.

func (*Flat[K, V]) Remove

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

Remove removes the specified key-value pair from the hashmap.

func (*Flat[K, V]) Reserve

func (m *Flat[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 (*Flat[K, V]) Size

func (m *Flat[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