import "Array" import "Utils" -- principle of the dictionary -- hash of a string = integer part of -- ((ord(char1) * ... * ord(char2))/500)*5 -- This leaves the first 4 entries unused; -- entry 1 gives the first free entry in the array -- five entries are reserved for each hash-value; -- when four are filled in extra space is reserved ; -- the fifth entry points to the extra space (second entry -- of the tuple; the string part is nil.) -- 1000 places are reserved for extensions; -- for a maximum number of atoms 3500. params :: Array Int Int params = array (1,b) [ (i,0)| i <- [1 .. b]] b :: Int b = 100 -- show element n f1 n = intToString(params1!n) -- set element 50 to 1 where params1 = params // [(50,1)] f3 pa n = intToString (i) where pa1 = pa // [(2,1)] i = pa1!n dict :: Array Int (String, Int) dict = array (1,3500) [ (i,("",0)) | i <- [1 .. 3500]] f2 = show (ord 'a') -- result 97 hash :: String -> Int hash "" = -1 hash s |bv1 = -1 |otherwise = (x `rem` 500) * 5 where x = hash1 s bv1 = x == -1 -- hash1 makes the product of the ordinal numbers minus 96 hash1 :: String -> Int hash1 "" = 1 hash1 (x:xs) = (ord x) * (hash1 xs)