caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: oliver@first.in-berlin.de (Oliver Bandel)
To: caml-list@inria.fr
Subject: Re: [Caml-list] Hashtbl and destructive operations on keys
Date: Tue, 23 Mar 2004 00:44:15 +0100	[thread overview]
Message-ID: <20040322234415.GA1126@first.in-berlin.de> (raw)

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.

Ciao,
   Oliver

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


             reply	other threads:[~2004-03-23  0:00 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-03-22 23:44 Oliver Bandel [this message]
  -- strict thread matches above, loose matches on Subject: below --
2004-03-22 23:44 Oliver Bandel
2004-03-22 18:16 Thomas Fischbacher
2004-03-22 19:09 ` Remi Vanicat
2004-03-22 23:13   ` Thomas Fischbacher
2004-03-23  0:59     ` Jacques Garrigue
2004-03-23  9:20     ` Correnson Loïc
2004-03-23 12:12       ` Thomas Fischbacher
2004-03-23  9:45     ` Oliver Bandel

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=20040322234415.GA1126@first.in-berlin.de \
    --to=oliver@first.in-berlin.de \
    --cc=caml-list@inria.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;
as well as URLs for NNTP newsgroup(s).