deno.land / std@0.157.0 / crypto / _fnv / fnv64.ts

نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// Ported from Go:// https://github.com/golang/go/tree/go1.13.10/src/hash/fnv/fnv.go// Copyright 2011 The Go Authors. All rights reserved. BSD license.// https://github.com/golang/go/blob/master/LICENSE// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.// This module is browser compatible.
import { mul64, swap32 } from "./util.ts";
const prime64Lo = 435;const prime64Hi = 256;
export const fnv64 = (data: Uint8Array): ArrayBuffer => { let hashLo = 2216829733; let hashHi = 3421674724;
data.forEach((c) => { [hashHi, hashLo] = mul64([hashHi, hashLo], [prime64Hi, prime64Lo]); hashLo ^= c; });
return new Uint32Array([swap32(hashHi >>> 0), swap32(hashLo >>> 0)]).buffer;};
export const fnv64a = (data: Uint8Array): ArrayBuffer => { let hashLo = 2216829733; let hashHi = 3421674724;
data.forEach((c) => { hashLo ^= c; [hashHi, hashLo] = mul64([hashHi, hashLo], [prime64Hi, prime64Lo]); });
return new Uint32Array([swap32(hashHi >>> 0), swap32(hashLo >>> 0)]).buffer;};
std
Deno standard library
GitHub Repositorydenoland/deno_std
GitHub Stars
2458

Version Info

Tagged at
4 months ago