Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

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


On 5/11/08, Florent Monnier <> 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:
> Archives:
> Beginner's list:
> Bug reports: