EXT:DEFINE-HASH-TABLE-TEST
You can define a new hash table test using the macro
EXT:DEFINE-HASH-TABLE-TEST
: (
, after
which EXT:DEFINE-HASH-TABLE-TEST
test-name test-function
hash-function
)name
can be passed as the :TEST
argument to MAKE-HASH-TABLE
.
E.g.:
(EXT:DEFINE-HASH-TABLE-TEST
stringSTRING=
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) ⇒; same object! (
T
=
(SXHASH
1) (SXHASH
1d0)) ⇒; different buckets!
NIL
The correct way is, e.g.:
(EXT:DEFINE-HASH-TABLE-TEST
number=
(LAMBDA
(x) (SXHASH
(COERCE
x 'SHORT-FLOAT
))))
Note that COERCE
ing to a SHORT-FLOAT
does not cons up
fresh objects while COERCE
ing to a DOUBLE-FLOAT
does.
These notes document CLISP version 2.49.93+ | Last modified: 2018-02-19 |