From owner-freebsd-hackers@FreeBSD.ORG Sat Jun 2 19:01:10 2012 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 1E43A1065672 for ; Sat, 2 Jun 2012 19:01:10 +0000 (UTC) (envelope-from phk@phk.freebsd.dk) Received: from phk.freebsd.dk (phk.freebsd.dk [130.225.244.222]) by mx1.freebsd.org (Postfix) with ESMTP id CE5948FC12 for ; Sat, 2 Jun 2012 19:01:09 +0000 (UTC) Received: from critter.freebsd.dk (critter.freebsd.dk [192.168.61.3]) by phk.freebsd.dk (Postfix) with ESMTP id 9DBC613F68; Sat, 2 Jun 2012 19:01:02 +0000 (UTC) Received: from critter.freebsd.dk (localhost [127.0.0.1]) by critter.freebsd.dk (8.14.5/8.14.5) with ESMTP id q52J10vP012213; Sat, 2 Jun 2012 19:01:02 GMT (envelope-from phk@phk.freebsd.dk) To: "enrico d'urso" From: "Poul-Henning Kamp" In-Reply-To: Your message of "Sat, 02 Jun 2012 20:14:34 +0200." Content-Type: text/plain; charset=ISO-8859-1 Date: Sat, 02 Jun 2012 19:01:00 +0000 Message-ID: <12212.1338663660@critter.freebsd.dk> X-Mailman-Approved-At: Sat, 02 Jun 2012 20:40:05 +0000 Cc: freebsd-hackers@freebsd.org Subject: Re: [Hash function Ipv4] X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 02 Jun 2012 19:01:10 -0000 In message , 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.