caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Christophe Raffalli <christophe.raffalli@univ-savoie.fr>
To: caml-list@inria.fr
Subject: disjoint test in set.
Date: Thu, 24 Jan 2008 23:38:14 +0100	[thread overview]
Message-ID: <47991356.9030307@univ-savoie.fr> (raw)


Dear list member,

I think a function testing if two sets are disjoint is really simple, 
more efficient than building the intersection, and missing in the 
standard library ?
I may be wrong ?

Here it is if someone wants to copy it in set.ml :

    let rec disjoint t1 t2 =
      match (t1, t2) with
        (Empty, _) | (_, Empty) ->
          true
      | (Node (l1, v1, r1, _), Node (l2, v2, r2, _)) ->
          let c = Ord.compare v1 v2 in
          if c = 0 then
            false
          else if c < 0 then
            disjoint (Node (l1, v1, Empty, 0)) l2 && disjoint r1 t2
          else
            disjoint l1 (Node (l2, v2, Empty, 0)) && disjoint t1 r2

+ the necessary lignes in signatures ...

Then, a small question:

Can we make disjoint (and subset) do no allocation in the heap (That is 
remove Node (l1, v1, Empty, 0) and the symmetric
from the code without loss of performance ? (checking v1 and l1 
separately is surely a bad idea) ...

Best Regards,
Christophe


                 reply	other threads:[~2008-01-24 22:34 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=47991356.9030307@univ-savoie.fr \
    --to=christophe.raffalli@univ-savoie.fr \
    --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).