
public class HashValue
{
    public static void main(String[] args)
    {
        Integer i = 4;
        System.out.println("i = " + i + "  i.hashCode() = " + i.hashCode() );
        System.out.println("MAD() = " + MAD(i.hashCode()) );

        Float f = 2.0f;  // 010000000000000000000000000000000000 = 1073741824
        System.out.println("f = " + f + "  f.hashCode() = " + f.hashCode() );
        System.out.println("MAD() = " + MAD(f.hashCode()) );

	String s = "A";  // A = 65
        System.out.println("s = " + s + "  s.hashCode() = " + s.hashCode() );
        System.out.println("MAD() = " + MAD(s.hashCode()) );

	s = "AA";        // AA = 65*31+ 65 = 2080
        System.out.println("s = " + s + "  s.hashCode() = " + s.hashCode() );
        System.out.println("MAD() = " + MAD(s.hashCode()) );

	s = "AAA";       // AAA = 65*31^2 + 65*31+ 65 = 64545
        System.out.println("s = " + s + "  s.hashCode() = " + s.hashCode() );
        System.out.println("MAD() = " + MAD(s.hashCode()) );
    }

    public static int MAD(int x)
    {
	int p = 109345121;
	int a = 123;
	int b = 456;

	return Math.abs(a*x + b) % p;
    }
}

