caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* filter on map
@ 2007-06-07  8:27 Christophe Raffalli
  2007-06-07  9:11 ` [Caml-list] " Jon Harrop
  2007-06-07 13:16 ` Brian Hurt
  0 siblings, 2 replies; 3+ messages in thread
From: Christophe Raffalli @ 2007-06-07  8:27 UTC (permalink / raw)
  To: caml-list

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


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2007-06-07 13:16 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-06-07  8:27 filter on map Christophe Raffalli
2007-06-07  9:11 ` [Caml-list] " Jon Harrop
2007-06-07 13:16 ` Brian Hurt

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).