From 5994a8fec4525010a9a4d97c806070c0be4c99d6 Mon Sep 17 00:00:00 2001 From: Rose Hogenson Date: Tue, 26 Jul 2022 21:00:43 -0700 Subject: Slightly improve the hash function. --- csc/hash-map.csc | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'csc') diff --git a/csc/hash-map.csc b/csc/hash-map.csc index 064b4ae..682fa30 100644 --- a/csc/hash-map.csc +++ b/csc/hash-map.csc @@ -217,7 +217,7 @@ (define (shuffle n) - (truncate-remainder + (remainder (* #x9e3779b97f4a7c55 n) #x10000000000000000)) @@ -291,11 +291,12 @@ (define (hash-bytevector b) - (let loop ((i 0) - (hash 0)) - (if (>= i (bytevector-length b)) - hash - (loop (+ 1 i) (+ (* hash #x100) (bytevector-u8-ref b i)))))) + (loop for i from 0 below (bytevector-length b) + with hash = 0 + do (set! hash (remainder + (+ (* hash #x100) (bytevector-u8-ref b i)) + #x10000000000000000)) + finally (return hash))) (define compare-symbols -- cgit v1.3.1