From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,eec376a334ad59ed X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-05-06 13:42:20 PST Path: archiver1.google.com!postnews1.google.com!not-for-mail From: antonio_duran@hotmail.com (Antonio Duran) Newsgroups: comp.lang.ada Subject: Re: hashing Date: 6 May 2002 13:42:19 -0700 Organization: http://groups.google.com/ Message-ID: References: <1b2t8.507$na.19833@news8-gui.server.ntli.net> NNTP-Posting-Host: 212.7.34.68 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: posting.google.com 1020717740 18333 127.0.0.1 (6 May 2002 20:42:20 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: 6 May 2002 20:42:20 GMT Xref: archiver1.google.com comp.lang.ada:23598 Date: 2002-05-06T20:42:20+00:00 List-Id: "chris.danx" 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).