Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: oliver@first.in-berlin.de (Oliver Bandel)
To: caml-list@inria.fr
Subject: [oliver: Re: [Caml-list] Should be INSIDE STANDARD-LIB: Hashtbl.keys]
Date: Fri, 23 Apr 2004 22:10:39 +0200	[thread overview]
Message-ID: <20040423201039.GH271@first.in-berlin.de> (raw)

----- Forwarded message from oliver -----

To: Richard Jones <rich@annexia.org>
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


             reply	other threads:[~2004-04-23 20:20 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-04-23 20:10 Oliver Bandel [this message]
2004-04-24  7:30 ` Martin Jambon
  -- strict thread matches above, loose matches on Subject: below --
2004-04-23 20:10 Oliver Bandel
2004-04-23 20:09 Oliver Bandel
2004-04-23 20:09 Oliver Bandel
2004-04-23 20:09 Oliver Bandel
2004-04-24  3:00 ` skaller
2004-04-24  4:46   ` Jon Harrop
2004-04-24 10:39     ` Oliver Bandel
2004-04-25 18:54     ` Marcin 'Qrczak' Kowalczyk
2004-04-25 20:06       ` Jon Harrop
2004-04-26 10:14         ` Richard Jones
2004-04-26 17:13           ` Jon Harrop
2004-04-24  6:42   ` Basile STARYNKEVITCH
2004-04-24 19:12     ` skaller
2004-04-24  8:56   ` Oliver Bandel

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=20040423201039.GH271@first.in-berlin.de \
    --to=oliver@first.in-berlin.de \
    --cc=caml-list@inria.fr \
    /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