On Wed, 26 Nov 2003 13:49:54 -0800, "Jonathan" <nospam@aol.com> wrote
in comp.lang.c++:
[color=blue]
> I am hoping that someone more experienced than myself can point me towards
> what might be the fastest data lookup method to use for storing ip
> addresses. My situation is that I will need to maintain a list of perhaps 50
> ip addresses to be used in a packet sniffing application. For each packet
> that goes through the application (which will be monitoring all traffic
> through a switch), I need to see if an entry for the source ip of that
> packet already exists in the list, and if not, add it.
>
> My ip list is not going to be too large (perhaps 50-100 items at a time),
> but I am going to be constantly searching the list every time a packet is
> received, which could be an incredible burden if doing a simple linear
> search on a linked list.
>
> What would be the best possible implementation for my situation? A binary
> search (slightly faster), a hash table which hashes the ip as a 32 bit
> integer or a string, anything else?
>
> Thanks in advance!
> Jonathan Halterman[/color]
I realize that this is really an algorithm, not a C++ question, but
stop and think -- why in the world would you want hash ip addresses to
32 bit integer types? By definition, an IPV4 address is actually
nothing but an unsigned 32-bit integer type. Dotted-quad notation is
just a convenience. Every single IPV4 address can be, rather quickly,
converted directly to an unsigned long, and every unique IP address
will result in a different unsigned long.
--
Jack Klein
Home:
http://JK-Technology.Com
FAQs for
comp.lang.c
http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++
http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
ftp://snurse-l.org/pub/acllc-c++/faq