add Fowler Noll Vo hash function - reed-alert - Lightweight agentless alerting system for server HTML git clone git://bitreich.org/reed-alert/ git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65d7roiv6bfj7d652fid.onion/reed-alert/ DIR Log DIR Files DIR Refs DIR Tags DIR README DIR LICENSE --- DIR commit 1b2f15bf2974f893f7dd55ff6b4742dd0c0430d2 DIR parent 3f03224030fd0b48e2de384f56c78834da14643b HTML Author: Solene Rapenne <solene@perso.pw> Date: Wed, 17 Jan 2018 07:57:38 +0100 add Fowler Noll Vo hash function Diffstat: M functions.lisp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) --- DIR diff --git a/functions.lisp b/functions.lisp @@ -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*)