From: Michael Anthony Knyszek Date: Tue, 13 Aug 2024 15:12:21 +0000 (+0000) Subject: internal/sync: add Store to HashTrieMap X-Git-Tag: go1.24rc1~318 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=872031dc10f30380663eda1c83d830c19eb13dff;p=gostls13.git internal/sync: add Store to HashTrieMap This change adds the Store operation (with the same semantics as sync.Map's Store) to HashTrieMap. Change-Id: Ida55421f28d8cc6527f983f7f1c2fd55bb280925 Reviewed-on: https://go-review.googlesource.com/c/go/+/606455 Reviewed-by: David Chase LUCI-TryBot-Result: Go LUCI Auto-Submit: Michael Knyszek --- diff --git a/src/internal/sync/hashtriemap.go b/src/internal/sync/hashtriemap.go index f2509d6920..6e66bc81d3 100644 --- a/src/internal/sync/hashtriemap.go +++ b/src/internal/sync/hashtriemap.go @@ -195,6 +195,11 @@ func (ht *HashTrieMap[K, V]) expand(oldEntry, newEntry *entry[K, V], newHash uin return &top.node } +// Store sets the value for a key. +func (ht *HashTrieMap[K, V]) Store(key K, old V) { + _, _ = ht.Swap(key, old) +} + // Swap swaps the value for a key and returns the previous value if any. // The loaded result reports whether the key was present. func (ht *HashTrieMap[K, V]) Swap(key K, new V) (previous V, loaded bool) {