tsmap

package
v0.0.12 Latest Latest
Warning

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

Go to latest
Published: May 14, 2024 License: LGPL-2.1 Imports: 2 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 tsmap provides a collection of generic thread-safe map utility functions that can be safely used between multiple goroutines.

The provided functions are intended to simplify the process of working with maps in a thread-safe manner.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Delete

func Delete[M ~map[K]V, K comparable, V any](mux threadsafe.Locker, m M, k K)

Delete is a thread-safe function to delete the key-value pair with the specified key from the given map.

func Filter

func Filter[M ~map[K]V, K comparable, V any](mux threadsafe.RLocker, m M, f func(K, V) bool) M

Filter is a thread-safe function that returns a new map containing only the elements in the input map m for which the specified function f is true.

func Get

func Get[M ~map[K]V, K comparable, V any](mux threadsafe.RLocker, m M, k K) V

Get is a thread-safe function to get a value by key k in a map m. See also GetOK.

func GetOK

func GetOK[M ~map[K]V, K comparable, V any](mux threadsafe.RLocker, m M, k K) (V, bool)

GetOK is a thread-safe function to get a value by key k in a map m. The second return value is a boolean that indicates whether the key was present in the map.

func Invert

func Invert[M ~map[K]V, K, V comparable](mux threadsafe.RLocker, m M) map[V]K

Invert is a thread-safe function that returns a new map were keys and values are swapped.

func Len

func Len[M ~map[K]V, K comparable, V any](mux threadsafe.RLocker, m M) int

Len is a thread-safe function to get the length of a map m.

func Map

func Map[M ~map[K]V, K, J comparable, V, U any](mux threadsafe.RLocker, m M, f func(K, V) (J, U)) map[J]U

Map is a thread-safe function that returns a new map that contains each of the elements of the input map m mutated by the specified function. This function can be used to invert a map.

func Reduce

func Reduce[M ~map[K]V, K comparable, V, U any](mux threadsafe.RLocker, m M, init U, f func(K, V, U) U) U

Reduce is a thread-safe function that applies the reducing function f to each element of the input map m, and returns the value of the last call to f. The first parameter of the reducing function f is initialized with init.

func Set

func Set[M ~map[K]V, K comparable, V any](mux threadsafe.Locker, m M, k K, v V)

Set is a thread-safe function to assign a value v to a key k in a map m.

Types

This section is empty.

Jump to

Keyboard shortcuts

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