From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by yquem.inria.fr (Postfix) with ESMTP id 7BA5EBB83 for ; Tue, 15 Aug 2006 10:08:21 +0200 (CEST) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by nez-perce.inria.fr (8.13.6/8.13.6) with ESMTP id k7F88LaL002851 for ; Tue, 15 Aug 2006 10:08:21 +0200 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 KAA30228 for ; Tue, 15 Aug 2006 10:08:20 +0200 (MET DST) Received: from rouge.crans.org (rouge.crans.org [138.231.136.3]) by nez-perce.inria.fr (8.13.6/8.13.6) with ESMTP id k7F88J2G002848 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL) for ; Tue, 15 Aug 2006 10:08:20 +0200 Received: from localhost (rouge.adm.crans.org [138.231.144.3]) by rouge.crans.org (Postfix) with ESMTP id B1B6CBB80 for ; Tue, 15 Aug 2006 10:08:19 +0200 (CEST) Received: from rouge.crans.org ([138.231.144.3]) by localhost (rouge [138.231.144.3]) (amavisd-new, port 10024) with LMTP id 23811-02-26 for ; Tue, 15 Aug 2006 10:08:19 +0200 (CEST) Received: from [10.27.0.2] (korell.crans.org [138.231.142.254]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by rouge.crans.org (Postfix) with ESMTP id 72615BB61 for ; Tue, 15 Aug 2006 10:08:16 +0200 (CEST) Message-ID: <44E180EC.2010807@crans.org> Date: Tue, 15 Aug 2006 17:08:12 +0900 From: =?UTF-8?B?U3TDqXBoYW5lIEdsb25kdQ==?= User-Agent: Thunderbird 1.5.0.5 (X11/20060728) MIME-Version: 1.0 To: caml-list Subject: Re: [Caml-list] generic Hashtbl.to_array References: <26EB47FDD566A7469FC862DAF373792F017112AD@kaiserslautern1.lmsintl.com> In-Reply-To: X-Enigmail-Version: 0.94.0.0 OpenPGP: id=FCE03DAA Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Virus-Scanned: by amavisd-new-20030616-p10 (Debian) at crans.org X-Miltered: at nez-perce with ID 44E180F5.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at nez-perce with ID 44E180F3.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; hashtbl:01 hashtbl:01 rec:01 phane:98 phane:98 caml-list:01 let:03 let:03 assign:05 assign:05 fold:06 fold:06 stephane:07 generic:08 fun:08 X-Spam-Checker-Version: SpamAssassin 3.0.3 (2005-04-27) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.0.3 I know I am late. Tom a =C3=A9crit : > The dirtiest solution: >=20 > let to_array t =3D > let a =3D Array.make (Hashtbl.length t) (Obj.magic 0) in > ignore > (Hashtbl.fold (fun k v i -> a.(i) <- (k, v); i + 1) t 0) ; > a What about: let to_array h =3D let res =3D ref [||] in let rec assign =3D ref (fun i x -> res :=3D Array.make (Hashtbl.length h) x; !res.(i) <- x; assign :=3D Array.set !res) in ignore (Hashtbl.fold (fun k v i -> !assign i (k, v); i+1) h 0); !res;; Sorry if it has already been proposed (but I have not seen it). --=20 St=C3=A9phane Glondu