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 whenn(len) is prime. - hash
- Takes a reference to a type
Tand 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 NRelies onis_primeandnext_primefunctions - 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