1 (* Read shared dictionary.
2 * $Id: test_ancient_dict_read.ml,v 1.1 2006-10-06 15:03:47 rich Exp $
8 let argv = Array.to_list Sys.argv
15 failwith (sprintf "usage: %s datafile"
19 let fd = openfile datafile [O_RDWR] 0o644 in
22 let arraysize = 256 (* one element for each character *)
24 type t = Not_Found | Exists of t array | Not_Exists of t array;;
25 let tree : t array Ancient.ancient = Ancient.get md 0
26 let tree = Ancient.follow tree
28 let word_exists word =
30 let tree = ref tree in
31 let len = String.length word in
32 for i = 0 to len-2; do
34 let c = Char.code c in
35 match (!tree).(c) with
36 | Not_Found -> raise Not_found
38 | Not_Exists tree' -> tree := tree'
41 (* Final character. *)
42 let c = word.[len-1] in
43 let c = Char.code c in
44 match (!tree).(c) with
46 | Not_Exists _ -> false
53 printf "Enter a word to check (q = quit program): ";
54 let word = read_line () in
56 printf "'%s' exists? %B\n%!" word (word_exists word);
64 (* Garbage collect - good way to check we haven't broken anything. *)
67 printf "Program finished.\n"