mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-21 11:10:42 +00:00
djb2
This commit is contained in:
+5
-4
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user