mirror of git://bitreich.org/reed-alert
add Fowler Noll Vo hash function
This commit is contained in:
parent
3f03224030
commit
1b2f15bf29
|
@ -10,6 +10,18 @@
|
|||
(defparameter *green* (color 1 32))
|
||||
(defparameter *yellow* (color 0 33))
|
||||
|
||||
;; simple hash function (Fowler Noll Vo)
|
||||
;; https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function
|
||||
(defun fnv-hash(string)
|
||||
"return a hash from a string"
|
||||
(let ((FNV_prime 2)
|
||||
(hash 26123230013))
|
||||
(loop for octet-of-data across string
|
||||
do
|
||||
(setf hash (* FNV_prime
|
||||
(logxor hash (char-code octet-of-data)))))
|
||||
hash))
|
||||
|
||||
;; common-lisp don't have a split string function natively
|
||||
(defun replace-all (string part replacement &key (test #'char=))
|
||||
(with-output-to-string (out)
|
||||
|
@ -72,8 +84,9 @@
|
|||
(or ,@body)))
|
||||
|
||||
(defun =>(level fonction &rest params)
|
||||
(format t "[~a~a ~20A~a] ~35A" *yellow* level fonction *white* (getf params :desc params))
|
||||
(let ((result (funcall fonction params)))
|
||||
(format t "[~a~a ~20A~a] ~45A" *yellow* level fonction *white* (getf params :desc params))
|
||||
(let ((hash (fnv-hash (format nil "~{~a~}" (nconc (list level fonction) (remove-if #'symbolp params)))))
|
||||
(result (funcall fonction params)))
|
||||
(if (not (listp result))
|
||||
(progn
|
||||
(format t " => ~asuccess~a~%" *green* *white*)
|
||||
|
|
Loading…
Reference in New Issue