Did you implement your own Set type and primitive functions?
Did you implement your own Set type and primitive functions?
Thankfully a lot of that stuff is in nodejs now, and there's a commitment to maintain parity with Web APIs which also helps, but there's still a lot of half-done work and path-dependencies on outside libs.
My usual example of something missing from the standard library is
func max(a, b int) int {
if a > b {
return a
} else {
return b
}
}
math.Max only operates on two float64s (due to the absence of function overloads; many standard library functions such as this predated generics), so if you want to avoid casting (and/or potential loss of precision if you're working with int64), you need to reinvent the wheel.Like the new slices package, meant to do common operations on slices, that is brand new on 1.21.
I wouldn't be surprised to see more and more new additions leveraging generics in next releases.
Neither of them use dummy values as you suggest. They have similar implementations (both are AVL trees) but sets really do contain only one value while maps contain two. I would be surprised if many other languages did as you suggest.
The set implementation points out some of the differences, at https://github.com/python/cpython/blob/main/Objects/setobjec... :
Unlike the dictionary implementation, the lookkey function can return
NULL if the rich comparison returns an error.
Use cases for sets differ considerably from dictionaries where looked-up
keys are more likely to be present. In contrast, sets are primarily
about membership testing where the presence of an element is not known in
advance. Accordingly, the set implementation needs to optimize for both
the found and not-found case.EDIT : and Rust: https://docs.rs/hashbrown/latest/hashbrown/hash_set/index.ht... (this is used by the default implementation of HashSet).