maphelpers

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: May 24, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ConcurrentMap

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

ConcurrentMap is a thread safe map backed by a Go map.

func NewConcurrentMap

func NewConcurrentMap[K comparable, T any]() *ConcurrentMap[K, T]

NewConcurrentMap creates a new ConcurrentMap.

func (*ConcurrentMap[K, T]) All

func (m *ConcurrentMap[K, T]) All() iter.Seq2[K, T]

All returns an iterator over all key/value pairs in the map. A read lock is held during the iteration.

func (*ConcurrentMap[K, T]) Delete

func (m *ConcurrentMap[K, T]) Delete(key K) bool

Delete deletes the given key from the map. It returns true if the key was found and deleted, false otherwise.

func (*ConcurrentMap[K, T]) Get

func (m *ConcurrentMap[K, T]) Get(key K) T

Get gets the value for the given key. It returns the zero value of T if the key is not found.

func (*ConcurrentMap[K, T]) GetOrCreate

func (m *ConcurrentMap[K, T]) GetOrCreate(key K, create func() (T, error)) (T, error)

GetOrCreate gets the value for the given key if it exists, or creates it if not.

func (*ConcurrentMap[K, T]) Len added in v0.11.0

func (m *ConcurrentMap[K, T]) Len() int

Len returns the number of key/value pairs in the map.

func (*ConcurrentMap[K, T]) Lookup

func (m *ConcurrentMap[K, T]) Lookup(key K) (T, bool)

Lookup looks up the given key in the map. It returns the value and a boolean indicating whether the key was found.

func (*ConcurrentMap[K, T]) Set

func (m *ConcurrentMap[K, T]) Set(key K, value T)

Set sets the given key to the given value.

func (*ConcurrentMap[K, T]) SetIfAbsent added in v0.10.0

func (m *ConcurrentMap[K, T]) SetIfAbsent(key K, value T) bool

SetIfAbsent sets the given key to the given value if the key is not already present in the map. It returns true if the key was set, false if the key was already present.

func (*ConcurrentMap[K, T]) WithReadLock added in v0.9.0

func (m *ConcurrentMap[K, T]) WithReadLock(f func(m map[K]T) error) error

WithReadLock executes the given function with a read lock on the map. Note that the map m should only be accessed within the function f.

func (*ConcurrentMap[K, T]) WithWriteLock

func (m *ConcurrentMap[K, T]) WithWriteLock(f func(m map[K]T) error) error

WithWriteLock executes the given function with a write lock on the map. Note that the map m should only be accessed within the function f.

type ConcurrentSet added in v0.12.0

type ConcurrentSet[K comparable] struct {
	// contains filtered or unexported fields
}

ConcurrentSet is a thread safe set backed by a Go map protected by a RWMutex.

func NewConcurrentSet added in v0.12.0

func NewConcurrentSet[K comparable]() *ConcurrentSet[K]

NewConcurrentSet creates a new ConcurrentSet.

func (*ConcurrentSet[K]) Add added in v0.12.0

func (s *ConcurrentSet[K]) Add(key K)

Add adds the given key to the set.

func (*ConcurrentSet[K]) AddIfAbsent added in v0.12.0

func (s *ConcurrentSet[K]) AddIfAbsent(key K) bool

AddIfAbsent adds the given key to the set if it is not already present. It returns true if the key was added, false if the key was already present.

func (*ConcurrentSet[K]) All added in v0.12.0

func (s *ConcurrentSet[K]) All() iter.Seq[K]

All returns an iterator over all keys in the set. A read lock is held during the iteration.

func (*ConcurrentSet[K]) Delete added in v0.12.0

func (s *ConcurrentSet[K]) Delete(key K) bool

Delete deletes the given key from the set. It returns true if the key was found and deleted, false otherwise.

func (*ConcurrentSet[K]) Has added in v0.12.0

func (s *ConcurrentSet[K]) Has(key K) bool

Has checks if the given key is in the set.

func (*ConcurrentSet[K]) Len added in v0.12.0

func (s *ConcurrentSet[K]) Len() int

Len returns the number of keys in the set.

Jump to

Keyboard shortcuts

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