Ports
Choose your language for installation and examples. All implementations
at the same version produce the same hash for the same bytes and
seed. The 128-bit result contains lo and hi;
lo equals the 64-bit hash.
Experimental: hash values can change between releases. Pin your version and check the stability policy.
C / C++ · Rust · Go · Zig · Java · C# · Python · Swift · JS / TS · Haskell · MIPS64 · Streaming
The snippets use buf for input bytes and
seed for a 64-bit seed.
C / C++
Copy the header into your project. It has no dependencies. Each release includes the header as an asset:
curl -LO https://github.com/thevilledev/hayahash/releases/latest/download/hayahash.h
#include "hayahash.h"
uint64_t h = hayahash64(buf, len, seed);
hayahash128_t h128 = hayahash128(buf, len, seed);
Rust
The hayahash crate is on
crates.io. It is
no_std compatible:
cargo add hayahash
let h = hayahash::hayahash64(buf, seed);
let h128 = hayahash::hayahash128(buf, seed);
Go
The module is
github.com/thevilledev/hayahash/go:
go get github.com/thevilledev/hayahash/go
import hayahash "github.com/thevilledev/hayahash/go"
h := hayahash.Hash64(buf, seed)
h128 := hayahash.Hash128(buf, seed)
Zig
The port needs Zig 0.16. Get the module from the release:
zig fetch --save https://github.com/thevilledev/hayahash/releases/download/v0.5.0/hayahash-zig-0.5.0.tar.gz
Then add this to build.zig:
const hayahash = b.dependency("hayahash", .{});
exe.root_module.addImport("hayahash", hayahash.module("hayahash"));
const hayahash = @import("hayahash");
const h = hayahash.hayahash64(buf, seed);
const h128 = hayahash.hayahash128(buf, seed);
Java
io.github.thevilledev:hayahash
is on Maven Central. It needs Java 17 or later:
<dependency>
<groupId>io.github.thevilledev</groupId>
<artifactId>hayahash</artifactId>
<version>0.5.0</version>
</dependency>
import io.github.thevilledev.hayahash.Hayahash;
long h = Hayahash.hash64(buf, seed);
Hayahash.Hash128 h128 = Hayahash.hash128(buf, seed);
C# / .NET
The Hayahash
package is on NuGet. It needs .NET 8 or later:
dotnet add package Hayahash
using Hayahash;
ulong h = Hayahash.Hash64(buf, seed);
Digest128 h128 = Hayahash.Hash128(buf, seed);
Python
The hayahash
package is on PyPI. It needs CPython 3.9 or later. A C extension
wraps the reference header. Releases include wheels for Linux
(manylinux and musllinux), Windows, and macOS:
pip install hayahash
from hayahash import hayahash128, hayahash64
h = hayahash64(buf, seed)
h128 = hayahash128(buf, seed) # (lo, hi)
Swift
Requires Swift 5.9+. Use the SwiftPM package as a local dependency, or extract the Swift release archive.
import Hayahash
let h = Hayahash.hash64(buf, seed: 0)
let h128 = Hayahash.hash128(buf, seed: 0)
JavaScript / TypeScript
The npm package uses WebAssembly with a pure-JS fallback.
npm install hayahash
import { hayahash128, hayahash64 } from "hayahash";
const h = hayahash64(buf, seed); // unsigned 64-bit BigInt
const h128 = hayahash128(buf, seed); // { lo, hi }
Haskell
Requires GHC 8.10+. Build the Cabal package from the repository:
git clone https://github.com/thevilledev/hayahash.git
cabal build ./hayahash/haskell
import Data.Hash.Hayahash
h = hayahash64 buf seed
h128 = hayahash128 buf seed
MIPS64 assembly
Copy mips/hayahash.S
and its header into your build. Uses the n64 ABI.
#include "hayahash.h" /* mips/hayahash.h */
uint64_t h = hayahash64(buf, len, seed);
hayahash128_t h128 = hayahash128(buf, len, seed);
Streaming
Use streaming when input arrives in chunks. Any split produces the same digest as hashing the complete input. Taking a digest leaves the state available for more updates.
hayahash64_state st;
hayahash64_init(&st, 0);
hayahash64_update(&st, "hel", 3);
hayahash64_update(&st, "lo", 2);
uint64_t h = hayahash64_digest(&st);
hayahash128_t h128 = hayahash128_digest(&st);
Streaming APIs by language. The MIPS64 assembly port has one-shot APIs only.
Source and tests
See the repository layout
and conformance checks.
hayahash.h
is the authoritative reference.