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§

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
Implements MAD compression as [(ai + b) mod p] mod N Relies on is_prime and next_prime functions
mad_compression_1
next_prime
Finds the next prime by brute force in O(n) time Finds the next prime in O(n/2) time by skipping evens
visual_bit_shift
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
visual_hash_code
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