Re: $100 Contest Question
- Posted by Derek Parnell <ddparnell at bigpond.com> Mar 03, 2002
- 460 views
I'm at my office now, so I'll try your code tomight when I get home. On my office machine (P6 800Mhz, Windows 2000) this runs in 1.16 seconds. 4/03/2002 11:59:20 AM, euman at bellsouth.net wrote: > >Hello all, > >Talking about speed! > >I found a much better way to implement my Hash table (below) for the >"words.txt" file so I thought Id post this old piece. > >-- hashing the dictionary takes @3.5 sec on my 233mhz laptop >-- 26 x 26 In alphabetical and length of text order. > >The routine here is pretty fast, believe it or not I figured out a way to speed >this up 100 fold and still have the same accuracy and distribution. >I'll share that one in a month or so... > >Maybe I could get some people to tell me how fast a PIII 550 or higher >might run this piece. > ><snip.....> > >without type_check >without trace > >include get.e >include file.e >include print.e > >atom t, junk > t = time() > >integer fnA, len >fnA = open("words.txt","r") > >integer len_text >function EumsHash( sequence text) -- a more unique hash > atom h, g > integer short > h = 0 > len = length(text) > for i = 1 to len do > short = text[i] > if short = 32 or short = 10 then > len_text = i - 1 > exit > end if > if h > #0FFFFFFF or h < 0 then -- (overflow) > h = and_bits(h, #0FFFFFFF) > end if > h *= 16 > h += short > g = and_bits(floor(h / #1000000), #F0) > if g != 0 then > h = xor_bits(h, g) > end if > h = and_bits(h, not_bits(g)) > end for > return h >end function > >sequence hash_table >hash_table = repeat(repeat({}, 26),26) -- 26 -> 676 buckets > >object line >integer letter >atom hashed > >while 1 do -- hashing the dictionary takes @3.5 sec on my 233mhz laptop > line = gets(fnA) > if atom(line) then > exit > end if > hashed = EumsHash(line) > hash_table[line[1] - 64][len_text] &= hashed >end while > >close(fnA) > >? time() - t > >if getc(0) then >end if --------- Cheers, Derek Parnell