aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorGravatar jhmaster <32803471+jhmaster2000@users.noreply.github.com> 2023-08-08 03:30:05 -0300
committerGravatar GitHub <noreply@github.com> 2023-08-07 23:30:05 -0700
commit182e600eb79655e85b3f0371bc46fc4de8e70094 (patch)
treeb91231bc9155cc769cc81a7b2f0892c47bd26d2c /examples
parentcb873cc0818d02216ac7285c58fe59883220d1a9 (diff)
downloadbun-182e600eb79655e85b3f0371bc46fc4de8e70094.tar.gz
bun-182e600eb79655e85b3f0371bc46fc4de8e70094.tar.zst
bun-182e600eb79655e85b3f0371bc46fc4de8e70094.zip
Fix `Bun.hash` functions (#4054)
* fix `Bun.hash` functions to behave as expected * update Bun.hash tests * properly test the returned hash * include murmur32v2 * update Bun.hash docs * run fmt
Diffstat (limited to 'examples')
-rw-r--r--examples/hashing.js19
1 files changed, 10 insertions, 9 deletions
diff --git a/examples/hashing.js b/examples/hashing.js
index cf4772ffe..3f23d1312 100644
--- a/examples/hashing.js
+++ b/examples/hashing.js
@@ -1,18 +1,19 @@
-// Accepts a string, TypedArray, or Blob (file blob supported is not implemented but planned)
+// Accepts a string, TypedArray, or Blob (file blob support is not implemented but planned)
const input = "hello world".repeat(400);
// Bun.hash() defaults to Wyhash because it's fast
console.log(Bun.hash(input));
console.log(Bun.hash.wyhash(input));
-// and returns a number
-// all of these hashing functions return numbers, not typed arrays.
-console.log(Bun.hash.adler32(input));
-console.log(Bun.hash.crc32(input));
-console.log(Bun.hash.cityHash32(input));
-console.log(Bun.hash.cityHash64(input));
-console.log(Bun.hash.murmur32v3(input));
-console.log(Bun.hash.murmur64v2(input));
+// and returns a bigint
+// all of these hashing functions return number if 32-bit or bigint if 64-bit, not typed arrays.
+console.log(Bun.hash.adler32(input)); // number
+console.log(Bun.hash.crc32(input)); // number
+console.log(Bun.hash.cityHash32(input)); // number
+console.log(Bun.hash.cityHash64(input)); // bigint
+console.log(Bun.hash.murmur32v3(input)); // number
+console.log(Bun.hash.murmur32v2(input)); // number
+console.log(Bun.hash.murmur64v2(input)); // bigint
// Second argument accepts a seed where relevant
console.log(Bun.hash(input, 12345));