Mercurial > core / lisp/lib/obj/hash/hasher.lisp
changeset 698: |
96958d3eb5b0 |
parent: |
9fa3b9154bb2
|
author: |
Richard Westhaver <ellis@rwest.io> |
date: |
Fri, 04 Oct 2024 22:04:59 -0400 |
permissions: |
-rw-r--r-- |
description: |
fixes |
1 ;;; lib/obj/hash/hasher.lisp --- Hash Functions 9 (defvar *global-hasher* #'sxhash)) 11 ;; TODO 2024-05-24: do better 12 (sb-ext:define-load-time-global *global-hash* (funcall *global-hasher* (get-universal-time))) 14 (macrolet ((specialize (str body) ; TODO 2023-12-21: test if this actually compiles to fastpath 15 `(if (typep ,str '(simple-array character 1)) 19 (declare (string string) 22 (declare ((and unsigned-byte fixnum) hash)) 25 (dotimes (n (min 6 (length string))) 27 (logand most-positive-fixnum 29 (char-code (schar string n))))))) 32 (defgeneric hash-object (obj) 34 (hash-object-address obj))) 36 (defun hash-object-address (obj &optional (test *global-hasher*)) 37 "Given some object OBJ, lookup the address with 38 SB-KERNEL:GET-LISP-OBJ-ADDRESS and return a hash." 39 (funcall test (sb-kernel:get-lisp-obj-address obj))) 41 (defun object-address-hash-equalp (a b) 42 (= (hash-object-address a) (hash-object-address b))) 44 (sb-ext:define-hash-table-test object-address-hash-equalp hash-object-address) 47 (defun dumb-string-hash (str) 48 "Produce a six-character hash of STRING." 49 (let ((hash #xD13CCD13)) 50 (loop for char across str 51 for value = (char-code char) 53 (setf hash (logand #xFFFFFFFF 57 (subseq (format nil "~(~36,6,'0R~)" (mod hash 88888901)) 60 ;; sb-lockless::multiplicative-hash 64 ;; (setq *h* (sb-c:make-perfect-hash-lambda 65 ;; (map '(array (unsigned-byte 32) 1) (lambda (x) (ldb (byte 32 0) (sxhash x))) 66 ;; '(a b c d e f g h i j k l m n o p))))