Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!newstop!texsun!convex!convex.COM From: macphee@convex.COM (Scott C. Mac Phee) Newsgroups: comp.lang.c Subject: Re: hash function for text in C Message-ID: <107251@convex.convex.com> Date: 17 Oct 90 12:47:59 GMT References: <1990Oct16.184951.513@watdragon.waterloo.edu> Sender: news@convex.com Reply-To: macphee@convex.COM (Scott C. Mac Phee) Organization: Convex Computer Corporation, Richardson, Tx. Lines: 64 In article <1990Oct16.184951.513@watdragon.waterloo.edu> cpshelley@violet.waterloo.edu (cameron shelley) writes: > > I have been (futily :<) experimenting with hash functions to >hash english words into a large array. No book I can find around >here gives the topic more than cursory discussion. Does anyone >out there know of a good, simple one? They must exist, and I'm >getting a little tired of mine... (er, function that is, I can't >afford another data structures book right now :). Here is some code I've been using. It is an adapted version of some hashing algorithms I've seen pass through this newsgroup. Hope it helps... =========================================================================== /* * ============================================================================ * HASH TABLE FUNCTIONS * ============================================================================ */ #define HASH_TABLE_SIZE 1000 static int eventhash[HASH_TABLE_SIZE] ; static int hash_entries, /* number in table... */ collisions ; /* count of collisions */ int init_hash_table() { register int i ; hash_entries = collisions = 0 ; for (i=0; i