From: David Miller <davem@davemloft.net>
To: mirqus@gmail.com
Cc: roland@purestorage.com, johnwheffner@gmail.com, mj@ucw.cz,
netdev@vger.kernel.org
Subject: Re: ipv4: Simplify ARP hash function.
Date: Fri, 08 Jul 2011 12:51:18 -0700 (PDT) [thread overview]
Message-ID: <20110708.125118.886216418938741383.davem@davemloft.net> (raw)
In-Reply-To: <CAHXqBFKE_hLvFgL1_7F+k+pQ0+tEuhBqeRUOtgaM1yrjvXQQww@mail.gmail.com>
From: Michał Mirosław <mirqus@gmail.com>
Date: Fri, 8 Jul 2011 21:39:18 +0200
> With b[3] = b[0] ^ b[1] ^ b[2] you get 2^24 keys that hash to the same bucket.
Ok, I'm convinced, thanks :-)
--------------------
#include <stdlib.h>
#include <stdio.h>
int hashfn(unsigned int key, unsigned int rnd)
{
unsigned int x = key ^ rnd;
x ^= (x >> 8) ^ (x >> 16) ^ (x >> 24);
return x & 0xff;
}
int count[256];
unsigned int collide(unsigned int key)
{
unsigned int b0 = key >> 24;
unsigned int b1 = (key >> 16) & 0xff;
unsigned int b2 = (key >> 8) & 0xff;
key &= ~0xff;
key |= (b0 ^ b1 ^ b2);
return key;
}
int main(int argc, char **argp)
{
unsigned int rnd = atoi(argp[1]);
unsigned int i;
for (i = 0; i < (64 * 1024); i++) {
unsigned int key = i << 8;
unsigned int hash;
key = collide(key);
hash = hashfn(key, rnd);
printf("%u: %u\n", key, hash);
count[hash]++;
}
for (i = 0; i < 256; i++)
printf("COUNT[%3u]=%3u\n", i, count[i]);
return 0;
}
next prev parent reply other threads:[~2011-07-08 19:51 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-07-08 17:10 ipv4: Simplify ARP hash function David Miller
2011-07-08 17:40 ` Martin Mares
2011-07-08 17:47 ` David Miller
2011-07-08 17:54 ` David Miller
2011-07-08 18:03 ` John Heffner
2011-07-08 18:06 ` David Miller
2011-07-08 19:26 ` Roland Dreier
2011-07-08 19:27 ` David Miller
2011-07-08 19:39 ` Michał Mirosław
2011-07-08 19:51 ` David Miller [this message]
2011-07-08 19:59 ` David Miller
2011-07-08 20:10 ` Michał Mirosław
2011-07-08 20:34 ` Michał Mirosław
2011-07-08 20:35 ` David Miller
2011-07-08 20:44 ` Roland Dreier
2011-07-08 22:32 ` David Miller
2011-07-08 23:11 ` Roland Dreier
2011-07-10 19:07 ` David Miller
2011-07-08 23:41 ` Stephen Hemminger
2011-07-08 23:47 ` David Miller
2011-07-09 3:08 ` Stephen Hemminger
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20110708.125118.886216418938741383.davem@davemloft.net \
--to=davem@davemloft.net \
--cc=johnwheffner@gmail.com \
--cc=mirqus@gmail.com \
--cc=mj@ucw.cz \
--cc=netdev@vger.kernel.org \
--cc=roland@purestorage.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).