syncmap

package
v0.0.0-...-6c366bb Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2024 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type SyncMap

type SyncMap[T any] struct {
	SyncMapComparableKey[string, T]
}

func NewSyncMap

func NewSyncMap[T any]() *SyncMap[T]

type SyncMapComparableKey

type SyncMapComparableKey[T1 comparable, T2 any] struct {
	// contains filtered or unexported fields
}

SyncMapComparableKey is a map with lockable keys. It allows to lock the key regardless of whether the entry for given key exists. When key is locked other threads can't read/write the key.

func NewSyncMapComparableKey

func NewSyncMapComparableKey[T1 comparable, T2 any]() *SyncMapComparableKey[T1, T2]

func (*SyncMapComparableKey[T1, T2]) Delete

func (c *SyncMapComparableKey[T1, T2]) Delete(lockedKey T1)

Delete deletes object from the entries map

func (*SyncMapComparableKey[T1, T2]) DoWithLock

func (c *SyncMapComparableKey[T1, T2]) DoWithLock(key T1, f func(key T1) error) error

DoWithLock takes care of locking and unlocking key.

func (*SyncMapComparableKey[T1, T2]) GetKeys

func (c *SyncMapComparableKey[T1, T2]) GetKeys() []T1

GetKeys returns a snapshot of all keys from entries map. After this function returns there are no guarantees that the keys in the real entries map are still the same

func (*SyncMapComparableKey[T1, T2]) Load

func (c *SyncMapComparableKey[T1, T2]) Load(lockedKey T1) (value T2, loaded bool)

Load returns the value stored in the map for a key, or nil if no value is present. The loaded result indicates whether value was found in the map.

func (*SyncMapComparableKey[T1, T2]) LoadOrStore

func (c *SyncMapComparableKey[T1, T2]) LoadOrStore(lockedKey T1, newEntry T2) (value T2, loaded bool)

LoadOrStore gets the key value if it's present or creates a new one if it isn't, loaded return value signals if the object was present.

func (*SyncMapComparableKey[T1, T2]) LockKey

func (c *SyncMapComparableKey[T1, T2]) LockKey(key T1)

LockKey should be called before reading/writing entry value, it guarantees exclusive access to the key. Unlock(key) should be called once the work for this key is done to unlock other threads After the key is unlocked there are no guarantees for the entry for given key

func (*SyncMapComparableKey[T1, T2]) Store

func (c *SyncMapComparableKey[T1, T2]) Store(lockedKey T1, newEntry T2)

Store sets the value for a key. If key-value was already present, it will be over-written

func (*SyncMapComparableKey[T1, T2]) UnlockKey

func (c *SyncMapComparableKey[T1, T2]) UnlockKey(lockedKey T1)

UnlockKey unlocks previously locked key. Call it when all the operations with the given key are done.

Jump to

Keyboard shortcuts

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