Re: If you can help... (map::find and map::insert)
On Jun 26, 4:42 pm, Joe Greer <jgr...@doubletake.com> wrote:
Ricardo <rbalbi...@gmail.com> wrote innews:7fe5e5e3-cc9a-4cd5-831f-31b79b=
ba6fd5@f30g2000vbf.googlegroups.com:
// 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.destinatio=
nIP) &&
(left.sourceIP <
right.sourceIP));
}
The problem is that this doesn't produce a strict ordering. Note that =
if
left.destinationIP >= right.destinationIP then the comparison relys on
sourceIP and doesn't really involve destinationIP. I thnk that what yo=
u
really want is something like:
return (left.destinationIP < right.destinationIP)
|| ((left.destinationIP == right.destinationIP)
&& (left.sourceIP < right.sourceIP));
That way, if left.destinationIP > right.destinationIP you return false.
joe
So, if I change the code to something like that:
bool SFlowId::operator<(const SFlowId &to) const {
if (this->destinationIP < to.destinationIP)
return true;
else if (this->destinationIP > to.destinationIP)
return false;
if (this->sourceIP < to.sourceIP)
return true;
else if (this->sourceIP > to.sourceIP)
return false;
if (this->destinationPort < to.destinationPort)
return true;
else if (this->destinationPort > to.destinationPort)
return false;
if (this->sourcePort < to.sourcePort)
return true;
else if (this->sourcePort > to.sourcePort)
return false;
if (this->protocol < to.protocol)
return true;
else if (this->protocol > to.protocol)
return false;
if (this->TOS < to.TOS)
return true;
else if (this->TOS > to.TOS)
return false;
if (this->ingressInterface < to.ingressInterface)
return true;
else if (this->ingressInterface > to.ingressInterface)
return false;
if (this->destinationMAC < to.destinationMAC)
return true;
else if (this->destinationMAC > to.destinationMAC)
return false;
if (this->sourceMAC < to.sourceMAC)
return true;
else if (this->sourceMAC > to.sourceMAC)
return false;
if (this->VLAN < to.VLAN)
return true;
return false;
}
it should work? There are several fields, indeed...
Anyways, besides that problem... I still would like to understande, if
you please, WHY insert behaves properly and find do not... even with
the function not properly written...
Thanks for now and awaiting for your comments :)
Ricardo