import { mul64 } from "./util.ts";
const offset64Lo = 2216829733;const offset64Hi = 3421674724;const prime64Lo = 435;const prime64Hi = 256;
abstract class Fnv64Base<T> { #stateHi: number; #stateLo: number;
constructor() { this.#stateHi = offset64Hi; this.#stateLo = offset64Lo; }
protected _updateState([newStateHi, newStateLo]: [number, number]) { this.#stateHi = newStateHi; this.#stateLo = newStateLo; }
reset() { this.#stateHi = offset64Hi; this.#stateLo = offset64Lo; }
abstract write(data: Uint8Array): T;
size(): number { return 8; }
blockSize(): number { return 1; }
sum64(): [number, number] { return [this.#stateHi, this.#stateLo]; }
sum(): Uint8Array { return Uint8Array.from([ (this.#stateHi >> 24) & 0xff, (this.#stateHi >> 16) & 0xff, (this.#stateHi >> 8) & 0xff, this.#stateHi & 0xff, (this.#stateLo >> 24) & 0xff, (this.#stateLo >> 16) & 0xff, (this.#stateLo >> 8) & 0xff, this.#stateLo & 0xff, ]); }}
export class Fnv64 extends Fnv64Base<Fnv64> { write(data: Uint8Array): Fnv64 { let [hashHi, hashLo] = this.sum64();
data.forEach((c) => { [hashHi, hashLo] = mul64([hashHi, hashLo], [prime64Hi, prime64Lo]); hashLo ^= c; });
this._updateState([hashHi, hashLo]); return this; }}
export class Fnv64a extends Fnv64Base<Fnv64a> { write(data: Uint8Array): Fnv64 { let [hashHi, hashLo] = this.sum64();
data.forEach((c) => { hashLo ^= c; [hashHi, hashLo] = mul64([hashHi, hashLo], [prime64Hi, prime64Lo]); });
this._updateState([hashHi, hashLo]); return this; }}