pub fn f1(byte: u8, p: u8, n: usize) -> usize
Expand description
Calculates the function f1
for the PHF. For the exact formula, please read the code.
When p == 0
, the operation is a simple modulus.
The argument n
is used only for taking the modulus so that the return value is
in the range [0, n)
.
Invariant: n > 0
§Examples
use zerotrie::_internal::f1;
const N: usize = 10;
// With p = 0:
assert_eq!(0, f1(0, 0, N));
assert_eq!(1, f1(1, 0, N));
assert_eq!(2, f1(2, 0, N));
assert_eq!(9, f1(9, 0, N));
assert_eq!(0, f1(10, 0, N));
assert_eq!(1, f1(11, 0, N));
assert_eq!(2, f1(12, 0, N));
assert_eq!(9, f1(19, 0, N));
// With p = 1:
assert_eq!(1, f1(0, 1, N));
assert_eq!(0, f1(1, 1, N));
assert_eq!(2, f1(2, 1, N));
assert_eq!(2, f1(9, 1, N));
assert_eq!(4, f1(10, 1, N));
assert_eq!(5, f1(11, 1, N));
assert_eq!(1, f1(12, 1, N));
assert_eq!(7, f1(19, 1, N));