caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Diego Olivier Fernandez Pons <Diego.FERNANDEZ_PONS@etu.upmc.fr>
To: Martin Jambon <martin_jambon@emailuser.net>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Map + Set
Date: Mon, 26 Jul 2004 18:52:50 +0200 (DST)	[thread overview]
Message-ID: <Pine.A41.4.44.0407261836120.716956-100000@ibm1> (raw)
In-Reply-To: <Pine.LNX.4.44.0407262348460.879-100000@localhost>

    Bonjour,

> I define a `merge' function so that:
> merge { ("a", {1;2;4}); ("b", {1}) } { ("a", {3;2;7;8}) } =
>     { ("a", {1;2;3;4;7;8}); ("b", {1}) }
>
> For this I define a `really_add' function so that:
> really_add ("a", {1}) { ("a", {3;2;7;8}); ... } =
>     { ("a", {1;3;2;7;8}); ... }
>
> which should perform O(log n) comparisons of keys (the strings) and
> not O(n). This is where I need an O(log n) find, or a remove that returns
> me the element that was removed.

It seems to me that what you are looking for is an ('a, 'b set) map in
which the insertion does not replace the existing data but applies a
given function (like Set.add) to the current data.

I sometimes need an insert_with function for ('a, 'b list) map that
inserts the data in the list if any or creates a new list otherwise.
It is a simple modification of the 'insert' (resp. union, difference)
function.

On the other hand, if you are using strings as keys you should use a
trie instead of a map in order to ensure worst-case logarithmic
complexity (have a look to lexicalmaps in /trie of Baire).

Finally since the data part seems to be a set (and not a list as in my
example) the best solution would be a ternary tree (that is a binary
tree with one extra pointer to the set represented by a tree, which
makes 3 tree pointers)

Look in Baire the ternary tree implementation of the /graph directory


        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


  reply	other threads:[~2004-07-26 16:54 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-07-25  8:17 Martin Jambon
2004-07-25 16:26 ` Matt Gushee
2004-07-25 17:01 ` Brian Hurt
2004-07-26 10:40   ` Matthieu Sozeau
2004-07-26 15:25     ` Brian Hurt
2004-07-26 15:47       ` Martin Jambon
2004-07-26 16:26         ` Brian Hurt
2004-07-26  7:43 ` Diego Olivier Fernandez Pons
2004-07-26 16:24   ` Martin Jambon
2004-07-26 16:52     ` Diego Olivier Fernandez Pons [this message]
2004-07-27 21:45   ` [Caml-list] Camlp4 help/questions Josh Smith
2004-07-27 22:11     ` Brian Hurt
2004-07-28  1:15       ` Josh Smith
     [not found]     ` <200407272307.50167.jon@jdh30.plus.com>
2004-07-28  1:38       ` Josh Smith
2004-07-28  8:03     ` Pierre Weis

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.A41.4.44.0407261836120.716956-100000@ibm1 \
    --to=diego.fernandez_pons@etu.upmc.fr \
    --cc=caml-list@inria.fr \
    --cc=martin_jambon@emailuser.net \
    /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).