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 MAA18000; Mon, 26 Jan 2004 12:17:02 +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 MAA18328 for ; Mon, 26 Jan 2004 12:17:00 +0100 (MET) Received: from postfix3-2.free.fr (postfix3-2.free.fr [213.228.0.169]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id i0QBH0P07342 for ; Mon, 26 Jan 2004 12:17:00 +0100 (MET) Received: from warp (lns-th2-5f-81-56-197-80.adsl.proxad.net [81.56.197.80]) by postfix3-2.free.fr (Postfix) with SMTP id 8193DC031; Mon, 26 Jan 2004 12:16:59 +0100 (CET) Message-ID: <006901c3e3fe$ad44ee40$ef01a8c0@warp> From: "Nicolas Cannasse" To: "Pietro Abate" , "ocaml ml" References: <20040126104345.GA3978@pulp.anu.edu.au> Subject: Re: [Caml-list] sharing problem ... Date: Mon, 26 Jan 2004 12:22:25 +0100 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 X-Loop: caml-list@inria.fr X-Spam: no; 0.00; cannasse:01 warplayer:01 caml-list:01 hashtbl:01 clone:01 hashtbl:01 cannasse:01 compiler:01 ocaml:01 ocaml:01 equality:01 nicolas:01 nicolas:01 int:01 polymorphic:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk > Hi all, > I'm trying to implement a (string * set) hashtbl > where some element (set) should be shared between different > objects. > the main point is that when I clone an object I want to duplicate > some sets and shared others (sticky sets) > > I tried to achieve this result with the method below. > it use the set_copy to duplicate a set and does nothing when then > element is marked as "shared". [...] > > how can I efficiently share elements in this kind of structure ? The main problem is that you're comparing the sets based on a structural polymorphic equality (compare) while what you want/need is physical comparison, which is of course faster and is the only way to detect shared structures. Sadly, there is no : phys_compare : 'a -> 'a -> int in OCaml, so you might use the following method : Add an unique integer "id" to your set in a record, that will enable you to maintain a hashtbl (or set) of shared structures based on integer comparison between their id's. That's what OCaml is doing inside the compiler. Regards, Nicolas Cannasse ------------------- 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