R
Ricardo
I have seen a lot of comments about this problem on the lists and,
even as I tried to implement the proper corrections, I was really
unable to do so... (or my problem is somehow different...).
I have a map that uses a class as its key.. something like this:
struct SFlowId {
uint32_t ingressInterface;
uint16_t VLAN;
uint32_t sourceIP;
uint32_t destinationIP;
uint16_t sourcePort;
uint16_t destinationPort;
};
I defined a < function to compare those values....
// this is short cause the problem occurs both with 2, 3 or 4
parameters being compared (anything more than 1 causes my problem).
bool operator<(const SFlowId &left,const SFlowId &right) {
return (left.destinationIP < right.destinationIP) ||
(!(left.destinationIP < right.destinationIP) && (left.sourceIP <
right.sourceIP));
}
Here is my map... :
map<SFlowId,SFlowInfo> fFlows;
After inserting some pairs on the map, I have the most strange
problem: (a) when I try to find a pair that is actually already inside
the map, I get a result with the find method that says that what I am
looking for is brand new.... (b) on the other way, if I try to insert
that same pair, using the same key, insert returns that the pair is
already on the map and no new pair is inserted on the map...
I know the < operator must obey certain rules and I do think that the
function is properly impåemented to fullfill those requirements.
The code I use is something like this:
SFlowId flid;
// just initialize the key values... omitted ...
flid.TOS = .....
map<SFlowId,SFlowInfo>::iterator it;
it = fFlows.find(flid);
if (it == fFlows.end()) {
// NOT FOUND ON THE MAP... MUST BE A NEW VALUE....
// create the value associated with the key....
pair<map<SFlowId,SFlowInfo>::iterator,bool> ret;
ret = fFlows.insert(pair<SFlowId,SFlowInfo>(flid,info));
if (ret.second) {
// REALLY A NEW VALUE...
} else {
// NOT A NEW VALUE
}
} else {
// FIND INDICATES ITS IS A NEW VALUE...
}
With this code, I often get results where find indicates a have a new
pair and insert says otherwise....
Can you help me understanding what is going on here?
If I use a single value in the comparison, I have no trouble at all...
I know I can just use insert in my code (and probably in my case this
will be better indeed), but I would like to understand what I am doing
wrong and how can two different methods behave in a different way....
Thanks in advance,
Ricardo
even as I tried to implement the proper corrections, I was really
unable to do so... (or my problem is somehow different...).
I have a map that uses a class as its key.. something like this:
struct SFlowId {
uint32_t ingressInterface;
uint16_t VLAN;
uint32_t sourceIP;
uint32_t destinationIP;
uint16_t sourcePort;
uint16_t destinationPort;
};
I defined a < function to compare those values....
// this is short cause the problem occurs both with 2, 3 or 4
parameters being compared (anything more than 1 causes my problem).
bool operator<(const SFlowId &left,const SFlowId &right) {
return (left.destinationIP < right.destinationIP) ||
(!(left.destinationIP < right.destinationIP) && (left.sourceIP <
right.sourceIP));
}
Here is my map... :
map<SFlowId,SFlowInfo> fFlows;
After inserting some pairs on the map, I have the most strange
problem: (a) when I try to find a pair that is actually already inside
the map, I get a result with the find method that says that what I am
looking for is brand new.... (b) on the other way, if I try to insert
that same pair, using the same key, insert returns that the pair is
already on the map and no new pair is inserted on the map...
I know the < operator must obey certain rules and I do think that the
function is properly impåemented to fullfill those requirements.
The code I use is something like this:
SFlowId flid;
// just initialize the key values... omitted ...
flid.TOS = .....
map<SFlowId,SFlowInfo>::iterator it;
it = fFlows.find(flid);
if (it == fFlows.end()) {
// NOT FOUND ON THE MAP... MUST BE A NEW VALUE....
// create the value associated with the key....
pair<map<SFlowId,SFlowInfo>::iterator,bool> ret;
ret = fFlows.insert(pair<SFlowId,SFlowInfo>(flid,info));
if (ret.second) {
// REALLY A NEW VALUE...
} else {
// NOT A NEW VALUE
}
} else {
// FIND INDICATES ITS IS A NEW VALUE...
}
With this code, I often get results where find indicates a have a new
pair and insert says otherwise....
Can you help me understanding what is going on here?
If I use a single value in the comparison, I have no trouble at all...
I know I can just use insert in my code (and probably in my case this
will be better indeed), but I would like to understand what I am doing
wrong and how can two different methods behave in a different way....
Thanks in advance,
Ricardo