My goal is to map elements of a type to other elements of the same type. Suppose they are size_t
for simplicity.
std::map<size_t, size_t> myMapping;
This would do it, but if I want to follow a bunch of such links (they are all the same map), each step is a log(n)
lookup.
size_t k = /*whatever*/;
myMapping[myMapping[myMapping[k]]]; //3 * log(n)
I want to make use of the fact that map iterators remain valid and have a map that maps size_t to iterators into itself.
typedef /*myMapTemplate*/::iterator map_iter;
std::map<size_t, map_iter> myMapping;
size_t k = /*whatever*/
map_iter entryPoint = myMapping.find(k);
entryPoint->second->second->first; //log(n) + 2 constant time operations
How would I write this type? I know copying would keep iterators to old map and plan to take care of this myself.