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 BAA18596; Sat, 20 Mar 2004 01:06:01 +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 BAA18442 for ; Sat, 20 Mar 2004 01:06:00 +0100 (MET) X-SPAM-Warning: Sending machine is listed in blackholes.five-ten-sg.com Received: from web40311.mail.yahoo.com (web40311.mail.yahoo.com [66.218.78.90]) by concorde.inria.fr (8.12.10/8.12.10) with SMTP id i2K05xHd008540 for ; Sat, 20 Mar 2004 01:05:59 +0100 Message-ID: <20040320000558.71279.qmail@web40311.mail.yahoo.com> Received: from [24.153.223.97] by web40311.mail.yahoo.com via HTTP; Fri, 19 Mar 2004 16:05:58 PST Date: Fri, 19 Mar 2004 16:05:58 -0800 (PST) From: Bob Bailey Subject: Re: [Caml-list] Question about string ref and Hashtbl. To: Caml List In-Reply-To: <20040320.075814.105434271.yoriyuki@mbg.ocn.ne.jp> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Miltered: at concorde by Joe's j-chkmail ("http://j-chkmail.ensmp.fr")! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 hashtbl:01 hashtbl:01 yamagata:01 yoriyuki:01 yoriyuki:01 caml-list:01 2004:99 struct:01 hash:01 hash:01 yamagata:01 dict:01 dict:01 mutable:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk X-Status: X-Keywords: X-UID: 254 That's an interesting idea. SO the key string and the value string will really point to the same location in memory. So if I did (string,string ref) Hashtbl.t, then the string ref would be a pointer to the key string. Would that allow me to compare two string ref variables together? Would the comparason of the locations of the strings mean I wouldn't have to do a full string compare? so in my module type index = string ref type dict = (string,index) Hashtbl.t So in the case of let a = Hashtbl.find dict "a" let b = Hashtbl.find dict "a" would a==b be the same as !a == !b? Also, would a==b be a faster comparason in this case? thanx bob --- Yamagata Yoriyuki wrote: > From: Bob Bailey > Subject: [Caml-list] Question about string ref and Hashtbl. > Date: Fri, 19 Mar 2004 14:03:23 -0800 (PST) > > > type t = > > { > > mutable last:int; > > names: (string,int) Hashtbl.t; > > indexes:(int,string ref) Hashtbl.t; > > } > > If I were you, I would define the dictonary as > > type t = (string, string) Hashtbl.t > > and add function as > > let add dict str = > try > Hashtbl.find dict str > with Not_found -> > Hashtbl.add dict str str > > In addition, if some of your strings become unused during exectuion, > I would recommend useing WeakHash. > > module Dict = Weak.Make (struct > type t = string > let equal = (=) > let hash = Hashtbl.hash > end) > > and use Dict as Hasthtbl. In this way, if a string becomes unused, > it is GC-ed and removed from the dict. > > -- > Yamagata Yoriyuki __________________________________ Do you Yahoo!? Yahoo! Mail - More reliable, more storage, less spam http://mail.yahoo.com ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners