Unordered(FIFO) hash_map implementation . Plz help

veer123's Avatar, Join Date: Jan 2009
Newbie Member
Hi want to implement an unordered hashmap ie. FIFO implementation using the standard hash_map library . Below is the sample i tested.Please help me with this.

#include <hash_map>
#include <iostream.h>
int main()
{
hash_map<int,int>testMap;
testMap[1]=1;
testMap[3]=5;
testMap[2]=2;
typedef hash_map<int,int>::iterator hashIter;
for(hashIter it=testMap.begin();it!=testMap.end();it++)
{
cout<<it->second<<"\n";
}
}

The output i get is

It gives output as

1
2
5

But I want . ie i want it in the same way i inserted it .

1
5
2

Any suggestions ?
sharmila's Avatar, Join Date: Mar 2006
Contributor
If you want to display in the same way you inserted, you have to display in the sameway.. 1st, then 3rd and then 2nd values.. not using a for loop by incrementing iterator..
veer123's Avatar, Join Date: Jan 2009
Newbie Member
After lots of trial and error i have found the answer .

In hashmap the hashFunc has to be empty . Something like this



struct hashFunc

{

int operator() (int i) const

{

}

};

This will not sort the data it will be in the manner u insert it….It will be in the stack order. ( What you enter last will be on top ) ...