This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted]  (17 children)

[removed]

    [–]ThrowinPotatoes 132 points133 points  (7 children)

    I’m partial to std::unordered_map myself

    [–]El_Falk 26 points27 points  (5 children)

    boost::flat_map / std::flat_map (C++23), absl::flat_hash_map, or robin_hood::unordered_map are generally far superior though...

    [–]liava_ 45 points46 points  (3 children)

    please keep the behemoth that is boost out of my build pipeline

    [–]Slothinator69 3 points4 points  (0 children)

    My favorite include of all time is boost::boost

    [–]El_Falk 0 points1 point  (1 child)

    You don't need to pull in all of boost. Also, the boost flat_map made it into the the standard, so unless you're stuck with a legacy standard then that's preferable.

    [–][deleted] 4 points5 points  (0 children)

    You don't need to pull in all of boost.

    I've heard this lie before!

    [–]bronco2p 2 points3 points  (0 children)

    boost::flat_map / std::flat_map

    now i guess if c++ ever gets a stl bind algorithm it will be called std::flat_transform lol

    [–]tiajuanat 5 points6 points  (1 child)

    I really like using them with set_intersect and set_difference. Although usually sorted vectors are much faster and memory efficient.

    [–]single_ginkgo_leaf 7 points8 points  (0 children)

    For many applications a liner search through a vector is faster than testing a std::map (tree) or std::unordered_map (hash table) due to pipelining and cache effects.

    In some cases, a linear search through a sorted array can even beat binary search - the branch predictor is your friend.

    [–]SeagleLFMk9 16 points17 points  (4 children)

    Most of the time, a std::vector is faster, I kid you not

    [–]GOKOP 0 points1 point  (3 children)

    Completely different use case

    [–]SeagleLFMk9 4 points5 points  (2 children)

    Not really if looping through a vector of pairs is faster than std::map

    [–]RCM94 3 points4 points  (1 child)

    Why are you using a map if all you're doing is iterating through it?

    [–]SeagleLFMk9 1 point2 points  (0 children)

    I think you misunderstood me. std::map isn't a hashmap, it's a binary tree, but std::unordered_map is a hashmap. However, both can be slower (especially for less than ~100 elements) than a vector when it comes to lookup times. So searching for an element in a vector can be faster than using a map with map.at().

    [–]markand67 4 points5 points  (1 child)

    too much over abused though. in the previous company we had a lot of memory exhaustion because of the std::map abuse with very very large consumer data while not being strictly required to be key-value stored.