hash #
Description
On the C backends, wyhash64_c mixes both halves of each input's 128-bit product, including on C compilers without a 128-bit integer type. Each input is mixed independently, so matching a hash seed in one half of a 128-bit map key preserves the other half's contribution. Upper key bits affect the low hash bits used by maps. Hash values may change between compiler versions and should not be persisted.
hash provides a way to hash binary data, i.e. produce a shorter value, that is highly content dependent, so even slightly different content will produce widely different hashes.
Hash functions are useful for implementing maps, caches etc.
Hasher is a streaming 64-bit interface with write(bytes)! and finish(). Successive writes absorb chunks in order; repeated finish() calls return the current digest without consuming the state.
Create a conforming FNV-1a hasher with fnv1a.new_fnv1a64() to initialize its offset basis. Its write method currently cannot fail. finish() agrees with fnv1a.sum64 over all bytes written so far. hasher.sum(bytes) computes a separate one-shot digest without modifying the streaming state. FNV-1a is a noncryptographic hash.
Available submodules
hash.adler32- Adler-32 (RFC 1950 checksum used by zlib)hash.crc32- CRC-32 variants (IEEE 802.3crc32, Castagnolicrc32c, Koopmancrc32k, CRC-32Qcrc32q)hash.crc64- CRC-64-ECMA-182hash.fnv1a- Fowler-Noll-Vo hashes
fn sum64 #
fn sum64(key []u8, seed u64) u64
sum64 returns a hash given a byte array key and a seed.
fn sum64_string #
fn sum64_string(key string, seed u64) u64
sum64_string returns a hash given a V string key and a seed.
fn wyhash64_c #
fn wyhash64_c(a u64, b u64) u64
wyhash64_c returns a hash given two u64 values a and b.
fn wyhash_c #
fn wyhash_c(key &u8, len u64, seed u64) u64
wyhash_c returns a hash given a byte string key, its len, and a seed. The key is only read, never modified.
fn wymum #
fn wymum(a u64, b u64) u64
wymum returns a hash by performing multiply and mix on a and b.
interface Hash #
interface Hash {
// Sum appends the current hash to b and returns the resulting array.
// It does not change the underlying hash state.
mut:
sum(b []u8) []u8
size() int
block_size() int
free()
reset()
write(p []u8) !int
}
interface Hasher #
interface Hasher {
// write feeds bytes into the hash state.
mut:
write(p []u8) !
// finish returns the current 64-bit digest without consuming state.
finish() u64
}
Hasher is the interface for streaming 64-bit hashers: bytes are fed with write and the digest is read with finish, which must be repeatable without consuming state. It is the V-idiomatic equivalent of Rust's std::hash::Hasher, for use in generic hashed containers. See fnv1a.Fnv1a64 for a conforming implementation.