hatmap

package
v0.0.0-...-b07eac8 Latest Latest
Warning

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

Go to latest
Published: Jan 1, 2026 License: BSD-3-Clause Imports: 2 Imported by: 0

Documentation

Overview

Package hatmap provides generic goroutine-safe map. It is implemented as an ordinary map protected by mutex ("mutex hat" idiom).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Condition

type Condition[V any] func(currValue V) bool

Condition to operate on a current value by the given key. May be called multiple times.

type Map

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

Map is a goroutine-safe map.

Map must not be copied after first use.

func New

func New[K comparable, V any](size int) Map[K, V]

New creates a new map with size hint.

func (*Map[K, V]) All

func (m *Map[K, V]) All() iter.Seq2[K, V]

All iterates over a map. Don't modify the map while iterating over it.

func (*Map[K, V]) Clear

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

Clear clears the map.

func (*Map[K, V]) Delete

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

Delete deletes the value by the given key. If the key doesn't exist does nothing.

func (*Map[K, V]) DeleteIf

func (m *Map[K, V]) DeleteIf(key K, cond Condition[V]) bool

DeleteIf conditionally deletes the value by the given key. Returns true if the value was deleted.

func (*Map[K, V]) Get

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

Get gets value y the given key.

func (*Map[K, V]) Len

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

Len returns the number of elements in the map.

func (*Map[K, V]) Set

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

Set sets the value by the given key.

func (*Map[K, V]) SetIf

func (m *Map[K, V]) SetIf(key K, newValue V, cond Condition[V]) (actual V, ok bool)

SetIf conditionally sets the value by the given key. Returns final value and condition result.

Jump to

Keyboard shortcuts

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