Hows this?

This commit is contained in:
boy0001 2014-11-07 22:15:19 +11:00
parent 12c476f3c2
commit c606b4d893
2 changed files with 40 additions and 12 deletions

View File

@ -288,12 +288,26 @@ public class Plot implements Cloneable {
*/ */
@Override @Override
public int hashCode() { public int hashCode() {
final int int x = id.x;
x = getId().x, int y = id.y;
z = getId().y; if (x >= 0) {
String if (y >= 0) {
xL = (x + "").length() + "", return x*x + 3*x + 2*x*y + y + y*y;
zL = (z + "").length() + ""; }
return Integer.parseInt(xL + x + zL + z); else {
int y1 = -y;
return x*x + 3*x + 2*x*y1 + y1 + y1*y1 + 1;
}
}
else {
int x1 = -x;
if (y >= 0) {
return -(x1*x1 + 3*x1 + 2*x1*y + y + y*y);
}
else {
int y1 = -y;
return -(x1*x1 + 3*x1 + 2*x1*y1 + y1 + y1*y1 + 1);
}
}
} }
} }

View File

@ -45,10 +45,24 @@ public class PlotId {
@Override @Override
public int hashCode() { public int hashCode() {
final int prime = 31; if (x >= 0) {
int result = 1; if (y >= 0) {
result = (prime * result) + this.x; return x*x + 3*x + 2*x*y + y + y*y;
result = (prime * result) + this.y; }
return result; else {
int y1 = -y;
return x*x + 3*x + 2*x*y1 + y1 + y1*y1 + 1;
}
}
else {
int x1 = -x;
if (y >= 0) {
return -(x1*x1 + 3*x1 + 2*x1*y + y + y*y);
}
else {
int y1 = -y;
return -(x1*x1 + 3*x1 + 2*x1*y1 + y1 + y1*y1 + 1);
}
}
} }
} }