stdlib.hash¶
Hashing
Generated from
v0.60.1. 16 source files, 94 documented symbols.
adler.xi¶
fn adler32(data: &Vec[UInt8]) -> UInt32¶
Computes the Adler-32 checksum over
data(RFC 1950). The empty input yields 1 (the initial A value). Check: adler32("Wikipedia") == 0x11E60398. Complexity: O(n).
fn adler32_str(s: Str) -> UInt32¶
Computes the Adler-32 checksum of the raw bytes of a string (its UTF-8 encoding, byte by byte). Complexity: O(n).
fn adler32_combine(a: UInt32, b: UInt32, len_b: Int) -> UInt32¶
Combines two Adler-32 checksums as if the blocks were concatenated:
acovers the first block,bcovers a second block oflen_bbytes. Returns 0xFFFFFFFF for a negativelen_b(zlib convention). Complexity: O(1).
checksum.xi¶
fn checksum_bsd(data: &Vec[UInt8]) -> UInt32¶
BSD sum: 16-bit checksum = rotate-right-1, then add each byte (mod 2^16). Complexity: O(n).
fn checksum_sysv(data: &Vec[UInt8]) -> UInt32¶
SysV sum: 16-bit accumulator that rotates right by one bit after each byte is added. Complexity: O(n).
fn checksum_internet(data: &Vec[UInt8]) -> UInt32¶
Internet one's-complement checksum (RFC 1071): the one's complement of the sum of 16-bit big-endian words, with end-around carry. Complexity: O(n).
fn checksum_fletcher16(data: &Vec[UInt8]) -> UInt16¶
Fletcher-16 checksum: two 8-bit accumulators modulo 255, sum1 = running sum of bytes, sum2 = running sum of sum1 values. The 16-bit result packs them as (sum2 << 8) | sum1. Complexity: O(n).
city.xi¶
fn city64(data: &Vec[UInt8]) -> UInt64¶
CityHash64 of a byte string.
fn city64_with_seed(data: &Vec[UInt8], seed: UInt64) -> UInt64¶
CityHash64WithSeed: HashLen16(CityHash64(s) - k2, seed).
fn city128(data: &Vec[UInt8]) -> Vec[UInt64]¶
CityHash128 of a byte string; returns [low, high].
crc.xi¶
fn crc64_ecma(data: &Vec[UInt8]) -> UInt64¶
CRC-64/ECMA of a byte string (reflected variant, init/xorout all-ones). Check: crc64_ecma("123456789") == 0x995DC9BBDF1939FA.
fn crc64_we(data: &Vec[UInt8]) -> UInt64¶
CRC-64/WE of a byte string (non-reflected, init/xorout all-ones). Check: crc64_we("123456789") == 0x62EC59E3F1A4F00A.
fn crc32c(data: &Vec[UInt8]) -> UInt32¶
CRC-32C (Castagnoli) of a byte string. Check: crc32c("123456789") == 0xE3069283.
fn crc16_ccitt(data: &Vec[UInt8]) -> UInt32¶
CRC-16/CCITT (FALSE) of a byte string. Check: crc16_ccitt("123456789") == 0x29B1.
fn checksum_bsd(data: &Vec[UInt8]) -> UInt32¶
BSD sum: 16-bit checksum = rotate-right-1 + byte per byte.
fn checksum_sysv(data: &Vec[UInt8]) -> UInt32¶
SysV sum: 16-bit accumulator with a rotate-right-1 after each byte.
fn checksum_internet(data: &Vec[UInt8]) -> UInt32¶
RFC 1071 Internet checksum: 16-bit one's complement of the sum of 16-bit big-endian words.
fn adler32(data: &Vec[UInt8]) -> UInt32¶
Adler-32 (RFC 1950). Verified against a clang-built reference (2026-08-11): "" -> 0x00000001, "a" -> 0x00620062, "abc" -> 0x024d0127, "Wikipedia" -> 0x11e60398 (matches the Wikipedia article).
farm.xi¶
fn farmhash64(data: &Vec[UInt8]) -> UInt64¶
FarmHash 64-bit digest over
data(no seed). Complexity: O(n).
fn farmhash64_seed(data: &Vec[UInt8], seed: UInt64) -> UInt64¶
FarmHash 64-bit digest with a single seed. Complexity: O(n).
fn farmhash64_seed2(data: &Vec[UInt8], seed1: UInt64, seed2: UInt64) -> UInt64¶
FarmHash 64-bit digest with two seeds. Complexity: O(n).
fn farmhash32(data: &Vec[UInt8]) -> UInt32¶
FarmHash 32-bit digest over
data(Murmur-style 4-byte mixing). Complexity: O(n).
fn farmhash128(data: &Vec[UInt8]) -> (UInt64, UInt64)¶
FarmHash 128-bit digest as two 64-bit words. Complexity: O(n).
fn farmhash128_seed(data: &Vec[UInt8], seed1: UInt64, seed2: UInt64) -> (UInt64, UInt64)¶
FarmHash 128-bit digest seeded with two 64-bit words. Complexity: O(n).
fn farmhash_fingerprint32(data: &Vec[UInt8]) -> UInt32¶
32-bit fingerprint, stable across runs for the same data. Complexity: O(n).
fn farmhash_fingerprint64(data: &Vec[UInt8]) -> UInt64¶
64-bit fingerprint, stable across runs for the same data. Complexity: O(n).
fn farmhash_fingerprint128(data: &Vec[UInt8]) -> (UInt64, UInt64)¶
128-bit fingerprint, stable across runs for the same data. Complexity: O(n).
fnv.xi¶
fn fnv1_128(data: &Vec[UInt8]) -> UInt128¶
FNV-1 128-bit hash: multiply first, then XOR each byte. Offset basis 0x6C62272E07BB014262B821756295C58D, prime 2^24 + 2^8 + 0x3B. Empty input yields the offset basis. Complexity: O(n).
fn fnv1a_128(data: &Vec[UInt8]) -> UInt128¶
FNV-1a 128-bit hash: XOR first, then multiply each byte. Empty input yields the offset basis. Complexity: O(n).
fn fnv1a_128_seed(data: &Vec[UInt8], seed: UInt128) -> UInt128¶
FNV-1a 128-bit hash starting from an explicit seed. The seed replaces the offset basis; a zero-length input yields the seed unchanged. Complexity: O(n).
fn fnv1a64(data: &Vec[UInt8]) -> UInt64¶
FNV-1a 64-bit hash (completeness companion to the 128-bit variants in this module). Offset basis 0xCBF29CE484222325, prime 0x100000001B3. Empty input yields the offset basis. Complexity: O(n).
hash.xi¶
type DefaultHasher¶
=== DefaultHasher -- DJB2-based concrete hasher ===
| Field | Type |
|---|---|
state |
Int |
Derives: Clone
fn new() -> DefaultHasher¶
Create a hasher with the default seed.
fn write(self: Self, bytes: &Vec[UInt8])¶
Feed bytes into the hasher.
fn write_int(self: Self, n: Int)¶
Feed an Int into the hasher.
fn write_str(self: Self, s: Str)¶
Feed the bytes of a string into the hasher.
fn finish(self: Self) -> Int¶
Finalize and return the 64-bit hash.
fn hash(self: Self) -> UInt64¶
=== Hash implementations for standard types === Full DJB2 hash computation. Each type hashes its bytes directly.
- Postcondition:
a == b => a.hash() == b.hash()
fn hash(self: Self) -> UInt64¶
Stable hash of a Bool.
fn hash_value[T](value: T) -> Int¶
=== Free functions === NOTE: these dispatch to the concrete 0-arg
.hash()methods (Int/Bool) like the siblinghashbelow. The hasher-basedHashinterface (hash(self, hasher)) is defined above but has no concrete impls yet; calling through it from a &T receiver produced invalid IR (ptr->i64) -- keep by-value params until the interface path is complete.
fn hash_combine(seed: Int, hash: Int) -> Int¶
Combine two hashes into one (order-dependent).
fn hash[T](value: T) -> UInt64¶
Hash any
Hash-implementing value.
fn sip_hash(data: &Vec[UInt8]) -> UInt64¶
SipHash-2-4 of the bytes (64-bit).
fn fnv1a32(data: &Vec[UInt8]) -> Int¶
FNV-1a 32-bit hash. Algorithm: hash = (hash XOR byte) * FNV Prime, with 32-bit wrapping. Offset basis: 0x811C9DC5, prime: 0x01000193. Complexity: O(n), n = data length. Security: Non-cryptographic. Excellent distribution for hash tables.
fn fnv1a64(data: &Vec[UInt8]) -> Int¶
FNV-1a 64-bit hash. Offset basis: 0xCBF29CE484222325, prime: 0x00000100000001B3. Complexity: O(n), n = data length.
fn fnv1_64(data: &Vec[UInt8]) -> Int¶
FNV-1 64-bit hash (multiply first, then XOR -- non-alternate variant). Offset basis: 0xCBF29CE484222325, prime: 0x00000100000001B3. Complexity: O(n), n = data length.
fn murmur3_32(data: &Vec[UInt8], seed: Int) -> Int¶
MurmurHash3 32-bit (x86_32 variant). Processes 4-byte blocks with fmix32 finalization. Test vector: murmur3_32("hello", 0) == 0x248BFA47. Complexity: O(n), n = data length. Security: Non-cryptographic. Good avalanche characteristics.
fn _rotl32(x: Int, r: Int) -> Int¶
Helper: rotates left within 32 bits.
fn xxhash32(data: &Vec[UInt8], seed: Int) -> Int¶
xxHash32 -- Yann Collet's fast non-cryptographic hash. Prime constants and avalanche per original xxHash specification. Complexity: O(n), n = data length. Processes 4-byte lanes + tail.
fn djb2(s: Str) -> Int¶
DJB2 string hash (Dan Bernstein). Start with 5381, for each char: hash = hash * 33 + char_code. Complexity: O(n), n = string length.
- Precondition:
true
fn sdbm(s: Str) -> Int¶
SDBM string hash. For each char: hash = char_code + (hash << 6) + (hash << 16) - hash. Complexity: O(n), n = string length.
- Precondition:
true
fn crc32_ieee(data: &Vec[UInt8]) -> Int¶
CRC32-IEEE 802.3 (polynomial 0xEDB88320, reflected). Generates lookup table lazily on first call. Complexity: O(n), n = data length.
fn hash_bytes_to_hex(data: &Vec[UInt8]) -> Str¶
Converts a byte vector to a lowercase hexadecimal string. Delegates to xiom.encoding.hex_encode.
fn combine_hashes(a: Int, b: Int) -> Int¶
Boost-style hash combination. Combines two hash values into one using a mixing function. Formula: a ^ (b + 0x9e3779b9 + (a << 6) + (a >> 2)).
fn string_hash(s: Str) -> Int¶
DJB2 hash over string characters. Alias for djb2.
fn xxhash64(data: &Vec[UInt8], seed: Int) -> Int¶
xxHash64 (seed 0 compatible with the reference implementation; 64-bit results wrap naturally in i64 arithmetic -- masks are no-ops at 64 bits).
fn fnv1_32(s: Str) -> Int¶
FNV-1 32-bit (multiply before XOR, unlike FNV-1a).
highway.xi¶
type Hh128¶
128-bit HighwayHash digest:
lowis the low 64 bits,highthe high.
| Field | Type |
|---|---|
low |
UInt64 |
high |
UInt64 |
fn highway64(data: &Vec[UInt8], key0: UInt64, key1: UInt64, key2: UInt64, key3: UInt64) -> UInt64¶
64-bit HighwayHash over
datawith a 256-bit key. Complexity: O(n).
fn highway128(data: &Vec[UInt8], key0: UInt64, key1: UInt64, key2: UInt64, key3: UInt64) -> Hh128¶
128-bit HighwayHash digest returned as a two-field struct (low, high). Complexity: O(n).
fn highway256(data: &Vec[UInt8], key0: UInt64, key1: UInt64, key2: UInt64, key3: UInt64) -> (UInt64, UInt64, UInt64, UInt64)¶
256-bit HighwayHash digest as four 64-bit lanes (v0, v1, v2, v3). Complexity: O(n).
fn highway_hash(data: &Vec[UInt8], key: Vec[UInt64]) -> UInt64¶
64-bit HighwayHash taking the four key words as a vector; traps if key.len() != 4 (a programming error). Complexity: O(n).
- Precondition:
key.len() == 4
fn highway_verify(data: &Vec[UInt8], key0: UInt64, key1: UInt64, key2: UInt64, key3: UInt64, expected: UInt64) -> Bool¶
Rehashes
datawith the given key and compares againstexpected. Complexity: O(n).
jenkins.xi¶
fn jenkins_lookup3(data: &Vec[UInt8], seed: UInt32) -> Vec[UInt32]¶
lookup3 hashlittle of a byte string with the given seed; returns [a, b].
metro.xi¶
fn metrohash64(data: &Vec[UInt8], seed: UInt64) -> UInt64¶
MetroHash64 v1 64-bit digest over
data. Complexity: O(n).
fn metrohash64_2(data: &Vec[UInt8], seed: UInt64) -> UInt64¶
MetroHash64 v2 64-bit digest (fixed-width, seedable). Uses the same lane construction as v1 with a length-aware final fold. Complexity: O(n).
fn metrohash128(data: &Vec[UInt8], seed: UInt64) -> (UInt64, UInt64)¶
MetroHash128 128-bit digest as two 64-bit words (low, high). Complexity: O(n).
fn metrohash128crc(data: &Vec[UInt8], seed: UInt64) -> (UInt64, UInt64)¶
MetroHash128 with CRC32 hardware acceleration when available. This pure fallback is identical to metrohash128 (no CRC32 instruction dependency). Complexity: O(n).
fn metrohash32(data: &Vec[UInt8], seed: UInt32) -> UInt32¶
MetroHash32 compact 32-bit digest for small tables: 4-byte word mixing with a 32-bit fold. Complexity: O(n).
murmur.xi¶
fn murmur3_128(data: &Vec[UInt8], seed: UInt32) -> Vec[UInt64]¶
MurmurHash3 x64_128 of a byte string; returns [h1, h2].
fn murmur2_64(data: &Vec[UInt8], seed: UInt64) -> UInt64¶
MurmurHash64A of a byte string with the given seed.
siphash.xi¶
fn siphash24(data: &Vec[UInt8], k0: UInt64, k1: UInt64) -> UInt64¶
Canonical SipHash-2-4 over a byte buffer.
- Precondition:
true
fn siphash13(data: &Vec[UInt8], k0: UInt64, k1: UInt64) -> UInt64¶
SipHash-1-3 (faster variant, same security level for MAC use cases).
- Precondition:
true
fn siphash24_zerokey(data: &Vec[UInt8]) -> UInt64¶
SipHash-2-4 with a zero key (convenience; NOT secure -- use real keys).
- Precondition:
true
fn siphash24_str(s: Str, k0: UInt64, k1: UInt64) -> UInt64¶
SipHash-2-4 over a Str's bytes with an explicit key, zero copies.
- Precondition:
true
fn siphash24_str_seeded(s: Str) -> UInt64¶
SipHash-2-4 over a Str using the process-wide OS-seeded key pair. This is the default hasher for Str-keyed containers (StringMap).
spooky.xi¶
fn spooky32(data: &Vec[UInt8]) -> UInt32¶
32-bit SpookyHash over
data(no seed): the low 32 bits of the unseeded 64-bit digest. Complexity: O(n).
fn spooky64(data: &Vec[UInt8], seed: UInt64) -> UInt64¶
64-bit SpookyHash over
datawith a single seed. Complexity: O(n).
fn spooky128(data: &Vec[UInt8], seed1: UInt64, seed2: UInt64) -> (UInt64, UInt64)¶
128-bit SpookyHash digest as two 64-bit words (hash1, hash2). Complexity: O(n).
fn spooky_short(data: &Vec[UInt8]) -> UInt64¶
Fast path 64-bit hash for messages of 8 bytes or fewer: a compact byte-wise rotate-multiply mix with an fmix64 avalanche. Complexity: O(n), n <= 8.
superfast.xi¶
fn superfast32(data: &Vec[UInt8]) -> Int¶
4-byte block loop plus 1-3 byte tail; all 32-bit wrapping via masks.
t1ha.xi¶
fn t1ha0(data: &Vec[UInt8], seed: UInt64) -> UInt64¶
t1ha0 latency-optimised portable 64-bit hash: single lane, 8-byte word mixing with a byte-wise tail fold. Complexity: O(n).
fn t1ha1(data: &Vec[UInt8], seed: UInt64) -> UInt64¶
t1ha1 64-bit hash, well-tuned for medium inputs: two-lane 16-byte block mixing. Complexity: O(n).
fn t1ha2(data: &Vec[UInt8], seed: UInt64) -> UInt64¶
t1ha2 64-bit hash, strongest avalanche of the family: two lanes, 32-byte block mixing with cross-lane addition. Complexity: O(n).
fn t1ha2_atonce(data: &Vec[UInt8]) -> UInt64¶
t1ha2 one-shot 64-bit hash with implicit zero seed. Complexity: O(n).
fn t1ha2_atonce128(data: &Vec[UInt8]) -> (UInt64, UInt64)¶
t1ha2 one-shot 128-bit digest as two 64-bit words. Complexity: O(n).
fn t1ha_ia32(data: &Vec[UInt8], seed: UInt64) -> UInt64¶
t1ha variant tuned for IA-32 targets: smaller state, 4-byte word mixing. Complexity: O(n).
xxhash.xi¶
fn xxh64(data: &Vec[UInt8], seed: UInt64) -> UInt64¶
XXH64 of a byte string with the given seed.
fn xxh32(data: &Vec[UInt8], seed: UInt32) -> UInt32¶
XXH32 of a byte string with the given seed.
type Xxh128¶
---- 128-bit ----
| Field | Type |
|---|---|
low64 |
UInt64 |
high64 |
UInt64 |
fn xxh3_64(data: &Vec[UInt8]) -> UInt64¶
XXH3-64, seed 0. Verified against xxHash v0.8.3 reference: "" -> 0x2d06800538d394c2, "a" -> 0xe6c632b61e964e1f, "abc" -> 0x78af5f94892f3950.
fn xxh3_64_with_seed(data: &Vec[UInt8], seed: UInt64) -> UInt64¶
XXH3-64 with an explicit 64-bit seed (v0.8.3 seeded-secret semantics).
fn xxh3_128(data: &Vec[UInt8]) -> Xxh128¶
XXH3-128, seed 0. Verified against xxHash v0.8.3 reference: "" -> (0x6001c324468d497f, 0x99aa06d3014798d8), "a" -> (0xe6c632b61e964e1f, 0xa96faf705af16834).
fn xxh3_128_with_seed(data: &Vec[UInt8], seed: UInt64) -> Xxh128¶
XXH3-128 with an explicit 64-bit seed (v0.8.3 seeded-secret semantics).