SCM Repository
View of /sml/branches/FLINT/src/comp-lib/strghash.sml
Parent Directory
|
Revision Log
Revision 245 -
(download)
(annotate)
Sat Apr 17 18:47:12 1999 UTC (21 years, 10 months ago) by monnier
File size: 740 byte(s)
Sat Apr 17 18:47:12 1999 UTC (21 years, 10 months ago) by monnier
File size: 740 byte(s)
version 110.16
(* stringhash.sml * * Copyright 1989 by AT&T Bell Laboratories *) structure StrgHash = struct val prime = 8388593 (* largest prime less than 2^23 *) val base = 128 fun hashString (str: string) : int = let val l = size str fun ordof i = Char.ord(String.sub(str, i)) in case l of 0 => 0 | 1 => ordof 0 | 2 => ordof 0 + base * ordof 1 | 3 => ordof 0 + base * (ordof 1 + base * ordof 2) | _ => let fun loop (0,n) = n | loop (i,n) = let val i = i-1 val n' = ordof i + (base * n) in loop (i, (n' - prime * Int.quot(n', prime))) end in loop (l,0) end (* end case *) end end (* structure StrgHash *) (* * $Log$ *)
root@smlnj-gforge.cs.uchicago.edu | ViewVC Help |
Powered by ViewVC 1.0.0 |