feat: some moving around

This commit is contained in:
2024-04-15 22:13:43 +02:00
parent 0254bc1ae5
commit dec205b234
86 changed files with 505 additions and 409 deletions

View File

@ -0,0 +1,11 @@
import { test, expect } from 'vitest';
import fastHash from './fastHash';
test('Hashes dont clash', () => {
const hashA = fastHash('abcdef');
const hashB = fastHash('abcde');
const hashC = fastHash('abcde');
expect(hashA).not.toEqual(hashB);
expect(hashB).toEqual(hashC);
});

View File

@ -0,0 +1,14 @@
// Shamelessly copied from
// https://stackoverflow.com/a/8831937
export default function (input: string) {
if (input.length === 0) return 0;
let hash = 0;
for (let i = 0; i < input.length; i++) {
hash = (hash << 5) - hash + input.charCodeAt(i);
hash = hash & hash;
}
return hash;
}