From ad7fdd19fb5588411939d1e8e78aeb74f2f7f77d Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Tue, 10 Jan 2017 16:03:10 +1100 Subject: [PATCH] Vector and BlockVector should use the same hashCode For example, the getChunks method returns a Set which is actually comprised of BlockVector2D, so using set.contains(some vector) will always return false. There's unlikely to be multiple entities on the same block, or above y=256, so using the int coords is better. --- .../src/main/java/com/sk89q/worldedit/BlockVector.java | 7 ------- .../src/main/java/com/sk89q/worldedit/BlockVector2D.java | 6 ------ .../src/main/java/com/sk89q/worldedit/Vector.java | 7 +------ .../src/main/java/com/sk89q/worldedit/Vector2D.java | 3 +-- 4 files changed, 2 insertions(+), 21 deletions(-) diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/BlockVector.java b/worldedit-core/src/main/java/com/sk89q/worldedit/BlockVector.java index 474d24f33..2c3a05dd2 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/BlockVector.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/BlockVector.java @@ -84,13 +84,6 @@ public class BlockVector extends Vector { } - @Override - public int hashCode() { - return ((int) x << 19) ^ - ((int) y << 12) ^ - (int) z; - } - @Override public BlockVector toBlockVector() { return this; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/BlockVector2D.java b/worldedit-core/src/main/java/com/sk89q/worldedit/BlockVector2D.java index 9a0ae4b91..a9a2ddb74 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/BlockVector2D.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/BlockVector2D.java @@ -80,12 +80,6 @@ public class BlockVector2D extends Vector2D { } - @Override - public int hashCode() { - return (Integer.valueOf((int) x).hashCode() >> 13) ^ - Integer.valueOf((int) z).hashCode(); - } - @Override public BlockVector2D toBlockVector2D() { return this; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/Vector.java b/worldedit-core/src/main/java/com/sk89q/worldedit/Vector.java index e148e75d5..84067738c 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/Vector.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/Vector.java @@ -789,12 +789,7 @@ public class Vector implements Comparable { @Override public int 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; + return ((int) x ^ ((int) z << 12)) ^ ((int) y << 24); } @Override diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/Vector2D.java b/worldedit-core/src/main/java/com/sk89q/worldedit/Vector2D.java index 2c295ca2c..ae58566b7 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/Vector2D.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/Vector2D.java @@ -627,8 +627,7 @@ public class Vector2D { @Override public int hashCode() { - return ((new Double(x)).hashCode() >> 13) ^ - (new Double(z)).hashCode(); + return ((int) x << 16) ^ (int) z; } @Override