3 ms·
Am I the only one who thinks writing my own Set data structure (based on a map under the hood) isn't crazy at all?
by Almaviva 13y ago
Am I the only one who thinks writing my own Set data structure (based on a map under the hood) isn't crazy at all?
- frou_dh 13y agoIf you're not the only one then you can all meet up in a month and each point out bugs in the other n-1 implementations.
- Almaviva 13y agoDoes a set do so much that you'd be worried about doing it wrong? Not to say having it in a common mature library wouldn't be an advantage, but it's something I'd be pretty sure I could implement and get right the first time. I'd be more worried about having two programmers write two implementations in the same project with subtly different interfaces, and having different parts of the code use each one. This is a cost and maintenance problem, but that's also a social and communication problem common to all projects.
- frou_dh 13y agoYeah, I was exaggerating a bit, but yes I think there could be room for bugs depending on what more involved operations are offered beyond basic membership tests. Anyway, have you seen the map[T]struct{} idiom for Go? Decent enough for the basic case.
- mediocregopher 13y agoNope, I posted this gist in a comment on the parent already: https://gist.github.com/mediocregopher/8319986 https://gist.github.com/mediocregopher/8319986