From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id XAA00947; Thu, 18 Apr 2002 23:04:50 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id XAA00928 for caml-list@pauillac.inria.fr; Thu, 18 Apr 2002 23:04:49 +0200 (MET DST) Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id WAA05215 for ; Wed, 17 Apr 2002 22:28:47 +0200 (MET DST) Received: from isis.lip6.fr (isis.lip6.fr [132.227.60.2]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id g3HKSkX18233; Wed, 17 Apr 2002 22:28:46 +0200 (MET DST) Received: from poleia.lip6.fr (poleia.lip6.fr [132.227.201.28]) by isis.lip6.fr (8.12.2/jtpda-5.4+victor) with ESMTP id g3HKSkJb005349 ; Wed, 17 Apr 2002 22:28:46 +0200 X-pt: isis.lip6.fr Received: from singha (mail@singha.lip6.fr [132.227.204.18]) by poleia.lip6.fr (8.8.6/jtpda-5.2) with ESMTP id WAA01872 ; Wed, 17 Apr 2002 22:28:46 +0200 (MET DST) Received: from gauthier (helo=localhost) by singha with local-esmtp (Exim 3.35 #1 (Debian)) id 16xw2n-0008WU-00; Wed, 17 Apr 2002 22:28:45 +0200 Date: Wed, 17 Apr 2002 22:28:45 +0200 (CEST) From: Nadji.Gauthier@lip6.fr X-Sender: gauthier@singha.lip6.fr To: Xavier Leroy cc: Christophe TROESTLER , "O'Caml Mailing List" Subject: Re: [Caml-list] The invert Benchmark In-Reply-To: <20020417220454.A4322@pauillac.inria.fr> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk May I propose this program ? It uses a list of strings attached to a string in a hashtbl as proposed by Xavier Leroy, uses the very useful Pcre binding of Markus Mottl, doesn't need a join facility, and is slightly faster than the one in perl. Of course, any comment from the gurus are appreciated ... exception Impossible let process_input () = let h = Hashtbl.create 127 in let foldadd k d = try let y = Hashtbl.find h k in Hashtbl.replace h k (d::y) with _ -> Hashtbl.add h k [d] in try let r = Pcre.regexp "\t" in while true do let l = input_line stdin in (match Pcre.split ~rex:r l with [a;b] -> foldadd b a | _ -> failwith "bad input") done; raise Impossible with _ -> h let post_process h = let l = Hashtbl.fold (fun k d l -> (k, List.sort compare d)::l) h [] in List.sort (fun (a,_) (b, _) -> compare a b) l let pprint = List.iter (fun (k, d) -> Printf.printf "%s" k; List.iter (fun s -> Printf.printf "\t%s" s) d; Printf.printf "\n"; ) let _ = let h = process_input () in let l = post_process h in pprint l ------------------- 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