caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Stefano Zacchiroli <zack@cs.unibo.it>
To: caml-list@inria.fr
Subject: Re: [Caml-list] Suggestion about balanced trees in stdlib
Date: Sat, 11 May 2002 19:18:18 +0200	[thread overview]
Message-ID: <20020511171818.GA6384@cs.unibo.it> (raw)
In-Reply-To: <20020511174704.A632@ice.gerd-stolpmann.de>

On Sat, May 11, 2002 at 05:47:04PM +0200, Gerd Stolpmann wrote:
> type 'a map = Empty | Node of 'a map * key * 'a * 'a map * int
> 
> type set = Empty | Node of set * elt * set * int
> 
> The difference is that every map node has 6 words, and every set node
> consists of 5 words. My suggestion is to prefer the map representation,
> and define set = unit map, wasting one word per node, and making sets
> 20% larger.

Ok, I agree that this is the "clean" way to the goal.

Anyway I think that memory consumption is crucial for the standard
library, this is why I'm proposing a dirty trick for the set/map matter.
Usually I dislike tricks and prefer clean programming, but IMHO a
standard library is somewhat a particular case.

<WARNING_dirty_trick>

Why not use a single source file that implement both set and map using
some campl4 tricks like pa_ifdef module?
You may have two different definitions of tree and a pool of accessor
functions working on a tree and returning single components (hoping that
the compiler inline this kind of functions).
In the set case you doesn't need to use the value component of a tree
so you can avoid to compile the relative accessor function (poor gain)
and you can also compile a tree tuple without a value component.

</WARNING_dirty_trick>

[ Question: gurus, do you thinks this is a feasible solution or I'm
missing something? ]

I know, this is a really dirty trick. Also I don't know if is applicable
because I have never looked at the implementations set.ml and map.ml but
just as an idea it can work.

Pros:
- reduce memory consumption for Set
- no code duplication

Cons:
- objects (.cm{a,o,x...}) duplication
- really dirty!
- last time I looked at it camlp4 pa_ifdef module doesn't permit
  multiple declaration using only one "if" construct so you incurs in
  situations like:
     ifdef FOO then let bar = ...
     ifdef FOO then let quux = ...
     ifdef FOO then let baz = ...

Just a [dirty] idea.
Cheers.

-- 
Stefano Zacchiroli - undergraduate student of CS @ Univ. Bologna, Italy
zack@cs.unibo.it | ICQ# 33538863 | http://www.cs.unibo.it/~zacchiro
"I know you believe you understood what you think I said, but I am not
sure you realize that what you heard is not what I meant!" -- G.Romney
-------------------
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


  reply	other threads:[~2002-05-11 17:18 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-05-10 16:59 Gerd Stolpmann
2002-05-10 16:56 ` Alexander V.Voinov
2002-05-10 22:31 ` Stefano Zacchiroli
2002-05-10 23:05   ` Alexander V.Voinov
2002-05-11  7:20     ` Stefano Zacchiroli
2002-05-11 15:47   ` Gerd Stolpmann
2002-05-11 17:18     ` Stefano Zacchiroli [this message]
2002-05-11 17:36       ` Dave Mason
2002-05-12  0:03       ` polux moon
2002-05-13  7:23 ` Mattias Waldau

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=20020511171818.GA6384@cs.unibo.it \
    --to=zack@cs.unibo.it \
    --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).