Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] The invert Benchmark
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Mattias Waldau <mattias.waldau@a...>
Subject: RE: [Caml-list] The invert Benchmark
I followed his Python-code, which was much better than
his Ocaml-code.

/mattias

module Ord_string =
  struct
    type t = string
    let compare = compare
  end ;;


module S = Splay.Make(Ord_string) ;;

let tab_pattern = (Str.regexp_string "\t") in
let b = S.create () in
try
  while true do
    let line = input_line stdin in
    match Str.split tab_pattern line with
    | v :: k :: _ ->
	(try
	  S.set b k (v :: (S.find b k))
	with Not_found ->
	  S.set b k [v])
    | _ -> failwith "Not a pair"
  done
with End_of_file -> ();
  S.iter (fun k vs -> 
    let vs = List.sort compare vs in
    Printf.printf "%s\t%s\n" k (String.concat "\t" vs))
    b ;;




-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners