From: cousinea@dmi.ens.fr
To: Xavier Leroy <xavier@Theory.Stanford.EDU>
Cc: caml-list@margaux
Subject: Re: new library modules
Date: Fri, 7 May 93 12:29:44 +0200 [thread overview]
Message-ID: <9305071029.AA00287@arnica.ens.fr> (raw)
As I said, I have also implemented balanced trees and used them
to manipulate what Xavier calls sets and maps .
It is certainly less efficient that Xavier's implementation
since it is a purely functional one
but I have nonetheless used them quite extensively, building
balanced trees of size over 2^20.
I am not sure my choices have been the right ones
but here is a short description.
My main functions over balanced trees are:
empty: 'a t
add: ('a*'a -> comparison) -> option -> 'a -> 'a t -> 'a t
exists: ('a -> comparison) -> 'a t -> bool
get: ('a -> comparison) -> 'a t -> 'a
get_all: ('a -> comparison) -> 'a t -> 'a list
remove: ('a -> comparison) -> 'a t -> 'a t
remove_all: ('a -> comparison) -> 'a t -> 'a t
................
Values of type ('a*'a -> comparison) are supposed to be
total preorders and it is user's responsibality to use
them consistently.
type option = Take_Old | Take_New | Take_Both
is a type that specifies what should be done
when adding a value to a tree that contains an equivalent one.
Note that functions "get" and "exists" use an argument
of type ('a -> comparison)
which is similar to giving both an argument "ord" of type
('a*'a -> comparison) and an argument "x" of type 'a as Xavier
does for function "mem". This choice takes into account
the fact that, when using a preorder and not an order,
it is sometimes useful to search for objects that have
a more specific property that just identity or equivalence
to a given object.
This goes against Damien's suggestion to encapsulate the preorder
in the type which I approve for sets and maps (by the way,
the proposal by Laufer and Odersky should give a solution
for that).
Xavier's maps are easily obtained from my balanced trees:
type ('a,'b) map == ('a,'b) t;;
let add_map ord m x y= add ord Take_New (x,y) m;;
let find_map ord m x = snd (get (fun y -> ord x (fst y)) m);;
........
Note that here, the order on type 'a induces a preorder on type
('a * 'b) which is used for the search. This is another argument
for the importance of preorders.
---Guy
next reply other threads:[~1993-05-07 13:35 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
1993-05-07 10:29 cousinea [this message]
-- strict thread matches above, loose matches on Subject: below --
1993-05-07 10:23 cousinea
1993-05-05 9:53 Damien Doligez
1993-05-04 9:14 cousinea
1993-05-04 9:38 ` Vale'rie Me'nissier-Morain
1993-05-05 2:25 ` Xavier Leroy
1993-05-03 18:45 Xavier Leroy
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=9305071029.AA00287@arnica.ens.fr \
--to=cousinea@dmi.ens.fr \
--cc=caml-list@margaux \
--cc=xavier@Theory.Stanford.EDU \
/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