// This function of mine doesn't seem to work
vector <int> getIndexFromMap(std::vector <string> &myList, map<string,double>&m) {
vector <int> foundIndex;
for (int i = 0; i< myList.size() ; i++ ){
map<string,double>::iterator iter = m.find(myList[i]);
for ( int k =0 ; k < m.size() ; k++ ) {
if (iter->first == myList[i]) {
cout << "K " << k << ",";
foundIndex.push_back(k);
}
}
}
return foundIndex;
}
Yes, I want to use map instead of vector for this task.
Because I the map also used in other parts of my code.
Also since the size of Map is very2 large. I prefer not to
have another variable for storing them.
returns the linear distance between two iterators. The iterators must be in the same container, and start must come "before" end. (ie, it must be possible to increment start and eventually reach end).
However that turns the lookup algorithm into an O(n) algorithm that will run slower than a linear search on any unordered container.
I'm also wondering why one would want such an index for anything. A map is internally sorted; it maintains it's own order and does not guarantee anything about the validity of an index/offset for its elements. The index sounds useless.
It might be time for a better look at your design.