1 (* Read shared dictionary. *)
6 let argv = Array.to_list Sys.argv
13 failwith (sprintf "usage: %s datafile"
17 let fd = openfile datafile [O_RDWR] 0o644 in
20 let arraysize = 256 (* one element for each character *)
22 type t = Not_Found | Exists of t array | Not_Exists of t array;;
23 let tree : t array Ancient.ancient = Ancient.get md 0
24 let tree = Ancient.follow tree
26 let word_exists word =
28 let tree = ref tree in
29 let len = String.length word in
30 for i = 0 to len-2; do
32 let c = Char.code c in
33 match (!tree).(c) with
34 | Not_Found -> raise Not_found
36 | Not_Exists tree' -> tree := tree'
39 (* Final character. *)
40 let c = word.[len-1] in
41 let c = Char.code c in
42 match (!tree).(c) with
44 | Not_Exists _ -> false
51 printf "Enter a word to check (q = quit program): ";
52 let word = read_line () in
54 printf "'%s' exists? %B\n%!" word (word_exists word);
62 (* Garbage collect - good way to check we haven't broken anything. *)
65 printf "Program finished.\n"