caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Radu Grigore <radugrigore@gmail.com>
To: "Frédéric Gava" <frederic.gava@wanadoo.fr>
Cc: sejourne_kevin <sejourne_kevin@yahoo.fr>, caml-list@inria.fr
Subject: Re: [Caml-list] Missing a function
Date: Sat, 29 Jan 2005 21:34:28 +0200	[thread overview]
Message-ID: <7f8e92aa05012911345344cbc6@mail.gmail.com> (raw)
In-Reply-To: <003601c4da0b$774ac220$0100a8c0@mshome.net>

On Sat, 4 Dec 2004 15:13:44 +0100, Frédéric Gava
<frederic.gava@wanadoo.fr> wrote:

> > let cardinal e = fold (fun _ _ x -> succ x) e 0;;
> [...] Map are also implemented as balanced
> tree (like sets) and therefore, it is easy to add a function of "cardinal".

I agree it's strange not to have "cardinal" in Map.Make. The
implementations of Set and Map are likely to be very similar anyway.

I do not have the ocaml sources handy right now but... Set and Map are
probably RB-trees. In this case there are at least 2 pointers for
links (left and right children),  one pointer for key and, for maps,
one pointer for data.  So a set of N elements occupies at least 12xN
bytes, while a map occupies at least 16xN bytes. If an element counter
is added then the sizes would increase to 16xN and 20xN. That doesn't
seem too bad. The advantages would be:

a. O(1) cardinal function. Right now for Map the user can implement a
O(n) one and for Set the complexity isn't specified. It is probably
O(lg n).

b. O(lg n) indexed access.

Such a change implies minimal modification of existing functions:
Set.cardinal becomes faster (if my guess -- lg n -- was correct) and
add/remove will be _slightly_ slower. The advantage would be
Map.cardinal and indexed access.

-- 
regards,
 radu
http://rgrig.idilis.ro/


  reply	other threads:[~2005-01-29 19:34 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-11-30 20:30 Strange observation on polymorphic '<' Ritesh Kumar
2004-12-01 23:17 ` [Caml-list] " Damien Doligez
2004-12-03  7:24   ` Ritesh Kumar
2004-12-03  8:22     ` Ville-Pertti Keinonen
2004-12-04 11:05       ` Missing a function Frédéric Gava
2004-12-04 13:25         ` [Caml-list] " sejourne_kevin
2004-12-04 14:13           ` Frédéric Gava
2005-01-29 19:34             ` Radu Grigore [this message]
2005-01-29 19:55               ` Radu Grigore
2005-01-29 21:05               ` Olivier Andrieu
2005-02-04 20:18               ` Radu Grigore
2005-01-30  9:53 Fw: " Frédéric Gava
2005-01-30 12:14 ` Olivier Andrieu

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=7f8e92aa05012911345344cbc6@mail.gmail.com \
    --to=radugrigore@gmail.com \
    --cc=caml-list@inria.fr \
    --cc=frederic.gava@wanadoo.fr \
    --cc=sejourne_kevin@yahoo.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).