[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
emptying an hashtable
Date: 31 May 90 8:51 +0100
Received: from eldi.epfl.ch by SIC.Epfl.CH with VMSmail ; Thu, 31 May 90 08:51:56 N
I use a lot of hashtables having the form described below:
(make-hash-table :test #'equal
When I have to empty them, I use the following function:
(defun reset-hashtable (table)
(maphash #'(lambda (key value)
(declare (ignore value))
(remhash key table))
Both declarations correspond to the description in the chapter 16 of ClTl,
and everything works well.
But, I had another slightly different table:
(make-hash-table :test #'eq ; instead of EQUAL
From the CLtl, EQ is also usable. But, When I tried to empty *another-table*,
only one element was removed. I had to recreate it with the test being EQUAL
so that my procedure worked.
Is this a bug (maybe known) or did I misunderstand something?
One possibility is that an ephemeral garbage collection occurred during the
MAPHASH, and it reordered the elements of the table, causing some
elements to be missed. If I'm right, I think this is a bug --
GC-dependent hash tables should not allow a GC during a MAPHASH.
However, Common Lisp has a built-in function CLRHASH which should do
what you want in this particular case.