• 1 reply
  • Latest Post - ‏2012-10-02T08:22:24Z by BoudewijnDijkstra
84 Posts

Pinned topic OMUMap searches

‏2012-09-26T20:58:18Z |
Looking at the code in omumap.h, the searches done in an OMUMap basically actually compare the key addresses (void*).
What's the point of sorting keys by their addresses, unless OMUMap is willing to represent some kind of unordered map?
If so, that means, unless you're able to cast a key into an int (or whatever fits a void*), you don't have an ordered map?
If so, that means there is no efficient way to search a key in an OMUMap, and you have to revert to sequentially browsing it with an iterator?
Did I just figure it out?
Updated on 2012-10-02T08:22:24Z at 2012-10-02T08:22:24Z by BoudewijnDijkstra
  • BoudewijnDijkstra
    20 Posts

    Re: OMUMap searches

    • Sorting by address is the easiest way to sort without requiring the key type to have comparison functions. Also, it is not unordered; the ordering is predictable, controllable and stable.
    • If you can't cast a key type to void*, you should use the key pointer type and you will still have an ordered map. If you want the keys to be in a specific order, then you should consider using a different container type.
    • If you bothered to look at the code in detail, you would have seen that it uses binary search to find keys. If that is too inefficient for you, then use a hash map.