diff options
| author | 2022-03-30 18:57:08 -0700 | |
|---|---|---|
| committer | 2022-03-30 18:57:08 -0700 | |
| commit | b09a22aaf589afff2b01fbed2751ab537475ea4a (patch) | |
| tree | 4b119c2370ed38c9bd76782e771a7af432040531 /examples | |
| parent | ba3a7c2bcf548c5473b2b5b3656efef553947dcd (diff) | |
| download | bun-b09a22aaf589afff2b01fbed2751ab537475ea4a.tar.gz bun-b09a22aaf589afff2b01fbed2751ab537475ea4a.tar.zst bun-b09a22aaf589afff2b01fbed2751ab537475ea4a.zip | |
Add bun.hash example
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/bun/hashing.js | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/examples/bun/hashing.js b/examples/bun/hashing.js new file mode 100644 index 000000000..cf4772ffe --- /dev/null +++ b/examples/bun/hashing.js @@ -0,0 +1,18 @@ +// Accepts a string, TypedArray, or Blob (file blob supported 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)); + +// Second argument accepts a seed where relevant +console.log(Bun.hash(input, 12345)); |
