(* * test.ml -- Testing the functions of splay_set * * Ling Li, Caltech * Jan. 16, 2001 *) open Printf (* String module *) module String = struct type elt = string let compare x y = if x < y then -1 else if x = y then 0 else 1 end (* Splay tree with String as the key type *) module StringSet = Splay_set.MakeSplaySet (String) (* main loop: read commands from console then execute them *) let rec main () = let set = StringSet.create () in try while true do output_string stdout "splay> "; flush stdout; let line = input_line stdin in match Str.bounded_split (Str.regexp "[ \t]+") line 2 with | ["mem"; s] -> printf "mem %s: %b\n" s (StringSet.mem s set) | ["insert"; s] -> printf "insert %s\n" s; let _ = StringSet.insert s set in () | ["delete"; s] -> printf "delete %s\n" s; let _ = StringSet.delete s set in () | ["help"] | ["?"] -> printf "Commands are: mem, insert, delete, help, bye\n" | ["bye"] | ["quit"] -> raise End_of_file | com :: _ -> fprintf stderr "Bad command %s\n" com; flush stderr | [] -> () done with End_of_file -> printf "Bye bye!\n" let _ = main ()