Browse thread
[Caml-list] Possible function to add to Hashtbl?
-
Jeremy Fincher
- Jean-Christophe Filliatre
[
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: | 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 =
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