Re:50 Algorithms Every Programmer Should Know (Second Edition)
by djur on Wednesday January 03, 2024 @06:25AM
(#38852892)
Python, Ruby, Perl. Languages where hashmaps are a builtin.
[ Parent
| on HN ]
Re:50 Algorithms Every Programmer Should Know (Second Edition)
by brabel on Wednesday January 03, 2024 @07:06AM
(#38853139)
Java as well: https://github.com/pengisgood/jdk-source-code/blob/master/sr...
EDIT : and Rust: https://docs.rs/hashbrown/latest/hashbrown/hash_set/index.ht... (this is used by the default implementation of HashSet).
Re:50 Algorithms Every Programmer Should Know (Second Edition)
by eesmith on Wednesday January 03, 2024 @07:03AM
(#38853119)
Python has its own set type not based on hashmap/dict, and that's been the case for years.
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.