diff options
author | 2023-08-08 03:30:05 -0300 | |
---|---|---|
committer | 2023-08-07 23:30:05 -0700 | |
commit | 182e600eb79655e85b3f0371bc46fc4de8e70094 (patch) | |
tree | b91231bc9155cc769cc81a7b2f0892c47bd26d2c /docs | |
parent | cb873cc0818d02216ac7285c58fe59883220d1a9 (diff) | |
download | bun-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 'docs')
-rw-r--r-- | docs/api/hashing.md | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/docs/api/hashing.md b/docs/api/hashing.md index 3c15e1346..13a285693 100644 --- a/docs/api/hashing.md +++ b/docs/api/hashing.md @@ -77,7 +77,7 @@ The standard `Bun.hash` functions uses [Wyhash](https://github.com/wangyi-fudan/ ```ts Bun.hash("some data here"); -// 976213160445840 +// 11562320457524636935n ``` The input can be a string, `TypedArray`, `DataView`, `ArrayBuffer`, or `SharedArrayBuffer`. @@ -91,14 +91,14 @@ Bun.hash(arr.buffer); Bun.hash(new DataView(arr.buffer)); ``` -Optionally, an integer seed can be specified as the second parameter. +Optionally, an integer seed can be specified as the second parameter. For 64-bit hashes seeds above `Number.MAX_SAFE_INTEGER` should be given as BigInt to avoid loss of precision. ```ts Bun.hash("some data here", 1234); -// 1173484059023252 +// 15724820720172937558n ``` -Additional hashing algorithms are available as properties on `Bun.hash`. The API is the same for each. +Additional hashing algorithms are available as properties on `Bun.hash`. The API is the same for each, only changing the return type from number for 32-bit hashes to bigint for 64-bit hashes. ```ts Bun.hash.wyhash("data", 1234); // equivalent to Bun.hash() @@ -107,6 +107,7 @@ Bun.hash.adler32("data", 1234); Bun.hash.cityHash32("data", 1234); Bun.hash.cityHash64("data", 1234); Bun.hash.murmur32v3("data", 1234); +Bun.hash.murmur32v2("data", 1234); Bun.hash.murmur64v2("data", 1234); ``` |