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=0.0 required=5.0 tests=AWL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by yquem.inria.fr (Postfix) with ESMTP id 07DA0BC69 for ; Tue, 2 Oct 2007 13:07:35 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAADPDAUfAXQImk2dsb2JhbACONgEBAQEHBAYHIA X-IronPort-AV: E=Sophos;i="4.21,220,1188770400"; d="scan'208";a="17185819" Received: from discorde.inria.fr ([192.93.2.38]) by mail4-smtp-sop.national.inria.fr with ESMTP; 02 Oct 2007 13:07:34 +0200 Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id l92B7Xfj022355 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=OK) for ; Tue, 2 Oct 2007 13:07:34 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAAKvDAUfLENaMn2dsb2JhbACONgEBAQEHBAYHIA X-IronPort-AV: E=Sophos;i="4.21,220,1188770400"; d="scan'208";a="3646678" Received: from ipmail01.adl2.internode.on.net ([203.16.214.140]) by mail3-smtp-sop.national.inria.fr with ESMTP; 02 Oct 2007 13:07:19 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAAFzBAUd5LHvc/2dsb2JhbAAM X-IronPort-AV: E=Sophos;i="4.21,220,1188743400"; d="scan'208";a="202519011" Received: from ppp121-44-123-220.lns10.syd6.internode.on.net (HELO [192.168.1.201]) ([121.44.123.220]) by ipmail01.adl2.internode.on.net with ESMTP; 02 Oct 2007 20:37:13 +0930 Subject: Re: [Caml-list] [ANN] Weaktbl: a weak hash table library From: skaller To: Zheng Li Cc: caml-list@inria.fr In-Reply-To: <87641q3ysp.fsf@pps.jussieu.fr> References: <87641q3ysp.fsf@pps.jussieu.fr> Content-Type: text/plain Date: Tue, 02 Oct 2007 21:07:11 +1000 Message-Id: <1191323231.28954.27.camel@rosella.wigram> Mime-Version: 1.0 X-Mailer: Evolution 2.10.1 Content-Transfer-Encoding: 7bit X-Miltered: at discorde with ID 47022675.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; hash:01 0200,:01 hash:01 ocaml:01 variants:01 pointer:01 unreferenced:01 node:01 ocaml:01 pointers:01 pointers:01 functor:01 hashtbl:01 sub-module:01 hashtbl:01 On Tue, 2007-10-02 at 06:50 +0200, Zheng Li wrote: > Hi, > Weaktbl is yet another weak hash table library for OCaml. Its main features > include: > > * Both keys and associated values are weakly stored. A binding exists until > the key is no longer referenced anywhere I'm a bit confused what it means.. If the key is weak, it is useless except for terms, i.e. variants or records of another data structure, where you are placing a pointer in the table as a key. You can't put values (int, float, etc) in the key field, because they're immediately unreferenced. So you could use this thing as a cache, where for example you have a tree and calculate some property of each node, and cache it in the table. The problem is .. physical comparison in Ocaml is unstable, so you cannot hash pointers using polymorphic hash, but pointers are the only kind that persist. So I have to conclude you must use the Weaktbl with a functor, instantiating the hash function to something which does a computation on the value, and this claim: * The interface is fully compatible with the standard Hashtbl library instead of the hash sub-module of the Weak library, so basically you can also use it as an alternative of the standard Hashtbl is misleading: I use Hashtbl extensively, but ALL my uses are using the polymorphic interface with polymorphic hash, so actually none of them will work with Weaktbl, which is a pity. Can you confirm or deny this analysis? A weakly keyed table would be cool for term cache, since it saves worrying about removing dangling references. -- John Skaller Felix, successor to C++: http://felix.sf.net