3 ms·
> Except you may not call them “maps” — key value data structures inexplicably have a different name in every single programming language: And then there's the
by majewsky 10y ago
> Except you may not call them “maps” — key value data structures inexplicably have a different name in every single programming language:
And then there's the cases where one language/framework has multiple associative arrays.
In C++, an std::map is an ordered map, where the key needs to implement a comparison method. An std::unordered_map, on the other hand, uses a hash function to organize items into buckets. (Same in Qt with QMap and QHash, by the way.)
When a language only provides one type of associative array, it tends to be the unordered variant, but there's usually a library for ordered associative arrays.
Usually, the unordered variant is preferred because it's much faster to compare computed hashes (usually an int32 or int64) instead of the keys themselves (e.g. potentially long strings), esp. if the map is clever and caches the hashes along with the keys. However, the implementation is more involved since it needs to implement a sufficiently nice hash function, that also adds a random salt to counter complexity attacks.