I have a data structure that stores values for rows. The rows are ordered, but not contiguous. In example I have 1,2,200,3000,3001,3002,8900,98700, etc.
A MAP is the most appropiate structure, inst't ? I'm going to use it only to know that 3001 is at 4, nothing more. So ... any trick to use it ? I need the faster way to use it.
Thanks
I think that it's the container appropriate for you job. Map provides iterator so you can use them.
Dereferencing a map iterator though returns a pair<key, int> (for your case) and you must use a syntax like: it->first (it:iterator) for key it->second for int.
Also as I recall don't search for a certain value through key because if there isn't an element with key = key it will create one with this key.
If all you need to know is that 3001 is at spot 4 (i.e. the 5th element, thus the 'keys' are incremental), a regular vector might be sufficient. If its size will be rather small, you can just iterate through it until you find the value you were looking for. If it's going to be larger, it might be worth implementing a binary searching method (i.e. check middle value: if it's larger than your value, check the left half; else, check the right; repeat on chosen half).
I don't think there's much point in using a map if the key simply notes the location in the list.