Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 02 Jun 2012 19:01:00 +0000
From:      "Poul-Henning Kamp" <phk@phk.freebsd.dk>
To:        "enrico d'urso" <e.durso@live.com>
Cc:        freebsd-hackers@freebsd.org
Subject:   Re: [Hash function Ipv4]
Message-ID:  <12212.1338663660@critter.freebsd.dk>
In-Reply-To: Your message of "Sat, 02 Jun 2012 20:14:34 %2B0200." <DUB116-W41324220EB6A5F7FD8B06A97090@phx.gbl>

next in thread | previous in thread | raw e-mail | index | archive | help
In message <DUB116-W41324220EB6A5F7FD8B06A97090@phx.gbl>, enrico d'urso writes:
>

>I'm looking for an Hash function for Ipv4 addresses.
>
>What are good ones?

They are generally very hard to hash well, for all sorts of reasons
related to how we use them.

One way that used to work reasonably well for me:

	uint32_t ipv4, h;

	h = ipv4 % HASH;
	ipv4 /= HASH;
	h ^= ipv4 % HASH;
	h ^= ipv4 / HASH;

Where HASH was a prime number near to 2^11

However, I cannot rule out that the good results I saw was a result
if RIPE's allocation policy at the time.


-- 
Poul-Henning Kamp       | UNIX since Zilog Zeus 3.20
phk@FreeBSD.ORG         | TCP/IP since RFC 956
FreeBSD committer       | BSD since 4.3-tahoe    
Never attribute to malice what can adequately be explained by incompetence.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?12212.1338663660>