Module hash_lib

Source
Expand description

Hashing & compression functions

The utility functions in this module can be used to implement various hashing and compression algorithms

Functions§

bit_shift_visualization
Illustrates the concept of bit shifting; Takes a string a prints the bit and integer value of each character before performing a bit shift operation and printing the result as bit and integer values
division_compression
Super simple division compression as i mod N. Produces a deterministic output, works best when n (len) is prime.
hash
Takes a reference to a type T and uses Rust’s default hasher to return a 64-bit digest.
hash_1
Does the same thing as hash() but feeds individual bytes which produces a slightly less efficient (and different) digest
mad_compression
Illustrates MAD compression as [(ai + b) mod p] mod N Relies on is_prime and next_prime functions c(h(k)) = ((a * h(k) + b) mod p) mod N
mad_compression_1
next_prime
Finds the next prime in O(n/2) time by skipping evens
simple_hash_function
Calculates a bit-shifted hash code; The function initializes a 32-bit hash code integer to 0, then loops over each character in the input string; Each loop adds the next character in the string to the hash code as an integer value with wrapping; This ensures consistency across architectures; The next operation in each loop performs a cyclic bit shift on the hash code, and the process repeats