English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
[Caml-list] Hashtbl iter semantics
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2002-05-27 (14:39)
From: Xavier Leroy <xavier.leroy@i...>
Subject: Re: [Caml-list] Hashtbl iter semantics
> Could the ocaml team please clarify the semantics of Hashtbl.iter?
> In particular, can I use Hashtbl.replace during iteration?
> [What about add, removed, etc?]

You can use Hashtbl.{replace,add,remove} while iterating over the same
hash table, in the sense that it will not corrupt the table.  However,
there is no guarantee that the iteration will "see" the modification
or not.  E.g. if you add an element, the function being iterated can
be called on the newly added element, or not, depending on the
relative positions of the new element and of the iteration point
inside the hash table.

If you need stronger guarantees (e.g. the iteration must operate on
the initial state of the table), consider replacing the hash table by
a reference to a binary tree (module Map).

- Xavier Leroy
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners