Hashing functions return a wide range of integers. In order to transform these values into useful indices for our array we need a compression function. A compression function uses modular arithmetic to calculate an array index for a hash map when given a hash code.



Create a .compressor() method for your hash map.

It should take two parameters: self and hash_code.


Take the modulus of the hash code by the map’s array_size in order to reduce the hash code to a possible index for the array.

Return the modulus.

Sign up to start coding

Mini Info Outline Icon
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.

Or sign up using:

Already have an account?