4 ms·
I’m sorry for the “gatekeeping”, but do you really want to work together with someone that doesn’t know the language’s standard library or won’t even look at th
by kaba0 6y ago
I’m sorry for the “gatekeeping”, but do you really want to work together with someone that doesn’t know the language’s standard library or won’t even look at the documentation? And instead it would be positive that he/she writes the very implementation of something?
- jholloway7 6y agoThis problem transcends documentation of any given language's standard library. list.delete(value) in any programming language is a degenerate without an ordering or hash built-in to the underlying data structure. If you ever need to delete based on value, it's a smell that a list is the wrong data structure. I'm sure there are cases in constrained environments where a linear search is heuristically okay, but generally in application development list.delete(value) is a hint that you're using the wrong data structure.
- mhaymo 6y agoGood 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.
- dullcrisp 6y agoMy Google search suggests that maps in Go aren’t ordered. If so this doesn’t work in place of an array.
- vlowther 6y ago`map[t]struct{}` saves you a few bytes per entry. Just use the `_,found := foo[key]` form of lookup
- nitrix 6y agomap[t]struct{} so that the values don't require any space.
- simiones 6y agoUnfortunately, 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.