comp.lang.ada
 help / color / mirror / Atom feed
From: antonio_duran@hotmail.com (Antonio Duran)
Subject: Re: hashing
Date: 6 May 2002 13:42:19 -0700
Date: 2002-05-06T20:42:20+00:00	[thread overview]
Message-ID: <e1a50f2.0205061242.6c0b5dc@posting.google.com> (raw)
In-Reply-To: 1b2t8.507$na.19833@news8-gui.server.ntli.net

"chris.danx" <chris.danx@ntlworld.com> wrote in message news:<1b2t8.507$na.19833@news8-gui.server.ntli.net>...
> Hi,
> 
> Does anyone have a good hash function for strings (length is arbitary,
> number of buckets is determined when package is instantiated and collisions
> are handled with chaining)?  I'm new to writing hash tables and functions
> (used them in libs, but this has to be all my own work!), and have chosen
> this technique to implement in an assignment -- had enough linked lists, and
> want to expand my horizons.
> 
> I'm searching for a function just now, so this isn't laziness just wanted to
> utilise another resource (your brains) in case nothing turns up.  After the
> assignment submission in a few weeks, I'll tidy up the sources for all the
> useful adts I've written this term and GMGPL them (lists (singly, doubly),
> hash tables, and whatever else comes up) if ppl express an interest (all
> adts are generic so far).
> 
> 
> 
> Thanks,
> Chris
> 
> p.s. does anyone have any uses for circular lists?  Tom Swans Tp5.5 book
> mentions them, what are they used for?  Just curious...
> 
> 
> p.p.s. should performance/complexity information be included?  I seem to
> recall a conversation on this a while back, but can't remember if ppl
> thought it was a good idea.

I've found the hash function:

with Interfaces;

function    Hash(
               What        : in     String)
   return   Interfaces.Unsigned_32
is
   Hash_Code      : Interfaces.Unsigned_32 := 0;
begin
   for I in What'Range loop
      Hash_Code := (31 * Hash_Code) + 
                   Interfaces.Unsigned_32(Character'Pos(What(I)));
   end loop;

   return Hash_Code;
end Hash;

The returned value must be mod'ed by the number of buckets in your
hash table (that number should be a prime number).



  parent reply	other threads:[~2002-05-06 20:42 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-04-10 21:31 hashing chris.danx
2002-04-10 21:24 ` hashing Steven Deller
2002-04-10 22:41   ` hashing Nick Williams
2002-04-10 23:36   ` hashing chris.danx
2002-04-11 14:18     ` hashing joevl
2002-04-15 15:32     ` hashing Ken Burtch
2002-04-11 23:18   ` hashing(HATs. A more efficient algorithm?) Wannabe h4x0r
2002-04-11 23:29     ` chris.danx
2002-04-12  7:24       ` Wannabe h4x0r
2002-04-12 15:00         ` Chad R. Meiners
2002-04-12 17:22         ` tmoran
2002-04-10 21:56 ` hashing Chad R. Meiners
2002-04-10 23:43 ` hashing Ted Dennison
2002-04-11 16:12 ` hashing Georg Bauhaus
2002-04-11 22:36 ` hashing Simon Wright
2002-05-03 10:16 ` hashing Antonio Duran
2002-05-05 13:55 ` hashing Robert Dewar
2002-05-06 20:42 ` Antonio Duran [this message]
2002-05-06 23:36   ` hashing Jeffrey Carter
  -- strict thread matches above, loose matches on Subject: below --
2002-04-10 22:00 hashing Beard, Frank [Contractor]
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox