[plt-scheme] hash_table_set

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Fri Dec 5 22:14:20 EST 2003

At Fri, 05 Dec 2003 21:22:26 -0500, Pedro Pinto wrote:
> But this:
>    Scheme_Hash_Table* myStore = scheme_make_hash_table(SCHEME_hash_ptr);
>    Scheme_Object *p = scheme_make_integer(12);
>    scheme_hash_set(myStore,p,scheme_make_integer(1));
>    scheme_hash_set(myStore,p,NULL);
>    assert (myStore->count == 0);
> fails (myStore->count is 1)
> Am I missing something here? My goal is to remove p from the list of keys.

The problem is that the `count' field wasn't right. I've fixed this.
The key did get unmapped in your example, though.

Lots of details:

The `count' field actually contained the number of non-NULL values in
the key array. When you delete something from the hash table, the key
gets replaced by a "nothing here" value which indicates that the slot
can be re-used, but that double-hashing searches should look further.

I've changed MzScheme so that `count' really does contain the number of
mapped keys, as documented. It turns out that `equal?' was broken on
hash tables passed to `hash-table-remove!', due to the `count'

For bucket tables --- normally used for weakly held keys --- the
`count' field is now documented to be the number of buckets, which is
>= the number of mapped keys. This field's meaning can't be changed,
because weakly held keys disappear without a specific hash table
option. For these kinds of tables, I had to change the implementation
of `equal?'.


Posted on the users mailing list.