Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

At least now we can write a generic set that supports all the things you want a set to do, instead of using map[T]interface{} and a lot of for loops.


>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.


Ah 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.


Because 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 :)


More reasons to have a generic Set type in the standard library. That way you know the implementation is correct every time.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: