From: "Jean-Christophe Filliâtre" <Jean-Christophe.Filliatre@lri.fr>
To: Evan Klitzke <evan@yelp.com>
Cc: peng.zang@gmail.com, caml-list@inria.fr
Subject: Re: [Caml-list] Help with simple ocaml memoization problem
Date: Thu, 29 Nov 2007 09:47:31 +0100 [thread overview]
Message-ID: <474E7CA3.2050008@lri.fr> (raw)
In-Reply-To: <cfb58d850711282212r64eddad3u713e2eb743526b0a@mail.gmail.com>
Evan Klitzke wrote:
> One question that I have is what is the difference
> between the Map and Hashtbl modules? From the documentation they look
> very similar -- why did you use Hashtbl here rather than Map?
Hashtbl implements an imperative data structure i.e. association tables
which are modified in-place when inserting, removing, etc.
On the contrary, Map implements a persistent data structure i.e. tables
which are not modified when you perform operations; instead, new tables
are returned, the previous ones being unchanged.
(This can be seen in the types
Hashtbl.add : ('a, 'b) Hashtbl.t -> 'a -> 'b -> unit
SomeMap.add : key -> 'a -> 'a t -> 'a t
Here you can see the return type unit for hash tables, and the return
type 'a t for the maps.)
There are many cases where persistence can help improving your code:
backtracking, sharing between several data structures, clarity and
correctness of the code, etc.
In the case of this particular example, however, the use of a hash table
is perfectly fine, as demonstrated by Peng. With a good hash function,
insertion in a hash table typically runs in constant time, while
insertion in a map has logarithmic cost. But don't be misleaded by this
performance comparison: persistence has so many advantages that it is
often the case that you want to pay this extra cost.
--
Jean-Christophe Filliâtre
http://www.lri.fr/~filliatr/
next prev parent reply other threads:[~2007-11-29 8:37 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-11-29 3:17 Evan Klitzke
2007-11-29 5:53 ` [Caml-list] " Peng Zang
2007-11-29 6:12 ` Evan Klitzke
2007-11-29 8:16 ` David Allsopp
2007-11-29 8:11 ` Jon Harrop
2007-11-29 8:58 ` Jean-Christophe Filliâtre
2007-11-29 18:57 ` Jon Harrop
2007-11-29 22:25 ` Jon Harrop
2007-11-30 11:03 ` Jean-Christophe Filliâtre
2007-11-29 8:40 ` Luc Maranget
2007-11-29 8:47 ` Jean-Christophe Filliâtre [this message]
2007-12-04 23:49 ` Peng Zang
2007-11-29 8:08 ` Jon Harrop
2007-11-29 15:59 ` Peng Zang
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=474E7CA3.2050008@lri.fr \
--to=jean-christophe.filliatre@lri.fr \
--cc=caml-list@inria.fr \
--cc=evan@yelp.com \
--cc=peng.zang@gmail.com \
/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