caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Xavier Leroy <xavier@Theory.Stanford.EDU>
To: Eric.Dujardin@inria.fr (Eric Dujardin)
Cc: caml-list@margaux.inria.fr, dujardin@naima.inria.fr
Subject: Re: using sets
Date: Mon, 28 Mar 1994 13:50:35 -0800 (PST)	[thread overview]
Message-ID: <9403282150.AA23982@Tamuz.Stanford.EDU> (raw)
In-Reply-To: <199403281237.AA12519@naima.inria.fr> from "Eric Dujardin" at Mar 28, 94 02:37:54 pm

> it seems that a "magic" function, that would for example take any
> reference as parameter and return an integer, would be more
> efficient. However, I have no idea how it could be written...

The obvious choice would be to use the memory address of the cell
representing the reference, but this does not work with a copying
garbage collector such as Caml Light's, where the address of a cell
may change during garbage collection. Similar problems arise in
connection with structured input-output (output_value and
input_value).

> I could add an explicit "Identifier" field to my "Noeud"
> instances,

Yes, that's a good trick. I use it all the time. Basically, you would
define your Lien type as

     type Lien =
       { stamp: int;
         mutable A_lien: Noeud;
         mutable B_lien: Noeud }

and always create values of type Lien through the following function:

      let stamp_counter = ref 0;;
      let new_lien a b =
        incr stamp_counter;
        { stamp = !stamp_counter; A_lien = a; B_lien = b };;

Then, a total order over these objects is

      let order_lien l1 l2 = l1.stamp - l2.stamp;;

The stamp also comes handy for printing the data structure during
debugging.

- Xavier Leroy




  reply	other threads:[~1994-03-29 11:57 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1994-03-28 12:37 Eric Dujardin
1994-03-28 21:50 ` Xavier Leroy [this message]
1994-03-28 17:41 Pierre Weis

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=9403282150.AA23982@Tamuz.Stanford.EDU \
    --to=xavier@theory.stanford.edu \
    --cc=Eric.Dujardin@inria.fr \
    --cc=caml-list@margaux.inria.fr \
    --cc=dujardin@naima.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).