Version française
Home     About     Download     Resources     Contact us    
Browse thread
Fw: [Caml-list] Missing a function
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Frédéric_Gava <frederic.gava@w...>
Subject: Fw: [Caml-list] Missing a function
Hi,
>
> > Another option is to build on top of the stdlib Map functor another
> > functor that keeps track of the cardinal of a map :
> >
> > module CMap = functor (Ord : Map.OrderedType) ->
> >   (struct
> >     module M = Map.Make (Ord)
> >
> >     type key = M.key
> >     type 'a t = int * 'a M.t
> >
> >     let cardinal = fst
> >
> >     let empty = 0, M.empty
> >
> >     let add k v (n, m) = (n + 1, M.add k v m)
> >
> >     let find k (_, m) = M.find k m
> >
> > ....
> >    : sig
> >        include Map.S
> >        val cardinal : 'a t -> int
> >      end)
> >
Hum. To remove an element, you have to test is its exists or not before
decrease n. It could be to much cost expansive...no ?

Regards,
Frédéric Gava