Debug and optimize token-bucket-decrement.
[lw2-viewer.git] / src / hash-utils.lisp
blob4c331911c210417b149cf602f05a126fe784a180
1 (uiop:define-package #:lw2.hash-utils
2 (:use #:cl #:iter)
3 (:import-from #:flexi-streams #:string-to-octets #:octets-to-string #:with-output-to-sequence)
4 (:export #:city-hash-128-vector #:hash-string #:hash-printable-object #:hash-file-list)
5 (:recycle #:lw2.lmdb))
7 (in-package #:lw2.hash-utils)
9 (defun city-hash-128-vector (data)
10 (let ((array (make-array 16 :element-type '(unsigned-byte 8))))
11 (multiple-value-bind (r1 r2) (city-hash:city-hash-128
12 (coerce data '(simple-array (unsigned-byte 8) (*))))
13 (setf (nibbles:ub64ref/be array 0) r1
14 (nibbles:ub64ref/be array 8) r2))
15 array))
17 (defun hash-string (string)
18 (city-hash-128-vector (string-to-octets string :external-format :utf-8)))
20 (defun hash-printable-object (object)
21 (hash-string (write-to-string object :circle nil :escape nil :pretty nil)))
23 (defun hash-file-list (file-list)
24 (city-hash-128-vector
25 (with-output-to-sequence (out-stream)
26 (iter (for f in file-list)
27 (with-open-file (in-stream (asdf:system-relative-pathname :lw2-viewer f) :direction :input :element-type '(unsigned-byte 8))
28 (uiop:copy-stream-to-stream in-stream out-stream :element-type '(unsigned-byte 8)))))))