caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Brighten Godfrey <pbg@cs.berkeley.edu>
To: Richard Jones <rich@annexia.org>
Cc: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Getting an element of a hashtable: simple ... or is it?
Date: Tue, 5 Aug 2008 05:26:27 -0700	[thread overview]
Message-ID: <0A438E08-42BB-4CC9-889E-7AAF90323CC8@cs.berkeley.edu> (raw)
In-Reply-To: <20080805121600.GB25452@annexia.org>

On Aug 5, 2008, at 5:16 AM, Richard Jones wrote:

> On Tue, Aug 05, 2008 at 05:05:46AM -0700, Brighten Godfrey wrote:
>> Suppose you are given a data structure, and you want to retrive one
>> element -- any one element.  Sounds simple... and it is, if you have
>> a list (List.hd list) or an array (arr.(0)).  But how about a
>> hashtable, if we don't know a priori any of the keys in the  
>> hashtable?
>
> It's very unclear what you're trying to do.

I think you've interpreted me correctly.  I want a function that,  
given a hashtable, returns any element of the hashtable (assuming  
it's not empty).  This is the same as the function "choose" in the  
Set module.

> For List and Array those methods won't work if the data structure is
> empty, but I guess that's expected.  Hashtbl isn't designed with the
> "get an/any element" usage in mind -- your loop/exception is probably
> the best way given that you've made a poor choice of data structure in
> the first place.  But this still comes back to the question, what are
> you trying to do?

A hashtable is not a poor choice of a data structure, because this  
"choose" functionality is not the only requirement for my data  
structure: I also want constant time search.  OCaml's Set data  
structure has O(log n)-time search.

Thanks,
~Brighten


  reply	other threads:[~2008-08-05 12:33 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-08-05 12:05 Brighten Godfrey
2008-08-05 12:16 ` [Caml-list] " Richard Jones
2008-08-05 12:26   ` Brighten Godfrey [this message]
2008-08-05 12:25 ` blue storm
2008-08-05 21:47   ` Brighten Godfrey
2008-08-08 15:46     ` Ludovic Coquelle
2008-08-08 16:01       ` Peng Zang
2008-08-05 13:21 ` Peng Zang
2008-08-05 21:02   ` Chris Kauffman

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=0A438E08-42BB-4CC9-889E-7AAF90323CC8@cs.berkeley.edu \
    --to=pbg@cs.berkeley.edu \
    --cc=caml-list@yquem.inria.fr \
    --cc=rich@annexia.org \
    /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;
as well as URLs for NNTP newsgroup(s).