From 50009cc8550773e552733d5e75a6e4829d41b7d9 Mon Sep 17 00:00:00 2001 From: TomyLobo Date: Sun, 25 Sep 2011 04:49:07 +0200 Subject: [PATCH] Improved hashCode implementations for the Vector classes. Block[World]Vector was ignoring changes of y < 128 (i.e. all of them) and changes of x < 8192. --- src/main/java/com/sk89q/worldedit/BlockVector.java | 4 ++-- src/main/java/com/sk89q/worldedit/BlockWorldVector.java | 4 ++-- src/main/java/com/sk89q/worldedit/Vector.java | 9 ++++++--- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/sk89q/worldedit/BlockVector.java b/src/main/java/com/sk89q/worldedit/BlockVector.java index 1f3ee514c..ab54bdf55 100644 --- a/src/main/java/com/sk89q/worldedit/BlockVector.java +++ b/src/main/java/com/sk89q/worldedit/BlockVector.java @@ -93,8 +93,8 @@ public class BlockVector extends Vector { */ @Override public int hashCode() { - return (Integer.valueOf((int)x).hashCode() >> 13) ^ - (Integer.valueOf((int)y).hashCode() >> 7) ^ + return (Integer.valueOf((int)x).hashCode() << 19) ^ + (Integer.valueOf((int)y).hashCode() << 12) ^ Integer.valueOf((int)z).hashCode(); } } diff --git a/src/main/java/com/sk89q/worldedit/BlockWorldVector.java b/src/main/java/com/sk89q/worldedit/BlockWorldVector.java index 6865cbedf..9de1ae59f 100644 --- a/src/main/java/com/sk89q/worldedit/BlockWorldVector.java +++ b/src/main/java/com/sk89q/worldedit/BlockWorldVector.java @@ -126,8 +126,8 @@ public class BlockWorldVector extends WorldVector { */ @Override public int hashCode() { - return (Integer.valueOf((int)x).hashCode() >> 13) ^ - (Integer.valueOf((int)y).hashCode() >> 7) ^ + return (Integer.valueOf((int)x).hashCode() << 19) ^ + (Integer.valueOf((int)y).hashCode() << 12) ^ Integer.valueOf((int)z).hashCode(); } } diff --git a/src/main/java/com/sk89q/worldedit/Vector.java b/src/main/java/com/sk89q/worldedit/Vector.java index 5b164b9b7..758de2ade 100644 --- a/src/main/java/com/sk89q/worldedit/Vector.java +++ b/src/main/java/com/sk89q/worldedit/Vector.java @@ -585,9 +585,12 @@ public class Vector { */ @Override public int hashCode() { - return ((new Double(x)).hashCode() >> 13) ^ - ((new Double(y)).hashCode() >> 7) ^ - (new Double(z)).hashCode(); + int hash = 7; + + hash = 79 * hash + (int) (Double.doubleToLongBits(this.x) ^ (Double.doubleToLongBits(this.x) >>> 32)); + hash = 79 * hash + (int) (Double.doubleToLongBits(this.y) ^ (Double.doubleToLongBits(this.y) >>> 32)); + hash = 79 * hash + (int) (Double.doubleToLongBits(this.z) ^ (Double.doubleToLongBits(this.z) >>> 32)); + return hash; } /**