Re: If you can help... (map::find and map::insert)
On Jun 30, 9:43 am, Joe Greer <jgr...@doubletake.com> wrote:
Ricardo <rbalbi...@gmail.com> wrote innews:afc72b86-18c6-4d5f-8116-5cd49e=
48615a@n30g2000vba.googlegroups.com:
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;
}
One other thing... You need to decide how you want to lookup your data=
..
The above looks like every field in the structure. If you know all tha=
t,
there probably isn't any reason to look it up. You don't really need
everything for your key. Just enough to be unique within the context o=
f
your application. For example, if you know that you will only have one
entry for any given sourceIP/port combination, that would be sufficient f=
or
theinsert/find mechanism. The problem with the previous code was that =
the
fields weren't used consistenly enough to give a good sorting order. T=
he
idea in general is that you need to be able to say that if A < B and B < =
C
than A < C. With your previous order, that wasn't always true. The =
above
looks correct, but may be overkill.
joe
First of all, tks a lot for your help!
Maybe I can get 2 or 3 fields off the key, but I do really need so
many items to classify my map, cause I have a struct that show some
info about a network flow, and to properly identify an unique flow I
need all that info (or most of it, at least).
But as I always understood, insert do return a value showing if it has
or has not find an already existing entry in the map. For what you
said, I do understand that it only searches till the point it thinks
the member is new, am I right?