4

I wonder if anyone is aware of any library code that has the performance characteristics provided by Loki'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?

RedBlueThing
  • 42,006
  • 17
  • 96
  • 122
JPC
  • 41
  • 2

1 Answers1

1

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.

Fred Foo
  • 355,277
  • 75
  • 744
  • 836
  • +1, especially for the allocator bit. By using a specialized "pool" allocator, one gets the locality of reference. Writing the allocator is another beast entirely though. – Matthieu M. Nov 16 '10 at 07:33