January 2019
Intermediate to advanced
316 pages
8h 8m
English
In addition to providing a generic data structure, the implementation lets the user supply a custom hash function that only maps a reference to the key type to a usize return type. The choice for the return type is arbitrary, and was chosen to avoid overflows.
Since the previously implemented hash function performed better than the Adler 32 checksum algorithm, the location cache will use this. To recall, the algorithm applies XOR between a byte and its predecessor and then bit shifts to the left, based on the byte's index. Alternatively, Rust's DefaultHasher is available as well:
pub fn hashcode(bytes: &[u8]) -> u32 { let mut a = 0_u32; for (i, b) in bytes.iter().enumerate() { a ^= *b as u32; a <<= i % 4; } a}
Choosing a ...