deno.land / std@0.224.0 / crypto / _fnv / fnv32.ts

View Documentation
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
// 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-2024 the Deno authors. All rights reserved. MIT license.// This module is browser compatible.
import { mul32, swap32 } from "./util.ts";
const prime32 = 16777619;
export const fnv32 = (data: Uint8Array): ArrayBuffer => { let hash = 2166136261;
data.forEach((c) => { hash = mul32(hash, prime32); hash ^= c; });
return Uint32Array.from([swap32(hash)]).buffer;};
export const fnv32a = (data: Uint8Array): ArrayBuffer => { let hash = 2166136261;
data.forEach((c) => { hash ^= c; hash = mul32(hash, prime32); });
return Uint32Array.from([swap32(hash)]).buffer;};
std

Version Info

Tagged at
6 months ago