Commit 5ada00b5 authored by Tim McNamara's avatar Tim McNamara

Add hash-functions-in-rust.md

parent 8a10b2fe
## [FNV][] (Fowler–Noll–Vo)
The FNV hash function requires uses different primes and offset bases that are used depending on the desired length of the output hash function.
Implementing it in Rust is quite pleasant, although appears to be affected by overflow issues:
```rust
fn fnv_32(input: &[u8]) -> u32 {
let mut hash = 0x811c9dc5_u32;
let prime = 16777619_u32;
for byte in input {
hash *= prime;
hash ^= *byte as u32;
}
hash
}
```
TODO: Add calculating the offset basis and primes.
[FNV]: https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment