Comment 5 for bug 1712130

Revision history for this message
Douglas Katzman (dougk) wrote :

+MAX-HASH-DEPTHOID+ isn't a "default". Bad things would happen if it were changed in a running system.

As a practical matter, hash keys that are lists that are the same up to 10 items are probably bad hash keys. Nevertheless you could rebuild from source with a changed value.

But you can do better than that. For example - and I'm not suggesting that you use system-internal functions, I'm just showing what is possible, given this:
(defun myhashfn (x)
  (sb-int:named-let h ((x x))
   (typecase x
    (fixnum x)
    (list
     (if x
        (sb-int:mix (the fixnum (h (car x)))
                    (the fixnum (h (cdr x))))
        0)))))

(let ((cache (make-hash-table :test test :hash-function 'myhashfn))) ; do this
and then: (time(ff 18))
Evaluation took:
  3.414 seconds of real time

Two other things I'll mention:
- There are somewhere between dozens and hundreds of build-time parameters most of which should not have to be touched; I don't think the right place to start touching them is observing that some lists hash badly under the default SXHASH, and question what else you can tweak.
- I kind of agree that in general 4 as the cutoff is probably a value that hasn't been adjusted in 20 years, and makes the wrong trade-off in time to compute the hash versus time to compare keys.

But as you can see, implementing an abstract memoize function isn't as simple as just using a builtin thing unspecific to your problem.