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

src/internal/sync/hashtriemap.go

index 73c8bba1e3617040ec26121123a8057645df2c05..defcd0b793947f1025694c584defe10f66898604 100644 (file)
@@ -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()