caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jacques Garrigue <garrigue@kurims.kyoto-u.ac.jp>
To: maya@dsl.serc.iisc.ernet.in
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Hashtbl.iter
Date: Wed, 17 Oct 2001 15:28:54 +0900	[thread overview]
Message-ID: <20011017152854F.garrigue@kurims.kyoto-u.ac.jp> (raw)
In-Reply-To: <Pine.LNX.4.21.0110171146330.31792-100000@yaman.serc.iisc.ernet.in>

From: Maya Ramanath <maya@dsl.serc.iisc.ernet.in>

> The question is with regard to Hashtbl.iter.  Basically, what happens when
> I'm doing an iteration on the Hashtbl and at the same time add something
> new to the hashtable ?  For ex:
> 	let xyz ht key value =
> 	  (* Do something with key, value *)
> 	  if (some-condition-holds) then
>    	    ht.add something new
> 
> 	let abc ht =
> 	  Hashtbl.iter (xyz ht) ht
> 
> I would like to know if the new things that I added to the hashtable will
> be picked up by the iterator.

If you look at the source in hashtbl.ml, clearly the answer is
"undefined behaviour". If your new element is added in a bucket
after the one your are currently processing then yes, otherwise no,
and the point of hashtables is that you don't know in which bucket you
will end up...

If you want to avoid this behaviour, use Map.Make.

Jacques Garrigue
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr


  reply	other threads:[~2001-10-17  6:29 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-10-17  6:17 Maya Ramanath
2001-10-17  6:28 ` Jacques Garrigue [this message]
     [not found] ` <9qj955$1l5$1@qrnik.zagroda>
2001-10-17  6:51   ` Marcin 'Qrczak' Kowalczyk
2001-10-17  8:30     ` Jacques Garrigue
2001-10-17  8:49 ` Fabrice Le Fessant

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=20011017152854F.garrigue@kurims.kyoto-u.ac.jp \
    --to=garrigue@kurims.kyoto-u.ac.jp \
    --cc=caml-list@inria.fr \
    --cc=maya@dsl.serc.iisc.ernet.in \
    /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).