I am using a map (which seemed the best implementation after a previous question, with a pair key, as a 'container' for incoming messages that can be sorted according to sourceID and priority i.e. key: (sourceID, priority) which points to an int value. Processing will happen 'on' this map.
I've just come against a problem - I need to do something like this pseudo code to subsequently retrieve messages:
map<pair<int, int>, int> mymap;
if (!mymap[make_pair(nodeID,i)].empty()) //i refers to all the priority levels
//processing occurs here to retrieve a value
but I can't seem to do it easily. Is there a way to do this simply without running an iterator e.g. for (i = 0; i <priority ; i++)
? I know that if I used an equivalent vector<vector<int>>
I would be able to do this easily, but a map works better for my program at the moment.
edit:
The messages are sorted into the map by (sourceID, priority level), and then processed before being mapped into another map by (destID, priority level). I need to check there there are messages available for any particular destID, regardless of priority level, so I am looking for an easy way to check this.
I know that if I use a vector<vector<int>>
, I will be able to do something like node[2].empty()
, if I want to check that node 2 has no available messages. Is there an equivalent for maps?