The book says that you should use these mathematical equivalents:
(a * b) mod m = ((a mod m) * (b mod m)) mod m (a + b) mod m = ((a mod m) + (b mod m)) mod m
Thus,
h = (((x*c) + y)*c + z) mod m
Is equivalent
_ _ _ _ h = (((x*c) + y)*c + z)
Where
_ a * b = ((a mod m) * (b mod m)) mod m _ a + b = ((a mod m) + (b mod m)) mod m
Essentially, for each basic addition and main subtraction, you replace it with an βextendedβ version, in which mod operands and mod results. Since the operands for basic multiplication are now in the range 0..m-1 , the largest number you get is (m-1)^2 , which can facilitate overflow if m is small enough.
see also
By the way, it should be noted that 32 is a terrible choice of factor for the hash functions of this class (since it is not simple), especially for calculation (since it has degree 2). Much better than 31 because:
- It is simple (mathematically important!)
- This one is less than two, so it can be optimized for a cheaper shift and subtracted
polygenelubricants
source share