Java Code Examples for java.math.BigInteger#hashCode()

The following examples show how to use java.math.BigInteger#hashCode() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: j2objc   File: BigIntegerHashCodeTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Test hash codes for the same object
 */
public void testSameObject() {
    String value1 = "12378246728727834290276457386374882976782849";
    String value2 = "-5634562095872038262928728727834290276457386374882976782849";
    BigInteger aNumber1 = new BigInteger(value1);
    BigInteger aNumber2 = new BigInteger(value2);
    int code1 = aNumber1.hashCode();
    aNumber1.add(aNumber2).shiftLeft(125);
    aNumber1.subtract(aNumber2).shiftRight(125);
    aNumber1.multiply(aNumber2).toByteArray();
    aNumber1.divide(aNumber2).bitLength();
    aNumber1.gcd(aNumber2).pow(7);
    int code2 = aNumber1.hashCode();
    assertTrue("hash codes for the same object differ", code1 == code2);
}
 
Example 2
Source Project: j2objc   File: BigIntegerHashCodeTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Test hash codes for equal objects.
 */
public void testEqualObjects() {
    String value1 = "12378246728727834290276457386374882976782849";
    String value2 = "12378246728727834290276457386374882976782849";
    BigInteger aNumber1 = new BigInteger(value1);
    BigInteger aNumber2 = new BigInteger(value2);
    int code1 = aNumber1.hashCode();
    int code2 = aNumber2.hashCode();
    if (aNumber1.equals(aNumber2)) {
        assertTrue("hash codes for equal objects are unequal", code1 == code2);
    }
}
 
Example 3
Source Project: j2objc   File: BigIntegerHashCodeTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Test hash codes for unequal objects.
 * The codes are unequal.
 */
public void testUnequalObjectsUnequal() {
    String value1 = "12378246728727834290276457386374882976782849";
    String value2 = "-5634562095872038262928728727834290276457386374882976782849";
    BigInteger aNumber1 = new BigInteger(value1);
    BigInteger aNumber2 = new BigInteger(value2);
    int code1 = aNumber1.hashCode();
    int code2 = aNumber2.hashCode();
    if (!aNumber1.equals(aNumber2)) {
        assertTrue("hash codes for unequal objects are equal", code1 != code2);
    }
}
 
Example 4
Source Project: javaanpr   File: Photo.java    License: Educational Community License v2.0 5 votes vote down vote up
@Override
public int hashCode() {
    BigInteger rgbSum = BigInteger.ZERO;
    for (int i = 0; i < getWidth(); i++) {
        for (int j = 0; j < getHeight(); j++) {
            rgbSum = rgbSum.add(BigInteger.valueOf(getRGB(i, j)));
        }
    }
    return rgbSum.hashCode();
}
 
Example 5
/**
 * Full constructor.
 * @param A
 * @param smallFactors small factors of Q
 */
public AQPair(BigInteger A, SortedIntegerArray smallFactors) {
	// The congruence A^2 == Q (mod kN) does not distinguish between +A and -A.
	// But avoiding such duplicates is asymptotically unfavourable because their likelihood decreases quickly.
	this.A = A;
	// Precompute hashCode
	this.hashCode = A.hashCode();
	// Copy small factors of Q
	this.smallFactors = smallFactors.copyFactors();
	this.smallFactorExponents = smallFactors.copyExponents();
}
 
Example 6
Source Project: spork   File: SchemaTuple.java    License: Apache License 2.0 4 votes vote down vote up
protected int hashCodePiece(int hash, BigInteger v, boolean isNull) {
    return isNull ? hash : 31 * hash + v.hashCode();
}