-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix hash code collision for Vector2D and Vector3D #227
base: master
Are you sure you want to change the base?
Fix hash code collision for Vector2D and Vector3D #227
Commits on Jan 16, 2024
-
Fix hash code collision for Vector2D and Vector3D
This commit modifies the `hashCode()` method for `Vector2D` and the `Vector3D` classes in order to ensure unique values are generated for non-identical instances of vectors. The proposed approach for calculating the hash code value is the same that is used in JTS and HE_Mesh projects. And as quoted in JTS project, this approach was initially 'borrowed' from the Joshua Bloch book 'Effective Java' (1st ed, 2008). In the "Item 9: Always override hashCode when you override equals" he describes the recipe as follows: 1. Store some constant nonzero value, say 17, in an int variable called `result`. 2. For each significant field `f` in your object, do the following: a. Compute an int hash code `c` for the field: i ... ii ... iii If the field is a long, compute (int)(f^(f>>>32)) iv ... v If the field is a double, compute Double.doublToLongBits(f), and then hash the resulting long as in step 2.a.iii vi ... vii ... b. Combine the hash code `c` computed in step 2.a into `result` as follows: result = 31 * result + c
Configuration menu - View commit details
-
Copy full SHA for 93a01fa - Browse repository at this point
Copy the full SHA 93a01faView commit details
Commits on Jan 17, 2024
-
Configuration menu - View commit details
-
Copy full SHA for d313086 - Browse repository at this point
Copy the full SHA d313086View commit details -
Make the Vector2D and Vector3D hashCode method more readable
This commit uses calls to Double.hashCode() method in order to make the code more readable while keeping the overall approach for calculating the hash code value.
Configuration menu - View commit details
-
Copy full SHA for ddb75f0 - Browse repository at this point
Copy the full SHA ddb75f0View commit details
Commits on Jan 18, 2024
-
Modify GreatCircle hashCode calculation
This commit uses the same approach we've used in Vector2D and Vector3D to calculate hash code value for the GreatCircle class instances. Previously, GreatCircle.hashCode was using the Objects.hash(Object ...) wrapper method. In its turn, it has called the Arrays.hashCode(Object[]) method. Unfortunately, this does not prevent hash collisions calculated for the GreatCircle instances. Not investigated the cause yet. As a guess, this might be related to that the Precision.DoubleEquivalence's hashCode() method is not overridden.
Configuration menu - View commit details
-
Copy full SHA for 448c2d3 - Browse repository at this point
Copy the full SHA 448c2d3View commit details
Commits on Jan 30, 2024
-
Revert GreatCircle hash code calculation
Modifid GreatCircleTest instead to allow all the test successfully pass. See this comment thread for details: apache#227 (review)
Configuration menu - View commit details
-
Copy full SHA for 0341398 - Browse repository at this point
Copy the full SHA 0341398View commit details
Commits on Jan 31, 2024
-
Add changes requested in PR review
- in Vector3D.hashCode(): - use Double.hashCode() instead of the Double.doubleToLongBits() - revert Javadoc formatting - in Vector2D.hashCode(), revert Javadoc formatting
Configuration menu - View commit details
-
Copy full SHA for 39c7ef0 - Browse repository at this point
Copy the full SHA 39c7ef0View commit details