I wonder if anyone is aware of any library code that has the performance characteristics provided by L开发者_如何学Pythonoki's AssocVector (Locality of reference of the elements, lower per-element memory overhead compared to a map) but with Boost's BiMap functionality (able to query the map from both sides of the relation)?
Or would using a sorted std::vector of std::pairs and adding functionality to lookup the vector using either element of the pair as the key be the way forward?
It really depends on what you want to do fast. Loki::AssocVector
has O(n) insert and delete, while boost::bimap
has O(1) when you use it with hash tables. If you can live with O(n) operations on one "view" of your data structure and O(lg n) on the other, then your proposed solution will work fine and take little memory. It may be very fast for small data sets, if operations on one view dominate.
You may also consider using Boost.Intrusive or boost::bimap
with specialized allocators.
精彩评论