tech

From map[T]struct{} to Red-Black Trees: A Deep Dive into go-set (and a bug I fixed)

Spotted a TODO optimize in hashicorp/go-set's TreeSet.EqualSliceSet. It was building and throwing away a full Red-Black tree just to check equality. Replaced it with a sort-and-scan using the same comparator the tree already uses. 15 lines, no heap allocations, all edge cases handled. Small change, but you only see why it matters once you understand what's underneath.

May 7, 2026·9 min read
Latest