Stop choking your application with std::map
For my job I primarily work in JavaScript and at night I largely work in Lua and C++. Until recently I assumed std::map
was similar read time complexity to a JavaScript object. That is until a person on my team was telling me that I should use something else for time complexity purposes on a PR I wrote.
He even linked me documentation to std::map
. Clear as day I read “logarithmic complexity”. Well, it turns out the C++ Standard Library has std::unordered_map
as well as the std::map
. Why was it decided that std::map
should be an ordered map and to have std::unordered_map
instead of std::ordered_map
as the alternative? We may never know. But now you know std::unordered_map
exists and std::map
may not have been what you thought it was!
I’m not saying to never use std::map
but since it uses a Red-Black tree to index values vs a constant lookup I will be using std::unordered_map
by default on my C++ projects.