From: Olivier Andrieu <andrieu@ijm.jussieu.fr>
To: frederic.gava@wanadoo.fr
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Missing a function
Date: Sun, 30 Jan 2005 13:14:47 +0100 (CET) [thread overview]
Message-ID: <20050130.131447.71085960.oandrieu@nerim.net> (raw)
In-Reply-To: <001901c506b1$7d89fb60$0100a8c0@mshome.net>
> Frédéric Gava [Sun, 30 Jan 2005]:
> 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 ?
Oh right. And a test is needed for `add' too since the cardinal will
not change if the key is already bound in the map. So, all in all it's
not a very good idea :)
--
Olivier
next prev parent reply other threads:[~2005-01-30 12:15 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-01-30 9:53 Fw: " Frédéric Gava
2005-01-30 12:14 ` Olivier Andrieu [this message]
-- strict thread matches above, loose matches on Subject: below --
2004-11-30 20:30 Strange observation on polymorphic '<' Ritesh Kumar
2004-12-01 23:17 ` [Caml-list] " Damien Doligez
2004-12-03 7:24 ` Ritesh Kumar
2004-12-03 8:22 ` Ville-Pertti Keinonen
2004-12-04 11:05 ` Missing a function Frédéric Gava
2004-12-04 13:25 ` [Caml-list] " sejourne_kevin
2004-12-04 14:13 ` Frédéric Gava
2005-01-29 19:34 ` Radu Grigore
2005-01-29 19:55 ` Radu Grigore
2005-01-29 21:05 ` Olivier Andrieu
2005-02-04 20:18 ` Radu Grigore
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=20050130.131447.71085960.oandrieu@nerim.net \
--to=andrieu@ijm.jussieu.fr \
--cc=caml-list@inria.fr \
--cc=frederic.gava@wanadoo.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