MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / hashString

Function hashString

packages/core/fumadb/src/utils/hash.ts:4–23  ·  view source on GitHub ↗
(str: string)

Source from the content-addressed store, hash-verified

2 * @returns 64-bit integer as hex string
3 */
4export function hashString(str: string) {
5 let hash1 = 0xdeadbeefn; // First 32-bit seed
6 let hash2 = 0x41c6ce57n; // Second 32-bit seed
7 const prime = 0x1000193n; // Large prime for multiplication
8 const mask = 0xffffffffn; // 32-bit mask
9
10 for (let i = 0; i < str.length; i++) {
11 const char = BigInt(str.charCodeAt(i));
12 // Update hash1: multiply by prime, add character, and rotate
13 hash1 = (hash1 * prime) ^ char;
14 hash1 = ((hash1 << 5n) | (hash1 >> 27n)) & mask; // Rotate left 5 bits
15 // Update hash2: XOR with character and multiply by prime
16 hash2 = (hash2 ^ char) * prime;
17 hash2 = ((hash2 << 7n) | (hash2 >> 25n)) & mask; // Rotate left 7 bits
18 }
19
20 // Combine both hashes into a 64-bit result
21 const combined = (hash1 << 32n) | hash2;
22 return combined.toString(16).padStart(16, "0");
23}

Callers

nothing calls this directly

Calls 1

toStringMethod · 0.80

Tested by

no test coverage detected