top | item 26222998

(no title)

mhaymo | 5 years ago

Good point. I guess the reason the author finds removing from lists to be relevant is because there is no Set structure in the Go standard library. They should use a `map[t]bool`, but that is non-obvious to many programmers.

discuss

order

dullcrisp|5 years ago

My Google search suggests that maps in Go aren’t ordered. If so this doesn’t work in place of an array.

vlowther|5 years ago

`map[t]struct{}` saves you a few bytes per entry. Just use the `_,found := foo[key]` form of lookup

simiones|5 years ago

Unfortunately, map[t]bool (or map[t]struct{}) only works for special structs that happen to have equality defined for them. It's not a general purpose solution, it's just a hack.

nitrix|5 years ago

map[t]struct{} so that the values don't require any space.