From owner-freebsd-hackers@FreeBSD.ORG Fri Dec 28 13:12:28 2007 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 B090316A417 for ; Fri, 28 Dec 2007 13:12:28 +0000 (UTC) (envelope-from aryeh.friedman@gmail.com) Received: from mta1.srv.hcvlny.cv.net (mta1.srv.hcvlny.cv.net [167.206.4.196]) by mx1.freebsd.org (Postfix) with ESMTP id 7CEF513C465 for ; Fri, 28 Dec 2007 13:12:28 +0000 (UTC) (envelope-from aryeh.friedman@gmail.com) Received: from flosoft.no-ip.biz (ool-435559b8.dyn.optonline.net [67.85.89.184]) by mta1.srv.hcvlny.cv.net (Sun Java System Messaging Server 6.2-8.04 (built Feb 28 2007)) with ESMTP id <0JTR00HUGFAGIER0@mta1.srv.hcvlny.cv.net>; Fri, 28 Dec 2007 07:42:18 -0500 (EST) Received: from flosoft.no-ip.biz (localhost [IPv6:::1]) by flosoft.no-ip.biz (8.14.2/8.14.2) with ESMTP id lBSCgFMU001267; Fri, 28 Dec 2007 07:42:15 -0500 Date: Fri, 28 Dec 2007 07:42:15 -0500 From: "Aryeh M. Friedman" In-reply-to: To: Ivan Voras Message-id: <4774EF27.90307@gmail.com> MIME-version: 1.0 Content-type: text/plain; charset=UTF-8 Content-transfer-encoding: 7BIT X-Enigmail-Version: 0.95.5 References: <5950EE0C-383D-4D6B-9991-A0DEABD2ADE4@u.washington.edu> <20071228003716.GB48997@lor.one-eyed-alien.net> User-Agent: Thunderbird 2.0.0.9 (X11/20071217) Cc: freebsd-hackers@freebsd.org Subject: Re: BSD license compatible hash algorithm? 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: Fri, 28 Dec 2007 13:12:28 -0000 -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Ivan Voras wrote: > Garrett Cooper wrote: > >> Looks promising, but how difficult would it be to port the code >> to other platforms (Win32 for instance?). > > The hash algorithm itself as implemented in hash.h is pretty much a > text-book hash algorithm (D.J.Bernstein's): > > #ifndef HASHINIT > #define HASHINIT 5381 > #define HASHSTEP(x,c) (((x << 5) + x) + (c)) > #endif > > /* > * Return a 32-bit hash of the given buffer. The init > * value should be 0, or the previous hash value to extend > * the previous hash. > */ > static __inline uint32_t > hash32_buf(const void *buf, size_t len, uint32_t hash) > { > const unsigned char *p = buf; > > while (len--) > hash = HASHSTEP(hash, *p++); > > return hash; > } > > It apparently has some weaknesses if used on binary (non-text) data > but I don't see why it wouldn't work on Windows. All hashs have issues with pooling.... see http://www.burtleburtle.net/bob/hash/index.html... btw it is a old wives tale that the number of buckets should be prime (mostly based on the very weak implementation Knuth offered) - -- Aryeh M. Friedman FloSoft Systems http://www.flosoft-systems.com Developer, not business, friendly -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.4 (FreeBSD) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFHdO8mzIOMjAek4JIRApb6AJ93JNR1sIPg6mH4TrOCEUn2jfdinwCeI/UO IQLG9bX1N5PHxsSALDS7dzw= =saZk -----END PGP SIGNATURE-----