caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "Nicolas Cannasse" <warplayer@free.fr>
To: "Pietro Abate" <Pietro.Abate@anu.edu.au>,
	"ocaml ml" <caml-list@inria.fr>
Subject: Re: [Caml-list] sharing problem ...
Date: Mon, 26 Jan 2004 12:22:25 +0100	[thread overview]
Message-ID: <006901c3e3fe$ad44ee40$ef01a8c0@warp> (raw)
In-Reply-To: <20040126104345.GA3978@pulp.anu.edu.au>

> 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


  reply	other threads:[~2004-01-26 11:17 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-01-26 10:43 Pietro Abate
2004-01-26 11:22 ` Nicolas Cannasse [this message]
2004-01-26 13:27 ` Damien Doligez
2004-01-26 13:46   ` Pietro Abate

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='006901c3e3fe$ad44ee40$ef01a8c0@warp' \
    --to=warplayer@free.fr \
    --cc=Pietro.Abate@anu.edu.au \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).