tsmap

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2023 License: MIT Imports: 3 Imported by: 0

README

tsmap

this util package is aim to solve the problem that original go map is not thread safe but the sync.Map can not be used with specific type.

TSMap is a thread safe map with specific key/value type.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Example

func Example()

func ExampleRange

func ExampleRange()

Types

type Exception

type Exception[K, V any] func(key K, value V) bool

func WithUntil

func WithUntil[K, V any](exception Exception[K, V]) Exception[K, V]

WithUntil when first occurrence of exception, stop range.

type Operation

type Operation[K, V any] func(key K, value V)

type Person

type Person struct {
	// contains filtered or unexported fields
}

type Some

type Some struct {
	// contains filtered or unexported fields
}

type TSMap

type TSMap[K any, V any] interface {
	// Get returns the value associated with the given key and whether it was
	Get(key K) (V, bool)
	// Set sets the value associated with the given key.
	Set(key K, value V)
	// Delete deletes the value associated with the given key.
	Delete(key K)
	// Len returns the number of items in the map.
	Len() int
	// Range calls fn sequentially for each key and value present in the map.
	//	but if exception exists and return true, fn will not be called.
	Range(fn Operation[K, V], exception ...Exception[K, V])
}

TSMap is a thread-safe map with specific key/value type.

func New

func New[K comparable, V any]() TSMap[K, V]

New returns a new TSMap[K, V] that uses sync.Map for synchronization.

func NewMutex

func NewMutex[K comparable, V any]() TSMap[K, V]

NewMutex returns a new TSMap[K, V] that uses map[K]V and a mutex for synchronization.

func NewSync

func NewSync[K comparable, V any]() TSMap[K, V]

NewSync returns a new TSMap[K, V] that uses sync.Map for synchronization.

Jump to

Keyboard shortcuts

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