caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Christophe Raffalli <christophe.raffalli@univ-savoie.fr>
To: caml-list@inria.fr
Subject: filter on map
Date: Thu, 07 Jun 2007 10:27:52 +0200	[thread overview]
Message-ID: <4667C188.1060408@univ-savoie.fr> (raw)

Dear list members

I just write this piece of code because I wanted filter on map:

module Map_Label = struct
   module M =  Map.Make(Label)
   include M

   let filter f m =
     M.fold (fun k v m ->
       if f k then M.add k v m else m) m M.empty
end

But I am now wondering: this is O(n ln n), isn't there an O(n) implementation (or just a faster
implementation). This code insert the keys in increasing order which is the worst case for balancing 
? Just using a "random_fold" should make things better ...

What do you think ?

Cheers,
-- 
Christophe Raffalli
Université de Savoie
Batiment Le Chablais, bureau 21
73376 Le Bourget-du-Lac Cedex

tél: (33) 4 79 75 81 03
fax: (33) 4 79 75 87 42
mail: Christophe.Raffalli@univ-savoie.fr
www: http://www.lama.univ-savoie.fr/~RAFFALLI


             reply	other threads:[~2007-06-07  8:27 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-06-07  8:27 Christophe Raffalli [this message]
2007-06-07  9:11 ` [Caml-list] " Jon Harrop
2007-06-07 13:16 ` Brian Hurt

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=4667C188.1060408@univ-savoie.fr \
    --to=christophe.raffalli@univ-savoie.fr \
    --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).