X-Authentication-Warning: anthony.siemens.ebp.ii3.b-rail.be: ddemerre owned process doing -bs Date: Fri, 2 Feb 2001 06:23:29 +0100 (CET) From: Dieter Demerre X-Sender: To: Subject: Re: Hash function In-Reply-To: <95cfee$m9h$1@venus.telepac.pt> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=X-UNKNOWN Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from QUOTED-PRINTABLE to 8bit by delorie.com id AAA32655 Reply-To: djgpp AT delorie DOT com Errors-To: nobody AT delorie DOT com X-Mailing-List: djgpp AT delorie DOT com X-Unsubscribes-To: listserv AT delorie DOT com Precedence: bulk -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Thu, 1 Feb 2001, Frederico Jerónimo wrote: > Ex : Given 0x8ae29 the function would return 0x629 > > I know this is not a very efficient hash function so I was wondering if > anyone has any ideas for a better one. Thanks in advance, int hashpjw(const int seed, const char* s) /* ACTION: perform some bit-operations upon the characters of s, to obtain a rather unique integer. (chaotic behaviour) (n.b. chaotic means little changes within s chould cause huge changes in result) Refer to the Dragonbook. */ { const char* p; unsigned int hv = 0; unsigned int g; for ( p = s; *p; p++ ) { hv = (hv << 4) + (*p); if ((g = (hv & 0xf0000000U)) != 0U) { hv = hv ^ (g >> 24); hv = hv ^ g; } else { } } return hv % seed; } - -- Groetjes vanwege... Greetings from... -- - -- Dieter Demerre *** ddemerre AT acm DOT org -- - -- http://www.angelfire.com/de/ddemerre/ -- -----BEGIN PGP SIGNATURE----- Version: PGP 6.5.8 iQA/AwUBOnpEWglG34XnM6kpEQKgPgCfXOGpwglZWcBMHjbzQBLcmrEoQQgAoNtp G74fNBxbmrf2Aff0suJx9p0f =jkYA -----END PGP SIGNATURE-----