Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Jean-Francois Monin <JeanFrancois.Monin@cnet.francetelecom.fr>
To: ohl@hep.tu-darmstadt.de
Cc: caml-list@inria.fr
Subject: Re: polymorphically comparable Maps?
Date: Mon, 22 Feb 1999 19:20:13 +0100	[thread overview]
Message-ID: <199902221820.TAA03582@lsun565.lannion.cnet.fr> (raw)
In-Reply-To: <14033.38333.652607.941379@heplix4.ikp.physik.tu-darmstadt.de>

> Does anybody know of a fast data structure for (applicative)
> association tables over ordered types (like Map in the standard
> library) with the property that identical maps will have an identical
> representation?  Sorted association lists work, but have linear access
> and insertion.  Is there something logarithmical (even with an OCaml
> implementation)?
> 
> Thanks,
> -Thorsten

I've just finished an in-place polymorphic version of splay trees,
with quite good perf. Splay trees (Tarjan & Sleator) are binary trees
where often accessed data tend to be near the root.

Here is the current mli.  Only iter and fold are still not
implemented, because I am currently experimenting this structure on an
application where they are not used. I can send the whole thing if you
are interested.

-- 
Jean-Francois Monin, CNET DTL/MSV,          Tel +33 2 96 05 26 79
2 av. Pierre Marzin, 22307 Lannion, France  Fax +33 2 96 05 39 45
SANS TRAIT D'UNION :      JeanFrancois.Monin@cnet.francetelecom     

-----------------------------------------------------------
(* splay.mli *)
(* NOT THREAD SAFE : env needs a mutex *)
(* WARNING : compare must not raise anu exception *)

module type OrderedType =
  sig
    type tt
    type tk
    val compare_int : tt -> tt -> int
    val compare_ext : tk -> tt -> int
    val print : tt -> unit
  end

module type S =
  sig
    type eltt
          (* The type of elements in the tree. *)
    type eltk
          (* The type of keys used for searching in the tree. *)
    type t
          (* The type of trees. *)
    exception Already_there
    exception Is_empty
    val print : t -> unit
	(* prints a tree *)
    val create: unit -> t
          (* The empty tree. *)
    val is_empty: t -> bool
        (* Test whether a tree is empty or not. *)
    val find: eltk -> t -> eltt
        (* [find x s] is an element y of [s] such that [compare_ext x y = 0]. *)
    val add: eltt -> t -> unit
        (* [add x s] adds the element [x] to the tree [s],
           If [x] was already in [s], [Already_there] is raised. *)
    val remove: eltk -> t -> unit
        (* [remove x s] returns a tree containing all elements of [s],
           except [y] such that compare_ext x y = 0.
	   If [x] was not in [s], TO BE COMPLETED. *)
(*
    val iter: (eltt -> unit) -> t -> unit
    val fold: (eltt -> 'a -> 'a) -> t -> 'a -> 'a
*)
    val cardinal: t -> int
        (* Return the number of elements of a tree. *)
    val elements: t -> eltt list
        (* Return the list of all elements of the given tree.
           The returned list is sorted in increasing order with respect
           to the ordering [Ord.compare_int], where [Ord] is the argument
           given to [Set.Make]. *)
    val min_elt: t -> eltt
        (* Return the smallest element of the given tree
           (with respect to the [Ord.compare_int] ordering), or raise
           [Not_found] if the tree is empty. *)
    val max_elt: t -> eltt
        (* Same as [min_elt], but returns the largest element of the
           given tree. *)
    val choose: t -> eltt
        (* Return one element of the given tree, or raise [Not_found] if
           the tree is empty. Which element is chosen is unspecified,
           but equal elements will be chosen for equal trees. *)
  end

module Make(Ord: OrderedType):
    (S with type eltt = Ord.tt and type eltk = Ord.tk)
        (* Functor building an implementation of the tree structure
           given a totally ordered type. *)





  reply	other threads:[~1999-02-23 14:52 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-02-22 17:37 Thorsten Ohl
1999-02-22 18:20 ` Jean-Francois Monin [this message]
1999-02-23 16:49 ` Stefan Monnier
1999-02-23 17:28   ` Adam P. Jenkins
1999-02-23 18:10   ` Thorsten Ohl

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=199902221820.TAA03582@lsun565.lannion.cnet.fr \
    --to=jeanfrancois.monin@cnet.francetelecom.fr \
    --cc=caml-list@inria.fr \
    --cc=ohl@hep.tu-darmstadt.de \
    /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