sync
packagestandard libraryThis package is not in the latest version of its module.
Details
Validgo.mod file
The Go module system was introduced in Go 1.11 and is the official dependency management solution for Go.
Redistributable license
Redistributable licenses place minimal restrictions on how software can be used, modified, and redistributed.
Tagged version
Modules with tagged versions give importers more predictable builds.
Stable version
When a project reaches major version v1 it is considered stable.
- Learn more about best practices
Repository
Links
Documentation¶
Overview¶
Package sync provides basic synchronization primitives such as mutualexclusion locks to internal packages (including ones that depend on sync).
Tests are defined in packagesync.
Index¶
- type HashTrieMap
- func (ht *HashTrieMap[K, V]) All() func(yield func(K, V) bool)
- func (ht *HashTrieMap[K, V]) Clear()
- func (ht *HashTrieMap[K, V]) CompareAndDelete(key K, old V) (deleted bool)
- func (ht *HashTrieMap[K, V]) CompareAndSwap(key K, old, new V) (swapped bool)
- func (ht *HashTrieMap[K, V]) Delete(key K)
- func (ht *HashTrieMap[K, V]) Load(key K) (value V, ok bool)
- func (ht *HashTrieMap[K, V]) LoadAndDelete(key K) (value V, loaded bool)
- func (ht *HashTrieMap[K, V]) LoadOrStore(key K, value V) (result V, loaded bool)
- func (ht *HashTrieMap[K, V]) Range(yield func(K, V) bool)
- func (ht *HashTrieMap[K, V]) Store(key K, old V)
- func (ht *HashTrieMap[K, V]) Swap(key K, new V) (previous V, loaded bool)
- type Mutex
Constants¶
This section is empty.
Variables¶
This section is empty.
Functions¶
This section is empty.
Types¶
typeHashTrieMap¶
type HashTrieMap[Kcomparable, Vany] struct {// contains filtered or unexported fields}
HashTrieMap is an implementation of a concurrent hash-trie. The implementationis designed around frequent loads, but offers decent performance for storesand deletes as well, especially if the map is larger. Its primary use-case isthe unique package, but can be used elsewhere as well.
The zero HashTrieMap is empty and ready to use.It must not be copied after first use.
func (*HashTrieMap[K, V])All¶
func (ht *HashTrieMap[K, V]) All() func(yield func(K, V)bool)
All returns an iterator over each key and value present in the map.
The iterator does not necessarily correspond to any consistent snapshot of theHashTrieMap's contents: no key will be visited more than once, but if the valuefor any key is stored or deleted concurrently (including by yield), the iteratormay reflect any mapping for that key from any point during iteration. The iteratordoes not block other methods on the receiver; even yield itself may call anymethod on the HashTrieMap.
func (*HashTrieMap[K, V])Clear¶
func (ht *HashTrieMap[K, V]) Clear()
Clear deletes all the entries, resulting in an empty HashTrieMap.
func (*HashTrieMap[K, V])CompareAndDelete¶
func (ht *HashTrieMap[K, V]) CompareAndDelete(key K, old V) (deletedbool)
CompareAndDelete deletes the entry for key if its value is equal to old.The value type must be comparable, otherwise this CompareAndDelete will panic.
If there is no current value for key in the map, CompareAndDelete returns false(even if the old value is the nil interface value).
func (*HashTrieMap[K, V])CompareAndSwap¶
func (ht *HashTrieMap[K, V]) CompareAndSwap(key K, old, new V) (swappedbool)
CompareAndSwap swaps the old and new values for keyif the value stored in the map is equal to old.The value type must be of a comparable type, otherwise CompareAndSwap will panic.
func (*HashTrieMap[K, V])Delete¶
func (ht *HashTrieMap[K, V]) Delete(key K)
Delete deletes the value for a key.
func (*HashTrieMap[K, V])Load¶
func (ht *HashTrieMap[K, V]) Load(key K) (value V, okbool)
Load returns the value stored in the map for a key, or nil if novalue is present.The ok result indicates whether value was found in the map.
func (*HashTrieMap[K, V])LoadAndDelete¶
func (ht *HashTrieMap[K, V]) LoadAndDelete(key K) (value V, loadedbool)
LoadAndDelete deletes the value for a key, returning the previous value if any.The loaded result reports whether the key was present.
func (*HashTrieMap[K, V])LoadOrStore¶
func (ht *HashTrieMap[K, V]) LoadOrStore(key K, value V) (result V, loadedbool)
LoadOrStore returns the existing value for the key if present.Otherwise, it stores and returns the given value.The loaded result is true if the value was loaded, false if stored.
func (*HashTrieMap[K, V])Range¶
func (ht *HashTrieMap[K, V]) Range(yield func(K, V)bool)
Range calls f sequentially for each key and value present in the map.If f returns false, range stops the iteration.
This exists for compatibility with sync.Map; All should be preferred.It provides the same guarantees as sync.Map, and All.
func (*HashTrieMap[K, V])Store¶
func (ht *HashTrieMap[K, V]) Store(key K, old V)
Store sets the value for a key.
func (*HashTrieMap[K, V])Swap¶
func (ht *HashTrieMap[K, V]) Swap(key K, new V) (previous V, loadedbool)
Swap swaps the value for a key and returns the previous value if any.The loaded result reports whether the key was present.
typeMutex¶
type Mutex struct {// contains filtered or unexported fields}A Mutex is a mutual exclusion lock.
See packagesync.Mutex documentation.
func (*Mutex)TryLock¶
TryLock tries to lock m and reports whether it succeeded.
See packagesync.Mutex documentation.