syncmap

package
v0.7.6 Latest Latest
Warning

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

Go to latest
Published: May 16, 2024 License: Apache-2.0 Imports: 1 Imported by: 0

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 (*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 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]) 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