Map Data Structures
Discussions compare map implementations like HashMap, TreeMap, and JavaScript's Map across languages such as Java, C++, and JS, focusing on key types, ordering, performance, and use cases versus plain objects.
Activity Over Time
Top Contributors
Keywords
Sample Comments
Yeah, Map (or WeakMap if keys are objects and you don't need iteration) is much better at this kind of thing.
i guess maps and array ? ( if you wanted to reimplement your own in a typesafe way, that is)
Some people just prefer hashmaps.
Maps with non string keys are handled differently even in languages that do support them. Are two instances of an object used as a key the same for example. This may vary depending on the type of the object.
Kind of strange they don't just have a type for that. In Java we have unsorted ones (hashmap), linked ones that retain the sort order (linkedhashmap), and even automatically sorting trees (treemap / sortedmap). Honestly, considering users were relying on the key order being different from the hash order, the default type should have just been made the sorted or linked one and the type added just made unsortedmap or something. Seems like a failing of the language libraries that you have
Sounds like you need to think a little more about the use case of these maps.
JavaScript also has Map. Which is more general since the keys don't have to be strings.
std::unordered_map is in the similar ballpark. linked lists, oom checks, integer key support.
You're right it couldn't be true on all the cases In my use case map and array are generally enough.
If you want ordering, then a hash-map doesn't help you.