[Hash function Ipv4]

enrico d'urso e.durso at live.com
Mon Jun 4 09:11:56 UTC 2012


Hi,
I did some tests with some subnets Ip /24  and I will share the results.


I got very good results with this configuration:

Hash table's size: 
Let x be the number of ip.
Y = x*2, then 
size_table = 'The power of 2 closest to Y, and greater than or equal to Y'.

Hash Function: 

return Ip_in_network_byte_order % size_table;

Collision's case:

In this case i have used research quadratic:
((unsigned int)( hash_function + 0.5*k + 0.5*k*k )) % size_table ;

----------------------------------
on the other hand

When I have used Random Ip, that does not belong to the same subnet ip:


unsigned int HASH = 2039;
  uint32_t  h; 
    h = key % HASH;
    key /= HASH;
    h ^= key % HASH;
    h ^= key / HASH; 

Suggested to me by Poul-Henning Kamp (thanks) works much better.

That's all.

Bye

Enrico 




 		 	   		  


More information about the freebsd-hackers mailing list