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 XAA11461; Fri, 19 Mar 2004 23:03:26 +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 XAA11167 for ; Fri, 19 Mar 2004 23:03:25 +0100 (MET) X-SPAM-Warning: Sending machine is listed in blackholes.five-ten-sg.com Received: from web40306.mail.yahoo.com (web40306.mail.yahoo.com [66.218.78.85]) by concorde.inria.fr (8.12.10/8.12.10) with SMTP id i2JM3OHd028705 for ; Fri, 19 Mar 2004 23:03:24 +0100 Message-ID: <20040319220323.49366.qmail@web40306.mail.yahoo.com> Received: from [144.189.241.170] by web40306.mail.yahoo.com via HTTP; Fri, 19 Mar 2004 14:03:23 PST Date: Fri, 19 Mar 2004 14:03:23 -0800 (PST) From: Bob Bailey Subject: [Caml-list] Question about string ref and Hashtbl. To: Caml List 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; hashtbl:01 hashtbl:01 ocamldebug:01 inthashtbl:01 dict:01 dict:01 mutable:01 int:01 int:01 string:03 string:03 btw:03 behavior:03 addresses:96 let:04 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk X-Status: X-Keywords: X-UID: 247 Sorry for the last mistake... sent by accident. I have created the following structure type t = { mutable last:int; names: (string,int) Hashtbl.t; indexes:(int,string ref) Hashtbl.t; } I am trying to only store the string once in memory. This will allow me to store the index of the string in the dictionary instead of copying the string all over memory. The add function is let add dict str = try Hashtbl.find dict.names str with Not_found -> ( Hashtbl.add dict.names str dict.last; Hashtbl.add dict.indexes dict.last (ref str); dict.last <- dict.last +1; dict.last - 1 ) So with this code can I expect the correct behavior. BTW, I have used ocamldebug to try to examine the addresses of the strings to see if the reference points to the same string in the hashtbl key. Also, I know that I can specialize the t.indexes with an IntHashtbl. I have actually done that but to simplify the example I have left it out. Any advice would be appreciated. bob __________________________________ 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