syncmap

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2024 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Iterator

type Iterator[K, V any] struct {
	// contains filtered or unexported fields
}

Iterator is a wrapper around an map iterator that provides thread-safe access to the underlying map.

func (Iterator[K, V]) Get

func (it Iterator[K, V]) Get() misc.Pair[K, V]

Get returns the current entry as a key-value pair.

func (Iterator[K, V]) Key

func (it Iterator[K, V]) Key() K

Key returns the current entry's key.

func (Iterator[K, V]) Move

func (it Iterator[K, V]) Move()

Move moves the iterator to the next entry.

func (Iterator[K, V]) Remove

func (it Iterator[K, V]) Remove()

Remove removes the current entry.

func (Iterator[K, V]) SetValue

func (it Iterator[K, V]) SetValue(value V)

SetValue sets the current entry's value.

func (Iterator[K, V]) Valid

func (it Iterator[K, V]) Valid() bool

Valid returns true if the iterator is currently pointing to a valid entry.

func (Iterator[K, V]) Value

func (it Iterator[K, V]) Value() V

Value returns the current entry's value.

func (Iterator[K, V]) ValueRef

func (it Iterator[K, V]) ValueRef() *V

ValueRef returns a reference to the current entry's value.

type Wrapper

type Wrapper[K, V any] struct {
	// contains filtered or unexported fields
}

Wrapper is a wrapper around a map that provides thread-safe access to the map. Locking is done through read-write mutex. This means that multiple goroutines can read from the map at the same time, but only one goroutine can write to the map at the same time.

func From

func From[K, V any](m maps.Map[K, V]) *Wrapper[K, V]

From creates a new Wrapper from the given map.

func (*Wrapper[K, V]) Clear

func (w *Wrapper[K, V]) Clear()

Clear removes all entries from the map.

func (*Wrapper[K, V]) Clone

func (w *Wrapper[K, V]) Clone() maps.Map[K, V]

Clone returns a copy of the wrapper and the underlying map.

func (*Wrapper[K, V]) Contains

func (w *Wrapper[K, V]) Contains(key K) bool

Contains returns true if the map contains the given key.

func (*Wrapper[K, V]) Get

func (w *Wrapper[K, V]) Get(key K) V

Get returns the value associated with the given key.

func (*Wrapper[K, V]) GetRef

func (w *Wrapper[K, V]) GetRef(key K) *V

GetRef returns a reference to the value associated with the given key. Usage of this method is discouraged, as it breaks the thread-safety of the map. Lock will not be held while the reference is used, so it is possible that the value of the element changes while the reference is used.

func (*Wrapper[K, V]) Iterator

func (w *Wrapper[K, V]) Iterator() iter.Iterator[misc.Pair[K, V]]

Iterator returns an iter.Iterator over the map.

func (*Wrapper[K, V]) MapIterator

func (w *Wrapper[K, V]) MapIterator() maps.Iterator[K, V]

MapIterator returns an iterator over the map.

func (*Wrapper[K, V]) RefsStream2 added in v1.7.0

func (w *Wrapper[K, V]) RefsStream2(yield func(K, *V) bool)

RefsStream2 streams over the keys and references to the values in the Map.

func (*Wrapper[K, V]) Remove

func (w *Wrapper[K, V]) Remove(key K)

Remove removes the entry with the given key.

func (*Wrapper[K, V]) Set

func (w *Wrapper[K, V]) Set(key K, value V)

Set sets the value associated with the given key.

func (*Wrapper[K, V]) Size

func (w *Wrapper[K, V]) Size() int

Size returns the number of entries in the map.

func (*Wrapper[K, V]) Stream2 added in v1.7.0

func (w *Wrapper[K, V]) Stream2(yield func(K, V) bool)

Stream2 streams over the entries in the Map.

func (*Wrapper[K, V]) Transaction

func (w *Wrapper[K, V]) Transaction(updateFunction func(m maps.Map[K, V]))

Transaction executes the given function with the map as an argument. The map is locked for writing while the function is executed.

func (*Wrapper[K, V]) TryGet

func (w *Wrapper[K, V]) TryGet(key K) (V, bool)

TryGet returns the value associated with the given key, and true if the key exists. If the key does not exist, the default value for the value type is returned, and false is returned.

func (*Wrapper[K, V]) Update

func (w *Wrapper[K, V]) Update(key K, updateFunction func(oldValue V) V)

Update updates the value associated with the given key.

func (*Wrapper[K, V]) UpdateRef

func (w *Wrapper[K, V]) UpdateRef(key K, updateFunction func(oldValue *V))

UpdateRef updates the value associated with the given key.

Jump to

Keyboard shortcuts

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