[racket] empty hash tables

From: Eli Barzilay (eli at barzilay.org)
Date: Mon May 30 04:12:00 EDT 2011

10 minutes ago, Marijn wrote:
> while browsing both guide[1] and reference[2] for a `hash-empty?'
> procedure I turned up with empty hands, although a few possibilities
> for implementing it did come to mind, like using `hash-count' and
> comparing to zero or, using `hash-iterate-first' which returns #f
> for empty hashes but otherwise returns an integer which is an index
> to the first element in the hash table (which sounds like hash
> tables are implemented using arrays and an index to the underlying
> array is returned).

Marijn clarified on #racket that his concern with `hash-count' is that
the documentation implies that it's not a constant time operation:

  If hash is not created with 'weak, then the result is computed in
  constant time and atomically.

And looking at the code, it seem that that justifies a primitive

But then there's a reference to the caveats section, which might not
be needed since there's no modification involved.  (I guess that it's
because the table can change while it's being counted, but that would
be an issue for other read-only operations too.)

> PS Note how hash table is spelled differently in below URLs
> [1]:http://docs.racket-lang.org/guide/hash-tables.html
> [2]:http://docs.racket-lang.org/reference/hashtables.html

He also clarified that the difference is in the spelling of the HTML
file name.  It's easy to fix, but I'm not sure that such a cosmetic
change is worth invalidating old links.

          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                    http://barzilay.org/                   Maze is Life!

Posted on the users mailing list.