18.3. Macro EXT:DEFINE-HASH-TABLE-TEST

You can define a new hash table test using the macro EXT:DEFINE-HASH-TABLE-TEST: (EXT:DEFINE-HASH-TABLE-TEST test-name test-function hash-function), after which name can be passed as the :TEST argument to MAKE-HASH-TABLE. E.g.:

(EXT:DEFINE-HASH-TABLE-TEST string STRING= SXHASH)
⇒ STRING
(MAKE-HASH-TABLE :test 'string)
⇒ #S(HASH-TABLE :TEST (#<SYSTEM-FUNCTION STRING=> . #<SYSTEM-FUNCTION SXHASH>))

(which is not too useful because it is equivalent to an EQUAL HASH-TABLE but less efficient).

The fundamental requirement is that the test-function and hash-function are consistent:

(FUNCALL test-function x y) ⇒
(= (FUNCALL hash-function x) (FUNCALL hash-function y))

This means that the following definition:

(EXT:DEFINE-HASH-TABLE-TEST number = SXHASH)broken!

is not correct because

(= 1 1d0)
⇒ Tsame object!
(= (SXHASH 1) (SXHASH 1d0))
⇒ NILdifferent buckets!

The correct way is, e.g.:

(EXT:DEFINE-HASH-TABLE-TEST number = (LAMBDA (x) (SXHASH (COERCE x 'SHORT-FLOAT))))

Note

Note that COERCEing to a SHORT-FLOAT does not cons up fresh objects while COERCEing to a DOUBLE-FLOAT does.


These notes document CLISP version 2.49Last modified: 2010-07-07