From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id LAA11132; Mon, 5 Nov 2001 11:18:19 +0100 (MET) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id LAA06738 for ; Mon, 5 Nov 2001 11:18:18 +0100 (MET) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.11.1/8.10.0) with ESMTP id fA5AI0H29686; Mon, 5 Nov 2001 11:18:01 +0100 (MET) Received: (from xleroy@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id LAA11216; Mon, 5 Nov 2001 11:18:00 +0100 (MET) Date: Mon, 5 Nov 2001 11:18:00 +0100 From: Xavier Leroy To: "Marcin 'Qrczak' Kowalczyk" Cc: caml-list@inria.fr Subject: Re: [Caml-list] Looking up exceptions in a dictionary Message-ID: <20011105111800.A10535@pauillac.inria.fr> References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 1.0i In-Reply-To: ; from qrczak@knm.org.pl on Mon, Nov 05, 2001 at 10:00:55AM +0000 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk > I haven't found the exception representation described. Is the > following description accurate? > > An exception is a block whose first field is a pointer used to > distinguish among exception constructors, and the rest are arguments. > The constructor pointer points to a one-field block which contains > a string pointer containing the constructor name. That's 100% accurate. > I think the dictionary can be constructed as I say below. Can it be > done in a better way? > > Since the real thing to be looked up is a pointer, and pointers don't > have a stable hash, the first step is a Hashtbl.t indexed by string > values - names of constructors, to quickly narrow the search. Names > are insufficient to reliably distinguish exceptions, so under each > name there is an association list holding actual constructor pointers > for all exceptions having a given name, looked up using List.assq. You can use the "functorial" interface to Hashtbl to indicate that you want keys to be compared by address and not by structure: module ExnHashtbl = Hashtbl.Make(struct type t = string let equal = (==) let hash = Hashtbl.hash end) - Xavier Leroy ------------------- Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr