From ab848a8984f87f8aa0c46e39402016fcc9f628f2 Mon Sep 17 00:00:00 2001 From: Scott Anderson <662325+scottanderson@users.noreply.github.com> Date: Wed, 4 Jun 2025 22:53:45 -0400 Subject: [PATCH] djb2 --- src/core/Util.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/core/Util.ts b/src/core/Util.ts index d78f7091d..a8d89756f 100644 --- a/src/core/Util.ts +++ b/src/core/Util.ts @@ -62,13 +62,14 @@ export function distSortUnit( } export function simpleHash(str: string): number { - let hash = 0; + // dbj2 is a fast string hashing function + let hash = 5381; for (let i = 0; i < str.length; i++) { const char = str.charCodeAt(i); - hash = (hash << 5) - hash + char; - hash = hash & hash; // Convert to 32-bit integer + // h = h * k + c (k=33) + hash = (hash << 5) + hash + char; } - return Math.abs(hash); + return hash >>> 0; // Coerce to 32-bit int } export function calculateBoundingBox(