English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
Re: [Caml-list] Hashtbl and destructive operations on keys
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2004-03-23 (00:00)
From: oliver@f...
Subject: Re: [Caml-list] Hashtbl and destructive operations on keys
On Mon, Mar 22, 2004 at 07:16:57PM +0100, Thomas Fischbacher wrote:
> Dear ocaml hackers,
> I read the documentation in such a way that I must not assume that after
> doing a Hashtbl.replace hash key new_val, I can destructively modify key
> with impunity. (I do cons a new key at every Hashtbl.add.)

When you modify the key, you will have the problem
not to get directly to your data (your hash-value).

But with Hashtbl.fold you can find anything in the hashtbl,
that was not destrctively overwritten.

So, if you throw away your key (why should one do that?),
you can find your value nevertheless with Hashtbl.fold.

> On the other hand (I have not looked into the sources), I am quite 
> confident that the system _could_ give me the guarantee that 
> nothing evil happens if I do so, and especially for the application I am 
> presently working on, this would induce a noticeable performance gain,
> due to reduced consing. (And performance is important here!)

You mean that the key is overwritten in-place,
because these imperative features are fast?!

> So, could I please get this officially sanctioned? :-)

Again: When you throw away your key, you will not have
_direct_ access to your value. So if you need that
direct access, you have a problem.
If it is not necessary to get directly to that data and you
are happy with finding the key-value pairs after you have
inserted all stuff into the hashtbl, then you can throw away
your key, if you want to.


To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners