[Caml-list] Hashtbl.remove legal within Hashtbl.iter for the same hash table?

2008-05-11 Thread David MENTRE
Hello, Probably a newbie question but anyway: is it allowed to do a Hashtbl.remove while doing a Hashtbl.iter on the same hash table? More precisely, at one point while doing a "Hashtbl.iter f h" my function "f" is called with something like "f k v". Can I do a "Hashtbl.remove h k" within the bod

Re: [Caml-list] Hashtbl.remove legal within Hashtbl.iter for the same hash table?

2008-05-11 Thread Florent Monnier
> Hello, Hello David, > Probably a newbie question but anyway: is it allowed to do a > Hashtbl.remove while doing a Hashtbl.iter on the same hash table? I don't know if it is legal, but at least it works: # let h = Hashtbl.create 8 ;; # for i = 0 to pred 8 do Hashtbl.add h i (char_of_int((in

Re: [Caml-list] Hashtbl.remove legal within Hashtbl.iter for the same hash table?

2008-05-11 Thread Julien Peeters
Hi David, Because the arguments passed to functions could be considered as references (same memory space), IMHO, if you respect the scope priority it should work. For instance: let () = let h = Hashtbl.create 7 in let f k v = Hashtbl.remove h k in Hashtbl.iter f h Julien. 2008/

Re: [Caml-list] Hashtbl.remove legal within Hashtbl.iter for the same hash table?

2008-05-11 Thread Till Varoquaux
Hatables are arrays of associative lists. When you are iterating over them removing any element you have already visited should be ok. Removing elements you haven't visited yet could cause you to encounter them anyhow. Adding elements might trigger resizing and then things could get sketchy (has t

Re: [Caml-list] Hashtbl.remove legal within Hashtbl.iter for the same hash table?

2008-05-11 Thread Florent Monnier
> (* this one would not appear with the sdt Hashtbl.iter ! *) wrong, it appears too I've made a mistake in the toplevel :) ___ Caml-list mailing list. Subscription management: http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list Archives: http://cam

Re: [Caml-list] Hashtbl.remove legal within Hashtbl.iter for the same hash table?

2008-05-11 Thread Florent Monnier
> Hatables are arrays of associative lists. When you are iterating over > them removing any element you have already visited should be ok. > Removing elements you haven't visited yet could cause you to encounter > them anyhow. which means that it is dependent to the order in which the content is i

Re: [Caml-list] Hashtbl.remove legal within Hashtbl.iter for the same hash table?

2008-05-11 Thread Till Varoquaux
Indeed. The answer you got was, however, based on the actual implementation not on the documentation. This means that, at some point, this might evolve and not be valid anymore. If you want to be on the safe side you should do a fold instead of an iter and collect all of the items to remove and the

Re: [Caml-list] Hashtbl.remove legal within Hashtbl.iter for the same hash table?

2008-05-11 Thread Martin Jambon
On Sun, 11 May 2008, Till Varoquaux wrote: Indeed. The answer you got was, however, based on the actual implementation not on the documentation. This means that, at some point, this might evolve and not be valid anymore. If you want to be on the safe side you should do a fold instead of an iter

Re: [Caml-list] Hashtbl.remove legal within Hashtbl.iter for the same hash table?

2008-05-12 Thread David MENTRE
Hello Till, "Till Varoquaux" <[EMAIL PROTECTED]> writes: > Indeed. The answer you got was, however, based on the actual > implementation not on the documentation. This means that, at some > point, this might evolve and not be valid anymore. If you want to be > on the safe side you should do a fol