From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id 128FCBB81 for ; Wed, 12 Oct 2005 10:02:54 +0200 (CEST) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id j9C82r97026350 for ; Wed, 12 Oct 2005 10:02:53 +0200 Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id KAA27715 for ; Wed, 12 Oct 2005 10:02:53 +0200 (MET DST) Received: from [128.93.11.95] (estephe.inria.fr [128.93.11.95]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id j9C82nSf025305 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Wed, 12 Oct 2005 10:02:49 +0200 Message-ID: <434CC328.7060803@inria.fr> Date: Wed, 12 Oct 2005 10:02:48 +0200 From: Xavier Leroy User-Agent: Mozilla Thunderbird 1.0.2 (X11/20050322) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Thomas Fischbacher Cc: Christian Lindig , Caml List Subject: Re: [Caml-list] EQ hash tables? References: <14893115.1128951765427.JavaMail.www@wwinf1521> In-Reply-To: X-Enigmail-Version: 0.90.0.0 X-Enigmail-Supports: pgp-inline, pgp-mime Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Miltered: at concorde with ID 434CC32D.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at nez-perce with ID 434CC329.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 hash:01 ocaml:01 hash:01 hashtbl:01 struct:01 hashtbl:01 semantics:01 structurally:01 functorial:02 slightly:02 module:03 let:03 let:03 long:04 X-Spam-Checker-Version: SpamAssassin 3.0.3 (2005-04-27) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.0.3 > Actually, this brings me to a question I wanted to ask for a long time: > while I never used this so far, I just assumed that OCaml does provide > hash tables where keys are compared w.r.t. "being the same" ('==' , that > is), rather than only hash tables where keys are compared for "being > equal" (say, '='). Easily definable using the functorial interface to hash tables: module MyEqHashTable = Hashtbl.Make(struct type t = my_type_for_keys let equal = (==) let hash = Hashtbl.hash end) > Of course, "EQ hash tables" have to be treated in a slightly special way > when talking about stop© GCing. No, not "of course". You're thinking of using the address of a memory block as its hash value. This indeed requires GC support. But you can get the semantics you want (keys compared by reference) while still computing the hash code structurally. This is what the code snippet above does. - Xavier Leroy