3 ms·
>map[T]interface{} If the semantics desired are merely those of a simple set, why instantiate storage for the value side of the map? An interface{} consumes 1
by everybodyknows 5y ago
>map[T]interface{}
If the semantics desired are merely those of a simple set, why instantiate storage for the value side of the map? An interface{} consumes 16 bytes. Instantiating a struct{}, i.e. with no fields inside, consumes 0 bytes.
- Shish2k 5y agoBecause when a language doesn’t supply common features out of the box, users implement them for themselves, and inevitably a lot of them do a bad job of it :)
- EdwardDiego 5y agoAh yeah, that's right, it was map[T]struct{} - it's been a bit since I had to do it. I knew it was something with curly brackets instead of the map[T]bool I started using.
- vips7L 5y agoMore reasons to have a generic Set type in the standard library. That way you know the implementation is correct every time.