From 872031dc10f30380663eda1c83d830c19eb13dff Mon Sep 17 00:00:00 2001 From: Michael Anthony Knyszek Date: Tue, 13 Aug 2024 15:12:21 +0000 Subject: [PATCH] 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 --- src/internal/sync/hashtriemap.go | 5 +++++ 1 file changed, 5 insertions(+) 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) { -- 2.48.1