Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[oliver: Re: [Caml-list] Should be INSIDE STANDARD-LIB: Hashtbl.keys]
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: oliver@f...
Subject: [oliver: Re: [Caml-list] Should be INSIDE STANDARD-LIB: Hashtbl.keys]
----- Forwarded message from oliver -----

To: John Goerzen <>
Subject: Re: [Caml-list] Should be INSIDE STANDARD-LIB: Hashtbl.keys

On Fri, Apr 23, 2004 at 01:29:35PM -0500, John Goerzen wrote:
> On Fri, Apr 23, 2004 at 06:04:07PM +0200, Xavier Leroy wrote:
> > > Perhaps I'm all wrong, but when I have to get rid of repetitions in a 
> > > list, I first sort it in O(n log n), then remove the repetitions in O(n).
> > > Jean-Baptiste.
> > 
> > OK, fair enough :-)  The point I was trying to make (not very well, I
> > agree) is that "list without repetition" or "sorted list without
> > repetition" is often not the best data structure for the job.
> And a keys function need not necessarily avoid repetition anyway.

It ONLY makes sense to have a keys function that avoids repitition!

Anything else can be done with List.iter and List.fold
from the outside of the Hashtbl-module implementation!

But explicitly ONLY a keys-function that reports keys only ONCE
is a valid candidate for going into the standard lib!


P.S.: If you want to have the keys reported as often as there are
      bindings to them, you can use
         List.length (Hashtbl.find_all ht key)
      to get the number of bindings for the key.

      ( And then you can print several times that key_n is
        used inside the hash. IMHO this is called redundance. :) )

      This is above not much code and does not looks like a performance
      problem, when doing outside the Hash-implementation.

      But to retrieve a non-repitional keys-list, it is much more
      work to do and it also seems to be much more efficient implemented
      when done inside the Hashtbl-lib's code.
      What keys to use in the above code-snippet?

      Well, you could do it like this:

      Get the keys with Hashtbl.keys and for each of
      the keys use the above code snippet to get the
      number of entries and report this ONCE. :)
      (or many times, if you really want to ;-))

----- End forwarded message -----

To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: