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 EAA25175; Sat, 20 Mar 2004 04:13:44 +0100 (MET) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f 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 EAA25947 for ; Sat, 20 Mar 2004 04:13:42 +0100 (MET) Received: from mwinf0601.wanadoo.fr (smtp6.wanadoo.fr [193.252.22.25]) by nez-perce.inria.fr (8.12.10/8.12.10) with ESMTP id i2K3ECKW013170 for ; Sat, 20 Mar 2004 04:14:12 +0100 Received: from vanicat.homelinux.org (ca-bordeaux-4-120.w80-8.abo.wanadoo.fr [80.8.76.120]) by mwinf0601.wanadoo.fr (SMTP Server) with ESMTP id 49D1434000E6 for ; Sat, 20 Mar 2004 04:13:41 +0100 (CET) Received: from moi by vanicat.homelinux.org with local (Exim 4.30) id 1B4Wvd-0008Ax-KQ for caml-list@inria.fr; Sat, 20 Mar 2004 04:13:41 +0100 To: caml-list@inria.fr Subject: Re: [Caml-list] Question about string ref and Hashtbl. References: <20040320000558.71279.qmail@web40311.mail.yahoo.com> From: Remi Vanicat Mail-Copy-To: never Date: Sat, 20 Mar 2004 04:13:41 +0100 In-Reply-To: <20040320000558.71279.qmail@web40311.mail.yahoo.com> (Bob Bailey's message of "Fri, 19 Mar 2004 16:05:58 -0800 (PST)") Message-ID: <87vfl0xlay.dlv@vanicat.homelinux.org> User-Agent: Gnus/5.1006 (Gnus v5.10.6) Emacs/21.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-15 Content-Transfer-Encoding: 8bit X-Miltered: at nez-perce 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 val:01 val:01 bool:01 bool:01 dict:01 dict:01 equality:01 writes:01 remi:01 remi:01 vanicat:01 vanicat:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk X-Status: X-Keywords: X-UID: 256 Bob Bailey writes: > 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. It is a strange thing that the key and value of a location of the Hashtbl are really the same thing. Mmm, i believe that I've understood what you want to do, and if you don't want to modify the value associated with a key, then you don't need to use the type ref. the type ref have one and only one interest: you can modify it. > 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? Well if let a = Hashtbl.find dict "a" and let b = Hashtbl.find dict "a" and if the Hashtbl have not been modified between the two call, then a==b. and if a==b then !a == !b. but beware : # let st = "test";; val st : string = "test" # let a = ref st;; val a : string ref = {contents = "test"} # let b = ref st;; val b : string ref = {contents = "test"} # a == b;; - : bool = false # !a == !b;; - : bool = true > Also, would a==b be a faster comparason in this case? No, == test the equality of the pointer to the value, so it take the same time for all type. By the way : # "test" == "test";; - : bool = false May be you want to use =, but with (=) then (a = b) is equal to (!a = !b) for all reference a and b, and the evaluation time are more or less the same (may be (!a = !b) is faster, but I won't bet on it). -- Rémi Vanicat ------------------- 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