]> Cypherpunks repositories - gostls13.git/commitdiff
internal/sync: add Store to HashTrieMap
authorMichael Anthony Knyszek <mknyszek@google.com>
Tue, 13 Aug 2024 15:12:21 +0000 (15:12 +0000)
committerGopher Robot <gobot@golang.org>
Mon, 18 Nov 2024 20:35:19 +0000 (20:35 +0000)
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 <drchase@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Michael Knyszek <mknyszek@google.com>

src/internal/sync/hashtriemap.go

index f2509d69202cc6a7c5e3b103369c9d22f52b674a..6e66bc81d385c30b1d4c365c956e1a91608e9ad5 100644 (file)
@@ -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) {