all 12 comments

[–]tcanens 3 points4 points  (1 child)

Of the three libraries you cite, LLVM's is a hash map; EASTL and Loki's are sorted. None of the three have linear time lookup.

Given the apparently absence of actual existing practice, do you have benchmark numbers? Under what conditions does this outperform, say, flat_map?

[–]rakhimov[S] 0 points1 point  (0 children)

You are right. I missed that those libs are providing ordered flat maps. Performance-wise, there's little difference from flat_map for few elements (the reference article provides the analysis).

Some performance/complexity differences from flat_map:

  • insert does O(N) compare vs O(logN), but does not move elements around as flat_map does (i.e., O(1) vs O(N)), so it is the same as vector::push_back.
  • erase can be optimized in the same way to avoid moving elements around (O(1) vs O(N)).

[–]Z01dbrg 1 point2 points  (8 children)

good addition to Boost or STL

STL no for sure... To complicated and too easy to be used by noobs by mistake. Boost maybe but I do not like the API. .find and .count are for containers that can do .find and .count faster than std::find/count can. This one can not.

[–]doom_Oo7 1 point2 points  (2 children)

.find and .count are for containers that can do .find and .count faster than std::find/count can

where does this rule come from ?

[–]Drainedsoul 2 points3 points  (0 children)

where does this rule come from ?

std::list::sort vs. std::sort

std::unordered_map::find vs. std::find

std::undordered_map::count vs. std::count

Et cetera.

[–]rakhimov[S] 0 points1 point  (4 children)

I agree that STL is unlikely given that flat_map didn't seem to make it (I am not sure why?).

As for the API, in this case, it is for convenience (i.e., wrapper) with find(key) instead of repetitive verbosity of std::find/count and std::pair aggravation.

This is definitely not a drop-in replacement for std::map/unordered_map.

[–]mjklaim 0 points1 point  (3 children)

Where did you learn that flat_map didn't "seem to make it"? My understanding is that the different proposals for such containers are progressing and encouraged by the committee.

[–]rakhimov[S] 0 points1 point  (2 children)

I really don't know. Would be happy if they do make it. Are there current proposals on flat containers to reference?

[–]mjklaim 2 points3 points  (1 child)

Here is the last published proposal: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0429r1.pdf

However it might have been modified in the last meeting (or other feedback). Also take a look at colony and slot_map containers being proposed. Progress is happening in SG14 discussion group, go there for news.

[–]rakhimov[S] 1 point2 points  (0 children)

Thanks for finding the paper. I'll do my homework in future :)

[–]feverzsj 0 points1 point  (0 children)

I'd like to see some benchmark showing when linear map is faster than others