[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Hash-Tables and :test #'equalp
Date: Thu, 26 Mar 1992 09:57 EST
From: rm@ki2.informatik.uni-hamburg.de (Ralf Moeller)
Since I want to use vectors as hash keys, #'equalp should be the right
:test predicate (according to CLtL2 this should work).
Symbolics Common Lisp currently only supports the language specified in
the original CLtL. There are some CLtL2 features in the
FUTURE-COMMON-LISP package, but not this particular one.
However, SCL
(Genera 8.1) requires a :hash-function be specified when :test #'equalp
is supplied. Is there anybody who wrote such a function for SCL?
Thanks for any comments.
The following should be pretty close. It doesn't handle all the cases
that EQUALP handles specially. However, SXHASH always returns the same
value for objects of those types, so you won't ever lose track of them
(using them as keys will be inefficient, though).
(defun equalp-hash (object)
(typecase object
;; Strings and characters are compared case-insensitively
(string (sxhash (string-downcase object)))
(character (sxhash (char-downcase object)))
;; Numbers are compared type-insensitively
(number (sxhash (coerce object '(complex long-float))))
;; Recurse into arrays.
(array
(stack-let ((temp (make-array (array-total-size object) :displaced-to object
:element-type (array-element-type object))))
(reduce #'logxor temp :key #'equalp-hash
;; Add a "randomizing" factor
:initial-value (sxhash 12345))))
(t (sxhash object))))