public Class myClass{
private final int[][] board;
}
I have
LinkedHashMap<Integer,Object> myMap
where Integer is a hashcode i create by using Arrays.deepHashCode
public int hashCode() {
int hash = 5;
hash = 89 * hash + Arrays.deepHashCode(this.board);
return hash;
}
public boolean equals(Object anObject) {
if (anObject == null) return false;
if (anObject == this) return true;
if (!(anObject instanceof myClass))return false;
Puzzle anotherClass = (myClass)anObject;
return Arrays.deepEquals(this.board,anotherClass.board);
}
I get new objects and i need to add them to myMap
only if they don't exist.
I tried to check the hashcode using myMap.containsKey(hashcode)
apparently i'm getting duplicate hashcode for different objects.
I tried to check further details when i get true from myMap.containsKey(hashcode)
but then i can't add them to myMap as they have the same key!!
Is there any workaround for this problem since using ArrayList
and checking with contains()
is extremely slow and i have a large number of iterations.