Hey guys get this...
I defined a vector of maps, like this:
And a map of vectors (i called it index) like this:Code:typedef vector<map<string,unsigned int> > myvec;
Then I did the following:Code:typedef map<string,vector<unsigned int> > index;
In my class, called myCoogle, i declaredand I filled it with maps...Code:myvec the_vec;
In each map there's a word (string) and a number (unsinged int).
So far so good.
I declared alsoNow I want to copy all the different words from maps_vec to the_index.Code:index the_index;
The words would be the strings...
And for each vector<int> i will be adding the numbers stored in the vector of maps.
For example:
the_vec has 3 maps.
the 1st has: chicken,1 | person,1 | elevator,5 | is,2 | ...
the 2nd has: person,2 | icecream,3 | is,3 | ...
the 3rd has: elevator,1 | bear,1 | is,4 |chicken,3 | ...
*the words might be similar...
So the_index should look like this:
word,[vector of ints]
chicken[1,0,3]
person,[1,2,0]
elevator[5,0,1]
is[2,3,4]
icecream[0,3,0]
bear[0,0,1]
OK here's my function:
clarification: FILE# is the maps number... I'm working with files (*.txt files).Code:void Coogle::make_index() { //SCAN THE FIRST MAP myvec::iterator myvec_iter; map<string,unsigned int>::iterator map_iter; index::iterator idx_iter = the_index.begin(); for(map_iter=maps_vec[0].begin(); map_iter!=maps_vec[0].end(); ++map_iter) { the_index[map_iter->first].push_back(map_iter->second); } //SCAN THE OTHER MAPS myvec_iter=maps_vec.begin(); myvec_iter++; int i=0; //FILE # while(myvec_iter!=maps_vec.end()) { i++; for(map_iter=maps_vec[i].begin(); map_iter!=maps_vec[i].end(); ++map_iter) { string word=map_iter->first; cout << "DEALING WITH WORD \"" << word << "\"" << endl; index::iterator location; location=the_index.find(word); if(location!=the_index.end()) //if word found in the index { cout << "WORD EXISTS!" << endl; location->second[i]=map_iter->second; } else //if not found { cout << "WORD DOES NOT EXIST! NEW WORD." << endl; the_index[word].push_back(map_iter->second); } } cout << endl; ++myvec_iter; } }
Alright so after I scanned the first map, I tried to print the_index and all was fine.
But I get this when trying to print after scanning also the other maps:
So something is wrong with my 2nd 'for' loop.
Anyone can help please?
Very sorry for the very long post...
Thank you very much !!!



3Likes
LinkBack URL
About LinkBacks





