From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id OAA23116; Fri, 19 Oct 2001 14:41:09 +0200 (MET DST) Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id OAA23311 for ; Fri, 19 Oct 2001 14:41:08 +0200 (MET DST) Received: from ext.lri.fr (ext.lri.fr [129.175.15.4]) by concorde.inria.fr (8.11.1/8.10.0) with ESMTP id f9JCf7508066 for ; Fri, 19 Oct 2001 14:41:08 +0200 (MET DST) Received: from pc803.lri.fr (IDENT:root@pc803 [129.175.8.114]) by ext.lri.fr (8.11.6/jtpda-5.3.2) with ESMTP id f9JCf7b25159 ; Fri, 19 Oct 2001 14:41:07 +0200 (MET DST) Received: by pc803.lri.fr (8.9.3/feuille) id OAA10046 ; Fri, 19 Oct 2001 14:41:08 +0200 X-Authentication-Warning: localhost.localdomain: filliatr set sender to filliatr@pc803 using -f From: Jean-Christophe Filliatre MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-ID: <15312.8036.484382.801683@pc803> Date: Fri, 19 Oct 2001 14:41:08 +0200 (MEST) To: "Jeremy Fincher" Cc: caml-list@pauillac.inria.fr Subject: Re: [Caml-list] Possible function to add to Hashtbl? In-Reply-To: References: X-Mailer: VM 6.49 under Emacs 20.4.1 Reply-To: Jean-Christophe.Filliatre@lri.fr (Jean-Christophe Filliatre) Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk > 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 = try 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