tinkerpop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dkupp...@apache.org
Subject [1/8] tinkerpop git commit: Improved `hashcode()` and `equals()` for all Traverser implementations.
Date Tue, 05 Sep 2017 16:56:54 GMT
Repository: tinkerpop
Updated Branches:
  refs/heads/tp32 397158ade -> 2e2d2cdfe


Improved `hashcode()` and `equals()` for all Traverser implementations.


Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/d0659e37
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/d0659e37
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/d0659e37

Branch: refs/heads/tp32
Commit: d0659e379bf59a164b4c3d87cc83de545d433547
Parents: 107329a
Author: Daniel Kuppitz <daniel_kuppitz@hotmail.com>
Authored: Thu Aug 24 13:51:41 2017 -0700
Committer: Daniel Kuppitz <daniel_kuppitz@hotmail.com>
Committed: Mon Aug 28 07:06:23 2017 -0700

----------------------------------------------------------------------
 .../traverser/B_LP_O_P_S_SE_SL_Traverser.java     | 12 ++++--------
 .../traverser/B_LP_O_S_SE_SL_Traverser.java       | 12 ++++--------
 .../traverser/B_O_S_SE_SL_Traverser.java          | 17 +++++++++++------
 .../traversal/traverser/B_O_Traverser.java        |  2 +-
 .../traverser/LP_O_OB_P_S_SE_SL_Traverser.java    | 15 +++++++--------
 .../traverser/LP_O_OB_S_SE_SL_Traverser.java      | 11 ++++-------
 .../traverser/O_OB_S_SE_SL_Traverser.java         | 18 +++++++++++-------
 .../process/traversal/traverser/O_Traverser.java  | 11 +++++++++++
 8 files changed, 53 insertions(+), 45 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/d0659e37/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/B_LP_O_P_S_SE_SL_Traverser.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/B_LP_O_P_S_SE_SL_Traverser.java
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/B_LP_O_P_S_SE_SL_Traverser.java
index 49f19e4..919157c 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/B_LP_O_P_S_SE_SL_Traverser.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/B_LP_O_P_S_SE_SL_Traverser.java
@@ -80,17 +80,13 @@ public class B_LP_O_P_S_SE_SL_Traverser<T> extends B_O_S_SE_SL_Traverser<T>
{
 
     @Override
     public int hashCode() {
-        return super.hashCode() + this.path.hashCode();
+        return carriesUnmergeableSack() ? System.identityHashCode(this) : (super.hashCode()
^ this.path.hashCode());
     }
 
     @Override
     public boolean equals(final Object object) {
-        return (object instanceof B_LP_O_P_S_SE_SL_Traverser)
-                && ((B_LP_O_P_S_SE_SL_Traverser) object).t.equals(this.t)
-                && ((B_LP_O_P_S_SE_SL_Traverser) object).future.equals(this.future)
-                && ((B_LP_O_P_S_SE_SL_Traverser) object).loops == this.loops
-                && (null == this.sack || null != this.sideEffects.getSackMerger())
-                && ((B_LP_O_P_S_SE_SL_Traverser) object).path.equals(this.path);
+        return object instanceof B_LP_O_P_S_SE_SL_Traverser &&
+                super.equals(object) &&
+                ((B_LP_O_P_S_SE_SL_Traverser) object).path.equals(this.path);
     }
-
 }

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/d0659e37/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/B_LP_O_S_SE_SL_Traverser.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/B_LP_O_S_SE_SL_Traverser.java
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/B_LP_O_S_SE_SL_Traverser.java
index 74a049c..1e50f3d 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/B_LP_O_S_SE_SL_Traverser.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/B_LP_O_S_SE_SL_Traverser.java
@@ -112,17 +112,13 @@ public class B_LP_O_S_SE_SL_Traverser<T> extends B_O_S_SE_SL_Traverser<T>
{
 
     @Override
     public int hashCode() {
-        return super.hashCode() + this.path.hashCode();
+        return carriesUnmergeableSack() ? System.identityHashCode(this) : (super.hashCode()
^ this.path.hashCode());
     }
 
     @Override
     public boolean equals(final Object object) {
-        return (object instanceof B_LP_O_S_SE_SL_Traverser)
-                && ((B_LP_O_S_SE_SL_Traverser) object).t.equals(this.t)
-                && ((B_LP_O_S_SE_SL_Traverser) object).future.equals(this.future)
-                && ((B_LP_O_S_SE_SL_Traverser) object).loops == this.loops
-                && (null == this.sack || (null != this.sideEffects && null
!= this.sideEffects.getSackMerger())) // hmmm... serialization in OLAP destroys the transient
sideEffects
-                && ((B_LP_O_S_SE_SL_Traverser) object).path.popEquals(Pop.last, this.path);
// this should be Pop.all?
+        return object instanceof B_LP_O_S_SE_SL_Traverser &&
+                super.equals(object) &&
+                ((B_LP_O_S_SE_SL_Traverser) object).path.equals(this.path);
     }
-
 }

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/d0659e37/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/B_O_S_SE_SL_Traverser.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/B_O_S_SE_SL_Traverser.java
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/B_O_S_SE_SL_Traverser.java
index ab1a783..2612472 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/B_O_S_SE_SL_Traverser.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/B_O_S_SE_SL_Traverser.java
@@ -23,6 +23,8 @@ import org.apache.tinkerpop.gremlin.process.traversal.Step;
 import org.apache.tinkerpop.gremlin.process.traversal.TraversalSideEffects;
 import org.apache.tinkerpop.gremlin.process.traversal.Traverser;
 
+import java.util.Random;
+
 /**
  * @author Marko A. Rodriguez (http://markorodriguez.com)
  */
@@ -110,17 +112,20 @@ public class B_O_S_SE_SL_Traverser<T> extends B_O_Traverser<T>
{
 
     /////////////////
 
+    final boolean carriesUnmergeableSack() {
+        return null != this.sack && (null == this.sideEffects || null == this.sideEffects.getSackMerger());
+    }
+
     @Override
     public int hashCode() {
-        return this.t.hashCode() + this.future.hashCode() + this.loops;
+        return carriesUnmergeableSack() ? System.identityHashCode(this) : (super.hashCode()
^ this.loops);
     }
 
     @Override
     public boolean equals(final Object object) {
-        return object instanceof B_O_S_SE_SL_Traverser
-                && ((B_O_S_SE_SL_Traverser) object).t.equals(this.t)
-                && ((B_O_S_SE_SL_Traverser) object).future.equals(this.future)
-                && ((B_O_S_SE_SL_Traverser) object).loops == this.loops
-                && (null == this.sack || (null != this.sideEffects && null
!= this.sideEffects.getSackMerger())); // hmmm... serialization in OLAP destroys the transient
sideEffects
+        return object instanceof B_O_S_SE_SL_Traverser &&
+                super.equals(object) &&
+                ((B_O_S_SE_SL_Traverser) object).loops == this.loops &&
+                !carriesUnmergeableSack(); // hmmm... serialization in OLAP destroys the
transient sideEffects
     }
 }

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/d0659e37/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/B_O_Traverser.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/B_O_Traverser.java
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/B_O_Traverser.java
index 4a66ab1..cef4e96 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/B_O_Traverser.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/B_O_Traverser.java
@@ -65,7 +65,7 @@ public class B_O_Traverser<T> extends O_Traverser<T> {
     @Override
     public boolean equals(final Object object) {
         return object instanceof B_O_Traverser &&
-                ((B_O_Traverser) object).t.equals(this.t) &&
+                super.equals(object) &&
                 ((B_O_Traverser) object).future.equals(this.future);
     }
 }

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/d0659e37/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/LP_O_OB_P_S_SE_SL_Traverser.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/LP_O_OB_P_S_SE_SL_Traverser.java
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/LP_O_OB_P_S_SE_SL_Traverser.java
index 5f24e8c..b1f4aa7 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/LP_O_OB_P_S_SE_SL_Traverser.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/LP_O_OB_P_S_SE_SL_Traverser.java
@@ -106,17 +106,16 @@ public class LP_O_OB_P_S_SE_SL_Traverser<T> extends O_OB_S_SE_SL_Traverser<T>
{
 
     @Override
     public int hashCode() {
-        return super.hashCode() + this.path.hashCode();
+        if (carriesUnmergeableSack()) {
+            return System.identityHashCode(this);
+        }
+        return super.hashCode() ^ this.path.hashCode();
     }
 
     @Override
     public boolean equals(final Object object) {
-        return (object instanceof LP_O_OB_P_S_SE_SL_Traverser)
-                && ((LP_O_OB_P_S_SE_SL_Traverser) object).t.equals(this.t)
-                && ((LP_O_OB_P_S_SE_SL_Traverser) object).future.equals(this.future)
-                && ((LP_O_OB_P_S_SE_SL_Traverser) object).loops == this.loops
-                && (null == this.sack || null != this.sideEffects.getSackMerger())
-                && ((LP_O_OB_P_S_SE_SL_Traverser) object).path.equals(this.path);
+        return object instanceof LP_O_OB_P_S_SE_SL_Traverser &&
+                super.equals(object) &&
+                ((LP_O_OB_P_S_SE_SL_Traverser) object).path.equals(this.path);
     }
-
 }

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/d0659e37/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/LP_O_OB_S_SE_SL_Traverser.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/LP_O_OB_S_SE_SL_Traverser.java
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/LP_O_OB_S_SE_SL_Traverser.java
index 58f420c..b58560c 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/LP_O_OB_S_SE_SL_Traverser.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/LP_O_OB_S_SE_SL_Traverser.java
@@ -89,16 +89,13 @@ public class LP_O_OB_S_SE_SL_Traverser<T> extends O_OB_S_SE_SL_Traverser<T>
{
 
     @Override
     public int hashCode() {
-        return super.hashCode() + this.path.hashCode();
+        return carriesUnmergeableSack() ? System.identityHashCode(this) : (super.hashCode()
^ this.path.hashCode());
     }
 
     @Override
     public boolean equals(final Object object) {
-        return (object instanceof LP_O_OB_S_SE_SL_Traverser)
-                && ((LP_O_OB_S_SE_SL_Traverser) object).t.equals(this.t)
-                && ((LP_O_OB_S_SE_SL_Traverser) object).future.equals(this.future)
-                && ((LP_O_OB_S_SE_SL_Traverser) object).loops == this.loops
-                && (null == this.sack || null != this.sideEffects.getSackMerger())
-                && ((LP_O_OB_S_SE_SL_Traverser) object).path.popEquals(Pop.last,
this.path); // this should be Pop.all?
+        return object instanceof LP_O_OB_S_SE_SL_Traverser &&
+                super.equals(object) &&
+                ((LP_O_OB_S_SE_SL_Traverser) object).path.equals(this.path);
     }
 }

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/d0659e37/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/O_OB_S_SE_SL_Traverser.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/O_OB_S_SE_SL_Traverser.java
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/O_OB_S_SE_SL_Traverser.java
index 2fb68ad..d1532bf 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/O_OB_S_SE_SL_Traverser.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/O_OB_S_SE_SL_Traverser.java
@@ -133,17 +133,21 @@ public class O_OB_S_SE_SL_Traverser<T> extends O_Traverser<T>
{
 
     /////////////////
 
+    final boolean carriesUnmergeableSack() {
+        return null != this.sack && (null == this.sideEffects || null == this.sideEffects.getSackMerger());
+    }
+
     @Override
     public int hashCode() {
-        return this.t.hashCode() + this.future.hashCode() + this.loops;
+        return carriesUnmergeableSack() ? System.identityHashCode(this) : (super.hashCode()
^ this.loops);
     }
 
     @Override
     public boolean equals(final Object object) {
-        return object instanceof O_OB_S_SE_SL_Traverser
-                && ((O_OB_S_SE_SL_Traverser) object).t.equals(this.t)
-                && ((O_OB_S_SE_SL_Traverser) object).future.equals(this.future)
-                && ((O_OB_S_SE_SL_Traverser) object).loops == this.loops
-                && (null == this.sack || (null != this.sideEffects && null
!= this.sideEffects.getSackMerger())); // hmmm... serialization in OLAP destroys the transient
sideEffects
+        return object instanceof O_OB_S_SE_SL_Traverser &&
+                super.equals(object) &&
+                ((O_OB_S_SE_SL_Traverser) object).loops == this.loops &&
+                ((O_OB_S_SE_SL_Traverser) object).future.equals(this.future) &&
+                !carriesUnmergeableSack(); // hmmm... serialization in OLAP destroys the
transient sideEffects
     }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/d0659e37/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/O_Traverser.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/O_Traverser.java
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/O_Traverser.java
index e9735b0..b4e1e0d 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/O_Traverser.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/O_Traverser.java
@@ -68,4 +68,15 @@ public abstract class O_Traverser<T> extends AbstractTraverser<T>
{
             this.tags.addAll(other.getTags());
         }
     }
+
+    @Override
+    public boolean equals(final Object object) {
+        return object instanceof O_Traverser &&
+                super.equals(object) &&
+                (this.tags == null
+                        ? ((O_Traverser) object).tags == null
+                        : (((O_Traverser) object).tags != null &&
+                            ((O_Traverser) object).tags.containsAll(this.tags) &&
+                            this.tags.containsAll(((O_Traverser) object).tags)));
+    }
 }


Mime
View raw message