delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2001/02/02/00:29:03

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 <ext DOT dieter DOT demerre AT siemens DOT be>
X-Sender: <ddemerre AT anthony DOT siemens DOT ebp DOT ii3 DOT b-rail DOT be>
To: <djgpp AT delorie DOT com>
Subject: Re: Hash function
In-Reply-To: <95cfee$m9h$1@venus.telepac.pt>
Message-ID: <Pine.LNX.4.30.0102020622480.28137-100000@anthony.siemens.ebp.ii3.b-rail.be>
MIME-Version: 1.0
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

-----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-----


- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019