Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Hal Daume III <hdaume@ISI.EDU>
To: Oliver Bandel <oliver@first.in-berlin.de>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Hashtbl.keys
Date: Tue, 18 Feb 2003 10:13:17 -0800 (PST)	[thread overview]
Message-ID: <Pine.GSO.4.21.0302181009450.2060-100000@moussor.isi.edu> (raw)
In-Reply-To: <20030218180341.GA267@first.in-berlin.de>

I actually find the OCaml hash table implementation to be very lacking and
have thus written my own, which probably isn't as efficient.  Nevertheless
you can find it at http://www.isi.edu/~hdaume/hashtable.ml.  It requires
garray.ml(i) found at the same location.  It doesn't have a keys function,
but such a thing is easy to write:

> let get_keys = fold (fun l k _ -> k :: l) []

You could probably do it marginally more efficiently by looking at the
actual implementaiton.

The reason I wrote this not-incredibly hash table implementation is
essentially because I needed a map function for hash tables and there was
no way to implement that on top of the current HashTbl interface.  I would
be more than happy to go back to the standard interface if it supported
maps.

--
Hal Daume III

 "Computer science is no more about computers    | hdaume@isi.edu
  than astronomy is about telescopes." -Dijkstra | www.isi.edu/~hdaume

On Tue, 18 Feb 2003, Oliver Bandel wrote:

> 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
> 

-------------------
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


  reply	other threads:[~2003-02-18 18:13 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-02-18 18:03 Oliver Bandel
2003-02-18 18:13 ` Hal Daume III [this message]
2003-02-20  9:43 ` Xavier Leroy
2003-02-20 16:54   ` [Caml-list] OCaml standard library improvement Stefano Zacchiroli
2003-02-21 13:47     ` Nicolas George
2003-02-22 14:09       ` Stefano Zacchiroli
2003-02-23 18:33         ` Alessandro Baretta
2003-02-21 13:53     ` fva
2003-02-21 16:18       ` Amit Dubey
2003-02-21 17:10         ` Brian Hurt
2003-02-21 17:23           ` Nicolas George
2003-02-21 18:01             ` Brian Hurt
2003-02-21 18:57               ` Chris Hecker
2003-02-21 19:28                 ` Brian Hurt
2003-02-22 15:52             ` John Max Skaller
2003-02-21 17:32         ` Maxence Guesdon
2003-02-24  1:21       ` Nicolas Cannasse
2003-02-24  1:45         ` Chris Hecker
2003-02-24  2:46           ` Brian Hurt
2003-02-24  7:42             ` Stefano Zacchiroli
2003-02-24 10:18             ` fva
2003-02-24 11:03             ` Amit Dubey
2003-02-24 12:56               ` John Max Skaller
2003-02-24 13:06                 ` Lauri Alanko
2003-02-24 13:08                 ` Sven Luther
2003-02-24 14:05                   ` [Caml-list] Library Discussion Followups Amit Dubey
2003-02-25  5:49                   ` [Caml-list] OCaml standard library improvement John Max Skaller
2003-02-25  8:29                     ` Xavier Leroy
2003-02-24 16:50                 ` Benjamin C. Pierce
2003-02-24 17:28                   ` brogoff
2003-02-25 18:08                   ` Diego Olivier Fernandez Pons
2003-02-26  7:47                     ` Jean-Christophe Filliatre
2003-02-25 10:47     ` [Caml-list] OCaml standard library _improvement_ NOT a new library! Stefano Zacchiroli
2003-02-25 21:43       ` Alessandro Baretta
2003-02-26  9:42         ` Stefano Zacchiroli
2003-02-21  6:40   ` [Caml-list] Hashtbl.keys Alex Cowie

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Pine.GSO.4.21.0302181009450.2060-100000@moussor.isi.edu \
    --to=hdaume@isi.edu \
    --cc=caml-list@inria.fr \
    --cc=oliver@first.in-berlin.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox