maps

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 5, 2026 License: BSD-3-Clause Imports: 4 Imported by: 0

Documentation

Overview

Package maps provides a generic allocated map implementation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ByteMap

type ByteMap struct {
	// contains filtered or unexported fields
}

ByteMap is a Robin Hood hashmap operating on raw byte keys and values. Most users will want to use the generic Map wrapper type instead.

func NewByteMap

func NewByteMap(a mem.Allocator, size, ksize, vsize int) ByteMap

NewByteMap creates a new ByteMap with the given initial capacity, key size, and value size, using the provided allocator (or the default allocator if nil). The map automatically grows as needed.

If the allocator is nil, uses the system allocator. The caller is responsible for freeing map resources with ByteMap.Free when done using it.

func (*ByteMap) Clear

func (m *ByteMap) Clear()

Clear removes all key-value pairs from the map, resetting it to an empty state. Does not free map resources; the map can be reused after Clear.

func (*ByteMap) Free

func (m *ByteMap) Free()

Free frees internal resources used by the map. If the map is already freed, does nothing. The map must not be used after Free.

func (*ByteMap) Len

func (m *ByteMap) Len() int

Len returns the number of key-value pairs in the map.

func (*ByteMap) Resize

func (m *ByteMap) Resize(size int)

Resize grows or reallocates the map to hold at least size entries.

type Iter

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

Iter is an iterator over a Map's key-value pairs.

func (*Iter[K, V]) Key

func (it *Iter[K, V]) Key() K

Key returns the key of the current key-value pair.

func (*Iter[K, V]) Next

func (it *Iter[K, V]) Next() bool

Next advances the iterator to the next key-value pair, which will then be available through the Iter.Key and Iter.Value methods. It returns false if there are no more pairs to iterate over.

func (*Iter[K, V]) Value

func (it *Iter[K, V]) Value() V

Value returns the value of the current key-value pair.

type Map

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

Map is a generic hashmap similar to Go's built-in map[K]V. It automatically grows as needed, but does not shrink.

func New

func New[K comparable, V any](a mem.Allocator, size int) Map[K, V]

New creates a new Map with the given minimal capacity.

func (*Map[K, V]) Clear

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

Clear removes all key-value pairs from the map, resetting it to an empty state. Does not free map resources; the map can be reused after Clear.

func (*Map[K, V]) Delete

func (m *Map[K, V]) Delete(key K)

Delete removes the key and its value from the map. If the key is not in the map, does nothing.

func (*Map[K, V]) Free

func (m *Map[K, V]) Free()

Free frees internal resources used by the map. If the map is already freed, does nothing. The map must not be used after calling Free.

func (*Map[K, V]) Get

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

Get returns the value for the given key, or the zero value if the key is not in the map.

func (*Map[K, V]) Has

func (m *Map[K, V]) Has(key K) bool

Has returns true if the given key is in the map.

func (*Map[K, V]) Iter

func (m *Map[K, V]) Iter() Iter[K, V]

Iter returns an iterator over the map's key-value pairs. The map must not be modified or freed while iterating.

func (*Map[K, V]) Len

func (m *Map[K, V]) Len() int

Len returns the number of key-value pairs in the map.

func (*Map[K, V]) Set

func (m *Map[K, V]) Set(key K, value V)

Set sets the value for the given key, overwriting any existing value.

Jump to

Keyboard shortcuts

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