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 LAA21204; Wed, 21 Apr 2004 11:14:10 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f 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 LAA20712 for ; Wed, 21 Apr 2004 11:14:09 +0200 (MET DST) Received: from out2.smtp.messagingengine.com (out2.smtp.messagingengine.com [66.111.4.26]) by nez-perce.inria.fr (8.12.10/8.12.10) with ESMTP id i3L9E7jq001029 for ; Wed, 21 Apr 2004 11:14:08 +0200 X-Sasl-enc: 2XvOTJeqRxwuHuuRun2WUw 1082535250 Received: from [192.168.1.100] (unknown [218.81.122.1]) by mail.messagingengine.com (Postfix) with ESMTP id 5C902A7B6B1; Wed, 21 Apr 2004 04:14:08 -0400 (EDT) Date: Wed, 21 Apr 2004 17:13:59 +0800 (HKT) From: Martin Jambon X-X-Sender: martin@localhost To: Oliver Bandel Cc: caml-list@inria.fr Subject: Re: [Caml-list] Should be INSIDE STANDARD-LIB: Hashtbl.keys In-Reply-To: <20040421011904.GA1411@first.in-berlin.de> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Miltered: at nez-perce by Joe's j-chkmail ("http://j-chkmail.ensmp.fr")! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 hashtbl:01 oliver:01 bandel:01 hashtbl:01 hash:01 hash:01 accu:01 accu:01 bindings:01 exists:01 jambon:02 jambon:02 wrote:03 data:03 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Wed, 21 Apr 2004, Oliver Bandel wrote: > Hashtbl.keys returns a list of all keys of the > hash "hash", that exists and therefore have values bound > to it. If a key has several bindings, it will occur only > once in this list. For that purpose, it is possible instead of a (key, data) Hashtbl.t to use a (key, data list ref) Hashtbl.t: let add tbl key data = let r = try Hashtbl.find tbl key with Not_found -> let r = ref [] in Hashtbl.add tbl key r; r in r := data :: !r let fold f tbl init = Hashtbl.fold (fun key r accu -> f key (List.hd !r) accu) tbl init let keys tbl = fold (fun key _ accu -> key :: accu) tbl [] Martin ------------------- 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