From: "Ludovic Coquelle" <lcoquelle@gmail.com>
To: "Brighten Godfrey" <pbg@cs.berkeley.edu>
Cc: "blue storm" <bluestorm.dylc@gmail.com>,
"Chris Kauffman" <kauffman@cs.umn.edu>,
peng.zang@gmail.com, caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Getting an element of a hashtable: simple ... or is it?
Date: Fri, 8 Aug 2008 23:46:41 +0800 [thread overview]
Message-ID: <d6c7b34d0808080846v512be854w2ef4962e814b57f5@mail.gmail.com> (raw)
In-Reply-To: <E6024C49-8B6D-43ED-B622-3D003CF81AEE@cs.berkeley.edu>
If the type of hashtbl key is known (if the hashtbl module has been
created by the functor),
the same code as initial can avoid a reference and use exception
propagation mechanism:
type key = MyHashtbl.key
exception One of key
let get_one h = try (MyHashtbl.iter (fun k _ -> raise (One k)) h;
raise Not_found) with One x -> x
Can't we have polymorphic exception? like
'a exception One of 'a
On Wed, Aug 6, 2008 at 5:47 AM, Brighten Godfrey <pbg@cs.berkeley.edu> wrote:
> On Aug 5, 2008, at 5:25 AM, blue storm wrote:
>>
>> With Extlib you can use :
>> let get_one hashtbl = Enum.peek (Hashtbl.enum hashtbl)
>> val get_one : ('a, 'b) Hashtbl.t -> ('a * 'b) option
>
> Ah, thanks.
>
>
> On Aug 5, 2008, at 6:21 AM, Peng Zang wrote:
>>
>> I think this is pretty standard. At least, I see it in ExtLib and I do it
>> on
>> a regular basis. In fact I have a function to do this for me so I don't
>> have
>> to do it over and over again. Eg.
>>
>> let get_one ht = mkGetOne Hashtbl.iter ht
>
> OK -- so you're saying ExtLib also implements it by breaking out of the loop
> with an exception. Interesting.
>
>
> On Aug 5, 2008, at 2:02 PM, Chris Kauffman wrote:
>>
>> I'm curious what sort of scenario calls for retrieving any single
>> element of a hash table (which is potentially empty?). It seems most
>> of the cases I deal with involve simply storing or iterating over all
>> the elements.
>
> Yes, nearly all cases are like that for me too. But in this case, I want to
> decompose a graph into its connected components, roughly according to the
> following pseudocode:
>
> unprocessed_nodes : (node_t, unit) Hashtbl.t = all nodes
> while unprocessed_nodes not empty do
> let one_node = choose any one node from unprocessed_nodes
> let cc = find_connected_component_containing one_node
> Do some sort of processing on cc. Then:
> for each node v in cc
> remove v from unprocessed_nodes
> done
>
> Thanks,
> ~Brighten Godfrey
>
> _______________________________________________
> Caml-list mailing list. Subscription management:
> http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
> Archives: http://caml.inria.fr
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
>
next prev parent reply other threads:[~2008-08-08 15:46 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
2008-08-05 12:25 ` blue storm
2008-08-05 21:47 ` Brighten Godfrey
2008-08-08 15:46 ` Ludovic Coquelle [this message]
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=d6c7b34d0808080846v512be854w2ef4962e814b57f5@mail.gmail.com \
--to=lcoquelle@gmail.com \
--cc=bluestorm.dylc@gmail.com \
--cc=caml-list@yquem.inria.fr \
--cc=kauffman@cs.umn.edu \
--cc=pbg@cs.berkeley.edu \
--cc=peng.zang@gmail.com \
/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