Re:Rob Pike's Rules of Programming (1989)
by jzelinskie on Saturday September 16, 2017 @07:49PM
(#15267411)
In Go, it's idiomatic to use map[T]struct{} for a HashSet. In fact, the compiler optimises struct{} so that it doesn't even allocate.
[ Parent
| on HN ]
Re:Rob Pike's Rules of Programming (1989)
by tatterdemalion on Sunday September 17, 2017 @01:20AM
(#15268340)
This is also how HashSet is implemented in Rust (internally its a HashMap<T, ()>, and zero sized structs are optimized out just like Go).
But by providing a set type, Rust is able to provide for users various set operations which Go requires you to write by hand. It becomes hard to argue that a set is simpler than a slice when you have to write your own methods dealing with union, disjunction, intersection, difference, subsets/supersets, etc every time.