syncmap

package
v0.10.0-rc.1 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2025 License: Apache-2.0 Imports: 1 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package syncmap provides a map that is safe for concurrent use. It is similar to sync.Map, but is simpler, and gives a consistent state for range loops.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Map

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

Map is a map that is safe for concurrent use. It is similar to sync.Map, but is simpler, and gives a consistent state for range loops. It takes two generic types, K (key) and V (value). K must be comparable, and V can be any type.

func New

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

New creates a new map.

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) bool

Delete deletes a value from the map.

func (*Map[K, V]) Exclusive

func (m *Map[K, V]) Exclusive(f func(map[K]V))

Exclusive calls a callback with exclusive access to the map. Modifications to the map will be kept.

func (*Map[K, V]) ExclusiveRead

func (m *Map[K, V]) ExclusiveRead(f func(map[K]V))

ExclusiveRead calls a callback with exclusive access to the map. It is not safe to modify the map.

func (*Map[K, V]) Extract

func (m *Map[K, V]) Extract(key K) (value V, ok bool)

Extract removes and returns the key's value, and whether it was found.

func (*Map[K, V]) Get

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

Get gets a value from the map. It returns the value, and whether it was found.

func (*Map[K, V]) Set

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

Set sets a value in the map.

Jump to

Keyboard shortcuts

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