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 TAA09464; Tue, 18 Feb 2003 19:00:06 +0100 (MET) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id TAA09335 for ; Tue, 18 Feb 2003 19:00:05 +0100 (MET) Received: from hirsch.in-berlin.de (hirsch.in-berlin.de [192.109.42.6]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id h1II04T24233 for ; Tue, 18 Feb 2003 19:00:04 +0100 (MET) Received: from hirsch.in-berlin.de (localhost [127.0.0.1]) by hirsch.in-berlin.de (8.12.1/8.12.1/Debian -2) with ESMTP id h1II03Wg002315 (version=TLSv1/SSLv3 cipher=EDH-RSA-DES-CBC3-SHA bits=168 verify=NOT) for ; Tue, 18 Feb 2003 19:00:03 +0100 Received: from first.UUCP (uucp@localhost) by hirsch.in-berlin.de (8.12.1/8.12.1/Debian -2) with UUCP id h1II01iU002307 for inria.fr!caml-list; Tue, 18 Feb 2003 19:00:01 +0100 X-Envelope-From: oliver@first.in-berlin.de X-Envelope-To: inria.fr!caml-list Received: by first.in-berlin.de via sendmail from stdin id (Debian Smail3.2.0.114) Tue, 18 Feb 2003 19:03:42 +0100 (CET) From: oliver@first.in-berlin.de (Oliver Bandel) Date: Tue, 18 Feb 2003 19:03:41 +0100 To: caml-list@inria.fr Subject: [Caml-list] Hashtbl.keys Message-ID: <20030218180341.GA267@first.in-berlin.de> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.3.28i Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Hello, the Hastbl-module is a fine thing. To have functions like Hastbl.find_all is convenient for a lot of problems, which would be not so easy to solve, when only hastbl.find would be in that library. Well... and Hashtbl.iter seems to work on *all* antries in the *whole* hash-table, that is: A Hastbl.find_all for each of the keys in that table. At least it is, how I understand the decription in the manual. Well, but Hashtbl.iter is used for unit-functions. But I need bool-functions, and maybe other tyopes too. So, if I want to apply a function with return-type different then unit, I have to use a second Hash-table to remember, which keys I have inside my main hastbl (using hashtbl.replace). Or I may have to use Hastbl.replace instead of Hastbl.add in my main Hashtbl, where my new data-entry is a list of the old entry with the new entry appended. But that all would be easier, if there would be a function Hashtbl.keys, which give back all keys of a hashtbl. So, Hashtbl.keys would have the following type: ('a, 'b) t -> key 'a list With that function, I could use things like ################################################## let myhash = Hashtbl.create 100000;; Hashtbl.add myhash "k1" "hellO";; Hashtbl.add myhash "k2" "xxx";; Hashtbl.add myhash "k3" "iuzwiuezriuw";; Hashtbl.add myhash "k1" "la la la";; Hashtbl.add myhash "k1" "shoo bi doo";; Hashtbl.find_all (Hashtbl.keys myhash) (* But the later function could also be named Hashtbl.values and this one may makes sense in the Hashtbl-module too, but a Hashtbl.keys would be much more necessary! let all_values_of_a_hash hash = Hashtbl.find_all(Hashtbl.keys hash) But I think, the implementation could be more efficient, when doing the latter function directly in the underwood of the Hashtbl-module itself. *) ################################################## Wouldn't it a good idea to add such a function "get all keys of a hashtable" into the hashtbl-module? (And a "get all values..." to?) Would that be hard work, or can it be added easily? What workaround makes sense until such a funtion will be available? Should I use a second hash to save all keys of the main-hash? Or what is a good way to solve this problem? Ciao, Oliver P.S.: For a possible Ocaml-advocacy discussion I want to drop that note here: I can't believe that programming such problems in perl should be easier than in Ocaml... in perl there is a function "keys" as well as a function "values" for working on hash-tables. ------------------- 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