syncmap

package module
v0.0.0-...-932123a Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2025 License: AGPL-3.0 Imports: 1 Imported by: 2

Documentation

Overview

A typed, thread-safe map built on top of sync.Map, using generics.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type SyncMap

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

SyncMap provides a thread-safe generic map built on top of sync.Map.

func NewSyncMap

func NewSyncMap[K comparable, V any]() *SyncMap[K, V]

NewSyncMap creates a new thread-safe generic map

func (*SyncMap[K, V]) Delete

func (sm *SyncMap[K, V]) Delete(key K)

Delete removes a key

func (*SyncMap[K, V]) Keys

func (sm *SyncMap[K, V]) Keys() []K

Keys returns all keys as a slice

func (*SyncMap[K, V]) Len

func (sm *SyncMap[K, V]) Len() int

Len returns the number of items (expensive operation)

func (*SyncMap[K, V]) Load

func (sm *SyncMap[K, V]) Load(key K) (V, bool)

Load gets a value by key, returns value and whether it was found

func (*SyncMap[K, V]) LoadOrStore

func (sm *SyncMap[K, V]) LoadOrStore(key K, value V) (V, bool)

LoadOrStore gets existing value or stores new one, returns actual value and whether it was loaded

func (*SyncMap[K, V]) Range

func (sm *SyncMap[K, V]) Range(fn func(key K, value V) bool)

Range calls fn for each key-value pair. Returning false quits the iteration

func (*SyncMap[K, V]) Store

func (sm *SyncMap[K, V]) Store(key K, value V)

Store sets a key-value pair

func (*SyncMap[K, V]) Values

func (sm *SyncMap[K, V]) Values() []V

Values returns all values as a slice

Jump to

Keyboard shortcuts

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