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 WAA06334; Fri, 23 Apr 2004 22:20:27 +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 WAA05190 for ; Fri, 23 Apr 2004 22:20:24 +0200 (MET DST) Received: from hirsch.in-berlin.de (hirsch.in-berlin.de [192.109.42.6]) by nez-perce.inria.fr (8.12.10/8.12.10) with ESMTP id i3NKKNjq021072 for ; Fri, 23 Apr 2004 22:20:23 +0200 X-Envelope-From: oliver@first.in-berlin.de X-Envelope-To: Received: from hirsch.in-berlin.de (localhost [127.0.0.1]) by hirsch.in-berlin.de (8.12.11/8.12.11/Debian-3) with ESMTP id i3NKK1Ie012403 for ; Fri, 23 Apr 2004 22:20:22 +0200 Received: from first.UUCP (uucp@localhost) by hirsch.in-berlin.de (8.12.11/8.12.11/Debian-3) with UUCP id i3NKF4i8012021 for inria.fr!caml-list; Fri, 23 Apr 2004 22:15:04 +0200 Received: by first.in-berlin.de via sendmail from stdin id (Debian Smail3.2.0.114) Fri, 23 Apr 2004 22:10:39 +0200 (CEST) From: oliver@first.in-berlin.de (Oliver Bandel) Date: Fri, 23 Apr 2004 22:10:39 +0200 To: caml-list@inria.fr Subject: [oliver: Re: [Caml-list] Should be INSIDE STANDARD-LIB: Hashtbl.keys] Message-ID: <20040423201039.GH271@first.in-berlin.de> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline User-Agent: Mutt/1.3.28i 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; oliver:01 in-berlin:01 oliver:01 bandel:01 caml-list:01 hashtbl:01 caml-list:01 hashtbl:01 2004:99 2004:99 bandel:01 hash:01 hashtable:01 implemented:01 hash:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk ----- Forwarded message from oliver ----- To: Richard Jones Subject: Re: [Caml-list] Should be INSIDE STANDARD-LIB: Hashtbl.keys On Wed, Apr 21, 2004 at 09:39:47AM +0100, Richard Jones wrote: > On Wed, Apr 21, 2004 at 03:19:04AM +0200, Oliver Bandel wrote: > > I think a good addition to the Hashtbl-module > > would be a function, that gives back a list of keys > > that are in the hash. > > And also a 'values' function which returns all the values. Well, ok, here is a problem then: for a keys-function it makes sense to only give back them once, so that means multiple occurrences (because of more than one binding) of a key will given back only once. But to have a values-function, it is not clear, if they should be reported once or as often as they appear. This is individually different, depending on what you want to get. You can use Hashtbl.iter and Hashtbl.fold for creating each version of them. But it does not makes sense to have a keys-function that reports keys as often as there are bindings to it in the hashtable, because you easily can get all bindings of it with find_all and the the current binding with find. So, wheras the keys function makes only sense to be implemented in a certain way (report each key only once), there are at least two kinds of a value-function possible. So, IMHO this is a reason, why a Hashtbl.values function does not necessarily makes sense in the standard lib itself! > > Both functions, BTW, are easily written using the Hashtbl's fold > function; but they ought to be part of the standard library. When you want to report each key only once, you need a temporarily hash to sort out multiple stuff. This, because the fold-function reports EACH binding (and it good that it does it), and therefore multiple bindings to a key will occur more than once. The function has to sort them out. I'm shure it's more efficient to implement that inside the hashtbl-module. (I've not looked into the sources, but suppose that it will be more performant, when a Hashtbl.keys will be implemented inside the Hashtbl-module.) WHICH values function would make more sense than the other, and why should it be used instead the other one? (Or maybe it makes sense to have a boolean parameter to decide, which of both values-function should be used?!) Ciao, Oliver ----- End forwarded message ----- ------------------- 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