开发者

Anything available implemented like Loki's AssocVector but with the functionality of Boost's Bimap?

开发者 https://www.devze.com 2023-01-25 01:06 出处:网络
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 me

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号