From: Michael Anthony Knyszek Date: Thu, 15 Aug 2024 19:22:43 +0000 (+0000) Subject: internal/sync: add Range to HashTrieMap X-Git-Tag: go1.24rc1~313 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=5c7b7c7d60d7c20b102d70e713e605504353ab26;p=gostls13.git internal/sync: add Range to HashTrieMap This implementation is trivial given that All already exists. The purpose of Range is to conform to sync.Map's API. Change-Id: Icfe755b9986c46b88c7201644e562b1631a02b66 Reviewed-on: https://go-review.googlesource.com/c/go/+/606460 Reviewed-by: David Chase Auto-Submit: Michael Knyszek LUCI-TryBot-Result: Go LUCI --- diff --git a/src/internal/sync/hashtriemap.go b/src/internal/sync/hashtriemap.go index 73c8bba1e3..defcd0b793 100644 --- a/src/internal/sync/hashtriemap.go +++ b/src/internal/sync/hashtriemap.go @@ -485,6 +485,16 @@ func (ht *HashTrieMap[K, V]) All() func(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 (ht *HashTrieMap[K, V]) Range(yield func(K, V) bool) { + ht.init() + ht.iter(ht.root.Load(), yield) +} + func (ht *HashTrieMap[K, V]) iter(i *indirect[K, V], yield func(key K, value V) bool) bool { for j := range i.children { n := i.children[j].Load()