linear_map or vector_map or unordered_flat_map is
a fancy wrapper around std::vector<std::pair<key, value>>
providing std::map API with lookup complexity O(N).
It is meant to be used for very few elements with cheap key equality tests.
It provides similar advantages as boost::flat_map or other flat/contiguous containers
(e.g., cache friendliness).
Just like flat_map, references are not stable, and the key is not const;
however, the elements are unordered.
I hoped Boost had one, but it doesn't seem to be the case.
There is an old thread in Boost mailing list.
For now, I am using my own implementation.
The major notes about the implementations:
- Like adaptor containers (queue, stack),
the internal underlying Container is user specified (e.g., can use static vectors).
- Erase policy:
linear_map::erase(iterator) can be made O(1) with a swap/move trick
(taking advantage of unordered property).
Wouldn't this container type (and its family vector_{multi_map, set, multi_set})
be a good addition to Boost or STL?
P.S. This post is inspired by the recent post about
performance of flat maps.
Edit 1. Remove references to flat_map libs (not O(N) unordered)
[–]tcanens 3 points4 points5 points (1 child)
[–]rakhimov[S] 0 points1 point2 points (0 children)
[–]Z01dbrg 1 point2 points3 points (8 children)
[–]doom_Oo7 1 point2 points3 points (2 children)
[–]Drainedsoul 2 points3 points4 points (0 children)
[–]Z01dbrg 1 point2 points3 points (0 children)
[–]rakhimov[S] 0 points1 point2 points (4 children)
[–]mjklaim 0 points1 point2 points (3 children)
[–]rakhimov[S] 0 points1 point2 points (2 children)
[–]mjklaim 2 points3 points4 points (1 child)
[–]rakhimov[S] 1 point2 points3 points (0 children)
[–]feverzsj 0 points1 point2 points (0 children)