Mercurial > core / lisp/lib/obj/hash/hasher.lisp
changeset 207: |
e48427b30ecd |
parent: |
85f27597cf60
|
child: |
1741660af6e9 |
author: |
Richard Westhaver <ellis@rwest.io> |
date: |
Thu, 15 Feb 2024 20:35:16 -0500 |
permissions: |
-rw-r--r-- |
description: |
lisp stuff, nu test stuff, back on stable support for rust |
1 ;;; lib/obj/hash/hasher.lisp --- Hash Functions 8 (defvar *global-hasher* #'sxhash)) 10 (defconstant +global-hash+ 11 (if (boundp '+global-hash+) 13 (funcall *global-hasher* (get-universal-time)))) 15 (macrolet ((specialize (str body) ; TODO 2023-12-21: test if this actually compiles to fastpath 16 `(if (typep ,str '(simple-array character 1)) 20 (declare (string string) 23 (declare ((and unsigned-byte fixnum) hash)) 26 (dotimes (n (min 6 (length string))) 28 (logand most-positive-fixnum 30 (char-code (schar string n))))))) 33 (defun hash-object-address (obj &optional (test *global-hasher*)) 34 "Given some object OBJ, lookup the address with 35 SB-KERNEL:GET-LISP-OBJ-ADDRESS and return a hash." 36 (funcall test (sb-kernel:get-lisp-obj-address obj))) 38 (defun object-address-hash-equalp (a b) 39 (= (hash-object-address a) (hash-object-address b))) 42 (defun dumb-string-hash (string) 43 "Produce a six-character hash of STRING." 44 (let ((hash #xD13CCD13)) 45 (loop for char across string 46 for value = (char-code char) 48 (setf hash (logand #xFFFFFFFF 52 (subseq (format nil "~(~36,6,'0R~)" (mod hash 88888901)) 55 (sb-ext:define-hash-table-test object-address-hash-equalp hash-object-address) 57 (defgeneric hash-object (obj))