1 (uiop:define-package
#:lw2.hash-utils
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
)
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
))
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)
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)))))))