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] Possible function to add to Hashtbl?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2001-10-19 (12:41)
From: Jean-Christophe Filliatre <Jean-Christophe.Filliatre@l...>
Subject: Re: [Caml-list] Possible function to add to Hashtbl?

 > I'm sure there's a more efficient way to implement such a function in the
 > hashtbl module, but here's what I've been using thus far:
 > -----
 > let hashtbl_remove_all h key =
 >   for i=1 to List.length (Hashtbl.find_all h key) do
 >     Hashtbl.remove h key;
 >   done
 > -----

To avoid allocating the list, you can do like this:

let rec remove_all h k = 
    let _ = Hashtbl.find h k in Hashtbl.remove h k; remove_all h k
  with Not_found -> 

But conversely, you compute the hash key several times.

Jean-Christophe Filliatre (http://www.lri.fr/~filliatr)

Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr