From 525178581e263d109f4620f742714ab3679ddf14 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Thu, 28 Jun 2018 06:09:25 -0700 Subject: genman: use hash function written in Lisp. Planning to support seeded hashing, so the behavior of the hashing function will change. But we need a stable hash for the section URL's in the HTML doc; so let's preserve the existing function as Lisp code. * genman.txr (hash-str): New string hashing function. This behaves like the existing hash-equal behaves on 32 bits. (hash-title): Use hash-str instead of hash-equal. --- genman.txr | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/genman.txr b/genman.txr index 31084dfa..58088e8e 100644 --- a/genman.txr +++ b/genman.txr @@ -14,10 +14,14 @@ (defvarl disamb (hash :equal-based)) (defvarl dist-counter 0) - (sys:set-hash-str-limit 1000) + (defun hash-str (str) + (for ((lim (len str)) (i 0) (h 0) g) ((< i lim) h) ((inc i)) + (set h (+ (ash h 4) (int-chr [str i]))) + (set g (logand h #x7c000000)) + (set h (logtrunc (logxor h (logxor (ash g -26) g)) 32)))) (defun hash-title (title) - (let* ((h (logtrunc (hash-equal title) 32)) + (let* ((h (logtrunc (hash-str title) 32)) (existing [dupes h])) (when existing (unless (equal title existing) -- cgit v1.2.3