January 14th, 2013, 08:58 AM
Hash table for ip addreses
I need to store IP addresses in a hash table and count the number of messages they send.
(Unknown number of IPs or messages)
I don't know what is the fastest data structure in this case (an array, a tree...).
Also i need a good hash function for the IP addresses.
Thanks in advance...
January 14th, 2013, 03:54 PM
If you are using C++ just use std::map. If you do it in C (and don't use a library) you are going to be writing 100's of lines of code that all has to work perfectly, not simple or easy even for experts.
January 14th, 2013, 05:04 PM
On a *nix system with a C compiler, you can use hcreate(), hsearch() and hfree(). Alternatively, you could use a third party library such as Apache's APR library (specifically, the apr_hash_xx routines), which is portable across multiple platforms.
Originally Posted by mitakeet
For C++, you could use std::unordered_map instead of std::map if you have a C++ 0x standard compliant compiler. For older C++ compilers, most of them support a std::hash_map template even though it wasn't part of the standard :). std::hash_map is faster than std::map (because std::map sorts on every item insert)
Up the Irons
What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
"Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
Down with Sharon Osbourne
"I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo