Version française
Home     About     Download     Resources     Contact us    
Browse thread
Hashtbl.remove legal within Hashtbl.iter for the same hash table?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Martin Jambon <martin.jambon@e...>
Subject: Re: [Caml-list] Hashtbl.remove legal within Hashtbl.iter for the same hash table?
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 and collect
> all of the items to remove and then remove them in a second pass. The
> performance hit shouldn't be as bad as you could expect (ie: I
> wouldn't bother unless performance really is critical).
> I see it as very unlikely that ocaml's implementation of hashtbl would
> evolve in such a way that it would break any code removing previously
> visited items during a traversal. Your call.

If you (Florent) want to rely on the standard Hashtbl module, I would 
strongly advise against making assumptions such as "the implementation is 
unlikely to change". Think of the situation 5 years later, when the 
implementation actually changes, you've left the company 3 years before, 
and the maintainer has to figure why the program returns messed up 
results... 
I bet you wouldn't like to be this maintainer.

It's like drunk driving or forgetting the condom: just don't do it...



Martin


> On 5/11/08, Florent Monnier <fmonnier@linux-nantes.fr.eu.org> wrote:
>>> 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
>> itered,
>> while the manual says :
>> "The order in which the bindings are passed to f is unspecified."
>>
>> _______________________________________________
>> Caml-list mailing list. Subscription management:
>> http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
>> Archives: http://caml.inria.fr
>> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
>> Bug reports: http://caml.inria.fr/bin/caml-bugs
>>
>
>
> -- 
> http://till-varoquaux.blogspot.com/
>
> _______________________________________________
> Caml-list mailing list. Subscription management:
> http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
> Archives: http://caml.inria.fr
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
>

--
http://wink.com/profile/mjambon
http://mjambon.com