smap

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2025 License: BSD-3-Clause Imports: 1 Imported by: 2

README

Safe map

Package smap is a thread-safe map with generic any key and any value.

GoDoc Go Report Card

Basic usage example

Licence

BSD

Documentation

Overview

Package smap is a thread-safe map with generic any key and any value.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Smap

type Smap[K comparable, V any] struct{ sync.Map }

Smap is a thread safe map with generic comparable key and any value.

func New

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

New returns a pointer to a new Smap.

func (*Smap[K, V]) Get

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

Get returns the value stored in the map for a key, or default V type value if no value is present by key. The ok result indicates whether value was found in the map.

func (*Smap[K, V]) Len

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

Len returns the number of elements in the map.

func (*Smap[K, V]) Range added in v0.0.2

func (m *Smap[K, V]) Range(f func(key K, value V) bool)

Range calls f sequentially for each key and value present in the map.

func (*Smap[K, V]) Set

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

Set sets the value for a key.

Jump to

Keyboard shortcuts

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