// the find
deckarep/golang-set
A simple, battle-tested and generic set type for the Go language. Trusted by GoogleCloudPlatform, Docker, 1Password, Ethereum and Hashicorp.
A generic set collection for Go, filling the gap left by the standard library. Offers both a thread-safe and non-thread-safe implementation behind a single interface, modeled on Python's set API. Used in production by Docker, Hashicorp, and others — this isn't someone's weekend experiment.
The dual-implementation design (threadsafe vs threadunsafe, same interface) is the right call — you pick at construction time and swap without touching call sites. Go 1.23+ iterator support means it integrates with range-over-func properly rather than forcing a ToSlice detour. The deadlock fix in 2.9.0 for panics inside Each callbacks shows the maintainer is paying attention to real edge cases, not just feature requests. BSON marshaling support rounds out JSON+BSON for anyone working with MongoDB.
The underlying implementation is just a map[T]struct{} with an optional mutex — there's no ordered set, no sorted set with O(log n) ops, no red-black tree. If you need iteration in insertion order or sorted order, you're writing it yourself. The thread-safe variant uses a single RWMutex over the whole map, so high-concurrency write-heavy workloads will see lock contention before you'd expect. No set algebra shortcuts either — Union allocates a new set every time, so chaining three Unions on large sets does three full copies.