Just as we can initialize vectors as:
vector<int> var1(2000,1);
Is it possible to initialize map;
map<int, int>var2;
for 2000 variables…the reason why I want to initialize are two:
- In case I access an element in future e.g. map[100]..I want that map[100]=0
- The second reason is that I am using a minimum priority queue which for comparison uses the second value of map i.e. the value stored in map[0]…map[100].
- I don’t want to use vectors as my indices are really skewed and this leads to a lot of wasted space…i.e. my indices are map[0], map[30], map[56],map[100],map[120],map[190], etc.
Is there some way by which I can initialize the map for say 1000 variables…I am also open to using any other data structure.
Also the conventional way of initializing map i.e.
map<int, int> m = map_list_of (1,2) (3,4) (5,6) (7,8);
The above way does not work in my case…is there some other way out.PLEASE HELP
EDIT: I can not use for loop as:
This way the key remains fixed which I don’t want since the distribution of my keys is skewed. In essence applying for loop in this way is the same as that of vector and this I don’t want
You can do it using a surrogate instead of an
intin your map, like this: