Browse thread
Hashtbl.remove legal within Hashtbl.iter for the same hash table?
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Till Varoquaux <till.varoquaux@g...> |
| Subject: | Re: [Caml-list] Hashtbl.remove legal within Hashtbl.iter for the same hash table? |
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. Till 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/