caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jean-Christophe Filliatre <Jean-Christophe.Filliatre@lri.fr>
To: "Jeremy Fincher" <tweedgeezer@hotmail.com>
Cc: caml-list@pauillac.inria.fr
Subject: Re: [Caml-list] Possible function to add to Hashtbl?
Date: Fri, 19 Oct 2001 14:41:08 +0200 (MEST)	[thread overview]
Message-ID: <15312.8036.484382.801683@pc803> (raw)
In-Reply-To: <F218UXPdvgyf2M0KFHR0000c8f2@hotmail.com>


 > 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


      reply	other threads:[~2001-10-19 12:41 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-10-19  4:20 Jeremy Fincher
2001-10-19 12:41 ` Jean-Christophe Filliatre [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=15312.8036.484382.801683@pc803 \
    --to=jean-christophe.filliatre@lri.fr \
    --cc=caml-list@pauillac.inria.fr \
    --cc=tweedgeezer@hotmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).