From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: * X-Spam-Status: No, score=1.1 required=5.0 tests=AWL,SPF_SOFTFAIL autolearn=disabled version=3.1.3 Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by yquem.inria.fr (Postfix) with ESMTP id 1112ABBAF for ; Tue, 5 Aug 2008 23:47:50 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AloBAHBnmEip5TxXo2dsb2JhbACRNgEBAQEBAQcFCAcRnQg X-IronPort-AV: E=Sophos;i="4.31,312,1215381600"; d="scan'208";a="15748112" Received: from gateway0.eecs.berkeley.edu ([169.229.60.87]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-SHA; 05 Aug 2008 23:47:49 +0200 Received: from [10.0.1.5] (136-152-208-62.VPN.Berkeley.EDU [136.152.208.62]) (authenticated bits=0) by gateway0.EECS.Berkeley.EDU (8.14.3/8.13.5) with ESMTP id m75Llbho008092 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=NOT); Tue, 5 Aug 2008 14:47:42 -0700 (PDT) In-Reply-To: <527cf6bc0808050525x5d574e5ek4b7acbc4e114307e@mail.gmail.com> References: <94C5D65F-7CA4-48FF-B4AA-E88E82F6C8E1@cs.berkeley.edu> <527cf6bc0808050525x5d574e5ek4b7acbc4e114307e@mail.gmail.com> Mime-Version: 1.0 (Apple Message framework v753.1) Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed Message-Id: Cc: caml-list@yquem.inria.fr Content-Transfer-Encoding: 7bit From: Brighten Godfrey Subject: Re: [Caml-list] Getting an element of a hashtable: simple ... or is it? Date: Tue, 5 Aug 2008 14:47:37 -0700 To: blue storm , Chris Kauffman , peng.zang@gmail.com X-Mailer: Apple Mail (2.753.1) X-Spam: no; 0.00; hashtable:01 hashtbl:01 enum:01 hashtbl:01 enum:01 val:01 iter:01 implements:01 hash:01 iterating:01 pseudocode:01 nodes:01 node:01 nodes:01 node:01 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