Open History to see the last commit
1const FNV_OFFSET_BASIS_32 = 0x811c9dc5;
2const FNV_PRIME_32 = 0x01000193;
3const SECONDARY_HASH_SEED = 0x9e3779b9;
4const SECONDARY_HASH_MULTIPLIER = 0x85ebca6b;
5
6function fnv1a32(input: string, seed: number, multiplier: number): number {
7 let hash = seed >>> 0;
8 for (let index = 0; index < input.length; index += 1) {
9 hash ^= input.charCodeAt(index);
10 hash = Math.imul(hash, multiplier) >>> 0;
11 }
12 return hash >>> 0;
13}
14
15export function buildPatchCacheKey(patch: string, scope = "diff-panel"): string {
16 const normalizedPatch = patch.trim();
17 const primary = fnv1a32(normalizedPatch, FNV_OFFSET_BASIS_32, FNV_PRIME_32).toString(36);
18 const secondary = fnv1a32(
19 normalizedPatch,
20 SECONDARY_HASH_SEED,
21 SECONDARY_HASH_MULTIPLIER,
22 ).toString(36);
23 return `${scope}:${normalizedPatch.length}:${primary}:${secondary}`;
24}