caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Diego Olivier Fernandez Pons <Diego-Olivier.FERNANDEZ-PONS@cicrp.jussieu.fr>
To: caml-list@inria.fr
Subject: [Caml-list] Three way comparaisons
Date: Wed, 7 Aug 2002 16:41:35 +0200 (DST)	[thread overview]
Message-ID: <Pine.A32.3.95.1020807162520.50734E-100000@ibm1.cicrp.jussieu.fr> (raw)
In-Reply-To: <20020807073600.GA31615@strontium.pps.jussieu.fr>

    Bonjour,

Dans une note d'Arno Andersson [signalée par Okasaki dans Oka98] est
présenté un algorithme de recherche dans un arbre en (log n + 1)
comparaisons :

au lieu de

let rec member x = function
  | Empty -> false
  | Node (a, y, b) ->
     match compare x y with
      | n when n < 0 -> member x a
      | n when n > 0 -> member x b
      | _ -> true

Arno propose un algorithme qui ne fait qu'une comparaison par noeud.
Il explique que "since most high-level languages do not supply three
way comparaisons the number of comparaisons used _de facto_ are
reduced by a factor of two"

Il ajoute en plus "However, so far the autor has never observed a
compiler which actually translate these two comparaisons into one
three-way comparaison"

- Qu'est exactement une comparaison à trois voies ? (est-ce une façon
d'exploiter que les processeurs en général lèvent des drapeaux de
signe ou de nullité pour leurs opérations ?)

- Le compilateur Caml effectue-t-il cette optimisation ?

- Le code proposé par Andersson sera-t-il vraiment plus efficace étant
donné que l'on est obligé de transmettre un paramètre de plus
(indépendamment du fait que l'arbre soit parcouru sur toute sa hauteur
dans la mesure où le truc peut toujours servir pour les insertions où
le parcours est toujours complet ?)

Code d'Andersson

(* y est le plus grand des minorants de x déjà rencontrés donc le
candidat idéal pour le test d'égalité *)

let rec member_some x y = function
  | Empty -> compare x y = 0
  | Node (a, z, b) ->
     compare x z with
       | n when n < 0 -> member_some x y a
       | _ -> member_some x z b

let rec member_none x = function
  | Empty -> false
  | Node (a, y, b) ->
      match compare x y with
        | n when n < 0 -> member_none x a
        | _ -> member_some x y b

let member x = function tree -> member_none x tree

        Diego Olivier

-------------------
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


  parent reply	other threads:[~2002-08-07 14:44 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-08-07  5:02 [Caml-list] Regarding regular expressions John Skaller
2002-08-07  7:36 ` Jerome Vouillon
2002-08-07 12:23   ` Pixel
2002-08-07 14:41   ` Diego Olivier Fernandez Pons [this message]
2002-08-07 15:22     ` [Caml-list] Three way comparaisons Luc Maranget
2002-08-08 11:44       ` Diego Olivier Fernandez Pons

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=Pine.A32.3.95.1020807162520.50734E-100000@ibm1.cicrp.jussieu.fr \
    --to=diego-olivier.fernandez-pons@cicrp.jussieu.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).