hashicorp / go-set

The go-set package provides generic Set implementations for Go, including HashSet for types with a Hash() function and TreeSet for orderable data
Mozilla Public License 2.0
118 stars 8 forks source link

treeset: avoid using goroutine / channel / context for iteration #60

Closed shoenig closed 1 year ago

shoenig commented 1 year ago

This PR swaps implementations of TreeSet.iterate to not require a background goroutine, channel, and context. Instead we use an explicit stack and a generator function to "pull" values one at time. Unlike with the goroutine, the stack object is garbage collected automatically if we do not traverse the entire tree.

Inspiriation is from https://github.com/golang/go/discussions/56413

shoenig commented 1 year ago

@zonewave for some reason I can't add you as a reviewer ... but if you don't mind taking a look that would be helpful :slightly_smiling_face: