tinkerpop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ok...@apache.org
Subject incubator-tinkerpop git commit: DefaultTraverser is getting slick. Also, realized that we had a memory leak in the other Traverser model, double object creation for no reason. CrAzY.
Date Thu, 03 Dec 2015 00:01:46 GMT
Repository: incubator-tinkerpop
Updated Branches:
  refs/heads/TINKERPOP3-1014 c9ae94245 -> 3cddfd46d


DefaultTraverser is getting slick. Also, realized that we had a memory leak in the other Traverser
model, double object creation for no reason. CrAzY.


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

Branch: refs/heads/TINKERPOP3-1014
Commit: 3cddfd46db50a7ea1b9a807d229765698a23a4ba
Parents: c9ae942
Author: Marko A. Rodriguez <okrammarko@gmail.com>
Authored: Wed Dec 2 17:01:40 2015 -0700
Committer: Marko A. Rodriguez <okrammarko@gmail.com>
Committed: Wed Dec 2 17:01:40 2015 -0700

----------------------------------------------------------------------
 .../traversal/traverser/DefaultTraverser.java   | 86 ++++++++++----------
 .../traverser/DefaultTraverserGenerator.java    |  6 +-
 .../traversal/step/map/MatchStepTest.java       |  2 +-
 3 files changed, 46 insertions(+), 48 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/3cddfd46/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/DefaultTraverser.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/DefaultTraverser.java
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/DefaultTraverser.java
index 7f71ad9..323b12d 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/DefaultTraverser.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/DefaultTraverser.java
@@ -39,13 +39,14 @@ public final class DefaultTraverser<T> implements Traverser.Admin<T>
{
     private T t;
     private long bulk = 1l;
     private String stepId;
-    private Path path;
     private short loops = 0;
-    private Set<String> tags = null;
+    private Set<String> tags;
+    private Object sack;
+    private Path path;
     private transient TraversalSideEffects sideEffects;
-    private boolean onlyLabeledPaths;
-    private boolean oneBulk;
-    private Object sack = null;
+    ///
+    private boolean onlyLabeledPaths; // we need to get rid of this
+
 
     /**
      * A no-args constructor  is necessary for Kryo serialization.
@@ -54,28 +55,29 @@ public final class DefaultTraverser<T> implements Traverser.Admin<T>
{
 
     }
 
-    public DefaultTraverser(final T t, final Step<T, ?> step, final long initialBulk,
final Path path, boolean onlyLabeledPaths, boolean oneBulk) {
+    public DefaultTraverser(final T t, final Step<T, ?> step, final long initialBulk,
final Path path, boolean onlyLabeledPaths) {
         this.t = t;
         this.stepId = step.getId();
         this.bulk = initialBulk;
-        this.path = path;
+        this.path = path instanceof EmptyPath ? null : path;
         this.sideEffects = step.getTraversal().getSideEffects();
         this.onlyLabeledPaths = onlyLabeledPaths;
-        this.oneBulk = oneBulk;
         if (null != this.sideEffects.getSackInitialValue())
             this.sack = this.sideEffects.getSackInitialValue().get();
     }
 
 
     @Override
-    public void addLabels(final Set<String> labels) {
-        if (this.onlyLabeledPaths) {
-            if (!labels.isEmpty())
-                this.path = this.path.size() == 0 || !this.path.get(this.path.size() - 1).equals(this.t)
?
-                        this.path.extend(this.t, labels) :
-                        this.path.extend(labels);
-        } else
-            this.path = this.path.extend(labels);
+    public void addLabels(final Set<String> labels) {  // we need to get rid of this
too
+        if (null != this.path) {
+            if (this.onlyLabeledPaths) {
+                if (!labels.isEmpty())
+                    this.path = this.path.size() == 0 || !this.path.get(this.path.size()
- 1).equals(this.t) ?
+                            this.path.extend(this.t, labels) :
+                            this.path.extend(labels);
+            } else
+                this.path = this.path.extend(labels);
+        }
     }
 
     @Override
@@ -85,8 +87,7 @@ public final class DefaultTraverser<T> implements Traverser.Admin<T>
{
 
     @Override
     public void incrLoops(final String stepLabel) {
-        if (!this.oneBulk)
-            this.loops++;
+        this.loops++;
     }
 
     @Override
@@ -112,7 +113,7 @@ public final class DefaultTraverser<T> implements Traverser.Admin<T>
{
     @Override
     public Admin<T> detach() {
         this.t = ReferenceFactory.detach(this.t);
-        if (!(this.path instanceof EmptyPath))
+        if (null != this.path)
             this.path = ReferenceFactory.detach(this.path);
         return this;
     }
@@ -144,30 +145,24 @@ public final class DefaultTraverser<T> implements Traverser.Admin<T>
{
     public <R> Admin<R> split(final R r, final Step<T, R> step) {
         final DefaultTraverser<R> clone = (DefaultTraverser<R>) this.clone();
         clone.t = r;
-        if (this.onlyLabeledPaths) {
-            if (!step.getLabels().isEmpty())
-                clone.path = this.path.clone().extend(r, step.getLabels());
-        } else
-            clone.path = this.path.clone().extend(r, step.getLabels());
-        if (null != this.tags)
-            clone.tags = new HashSet<>(this.tags);
-        clone.sack = null == clone.sack ? null : null == clone.sideEffects.getSackSplitter()
? clone.sack : clone.sideEffects.getSackSplitter().apply(clone.sack);
+        if (null != this.path) {
+            if (this.onlyLabeledPaths) {
+                if (!step.getLabels().isEmpty())
+                    clone.path = clone.path.extend(r, step.getLabels());
+            } else
+                clone.path = clone.path.extend(r, step.getLabels());
+        }
         return clone;
     }
 
     @Override
     public Admin<T> split() {
-        final DefaultTraverser<T> clone = (DefaultTraverser<T>) this.clone();
-        clone.path = this.path.clone();
-        if (null != this.tags)
-            clone.tags = new HashSet<>(this.tags);
-        clone.sack = null == clone.sack ? null : null == clone.sideEffects.getSackSplitter()
? clone.sack : clone.sideEffects.getSackSplitter().apply(clone.sack);
-        return clone;
+        return (DefaultTraverser.Admin<T>) this.clone();
     }
 
     @Override
     public void merge(final Traverser.Admin<?> other) {
-        if (!this.oneBulk)
+        if (-1 != this.bulk)
             this.bulk = this.bulk + other.bulk();
         if (!other.getTags().isEmpty()) {
             if (this.tags == null) this.tags = new HashSet<>();
@@ -194,7 +189,7 @@ public final class DefaultTraverser<T> implements Traverser.Admin<T>
{
 
     @Override
     public Path path() {
-        return this.path;
+        return null == this.path ? EmptyPath.instance() : this.path;
     }
 
     @Override
@@ -204,16 +199,19 @@ public final class DefaultTraverser<T> implements Traverser.Admin<T>
{
 
     @Override
     public long bulk() {
-        return this.bulk;
+        return this.bulk == -1 ? 1 : this.bulk;
     }
 
     @Override
     public Traverser<T> clone() {
         try {
             final DefaultTraverser<T> clone = (DefaultTraverser<T>) super.clone();
-            if (this.tags != null)
-                clone.getTags().addAll(this.tags);
-            clone.path = this.path.clone();
+            if (null != this.tags)
+                clone.tags = new HashSet<>(this.tags);
+            if (null != this.path)
+                clone.path = this.path.clone();
+            if (null != this.sack)
+                clone.sack = null == clone.sideEffects.getSackSplitter() ? this.sack : clone.sideEffects.getSackSplitter().apply(this.sack);
             return clone;
         } catch (final CloneNotSupportedException e) {
             throw new IllegalStateException(e.getMessage(), e);
@@ -224,17 +222,17 @@ public final class DefaultTraverser<T> implements Traverser.Admin<T>
{
 
     @Override
     public int hashCode() {
-        return this.t.hashCode() + this.stepId.hashCode() + this.loops + this.path.hashCode();
+        return this.t.hashCode() + this.stepId.hashCode() + this.loops + (null == this.path
? 0 : this.path.hashCode());
     }
 
     @Override
     public boolean equals(final Object object) {
         return object instanceof DefaultTraverser &&
-                ((DefaultTraverser) object).get().equals(this.t) &&
-                ((DefaultTraverser) object).stepId.equals(this.stepId) &&
-                ((DefaultTraverser) object).loops() == this.loops &&
+                this.t.equals(((DefaultTraverser) object).t) &&
+                this.stepId.equals(((DefaultTraverser) object).stepId) &&
+                this.loops == ((DefaultTraverser) object).loops &&
                 (null == this.sack || (null != this.sideEffects && null != this.sideEffects.getSackMerger()))
&& // hmmm... serialization in OLAP destroys the transient sideEffects
-                ((DefaultTraverser) object).path().equals(this.path);
+                (null == this.path || this.path.equals(((DefaultTraverser) object).path));
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/3cddfd46/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/DefaultTraverserGenerator.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/DefaultTraverserGenerator.java
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/DefaultTraverserGenerator.java
index f399549..c6733d1 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/DefaultTraverserGenerator.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/DefaultTraverserGenerator.java
@@ -43,11 +43,11 @@ public final class DefaultTraverserGenerator implements TraverserGenerator
{
     public <S> Traverser.Admin<S> generate(final S start, final Step<S, ?>
startStep, final long initialBulk) {
         final Set<TraverserRequirement> requirements = TraversalHelper.getRootTraversal(startStep.getTraversal()).getTraverserRequirements();
         if (requirements.contains(TraverserRequirement.PATH))
-            return new DefaultTraverser<>(start, startStep, initialBulk, ImmutablePath.make().extend(start,
startStep.getLabels()), false, requirements.contains(TraverserRequirement.ONE_BULK));
+            return new DefaultTraverser<>(start, startStep, requirements.contains(TraverserRequirement.ONE_BULK)
? -1 : initialBulk, ImmutablePath.make().extend(start, startStep.getLabels()), false);
         else if (requirements.contains(TraverserRequirement.LABELED_PATH))
-            return new DefaultTraverser<>(start, startStep, initialBulk, ImmutablePath.make().extend(start,
startStep.getLabels()), true, requirements.contains(TraverserRequirement.ONE_BULK));
+            return new DefaultTraverser<>(start, startStep, requirements.contains(TraverserRequirement.ONE_BULK)
? -1 : initialBulk, ImmutablePath.make().extend(start, startStep.getLabels()), true);
         else
-            return new DefaultTraverser<>(start, startStep, initialBulk, EmptyPath.instance(),
true, requirements.contains(TraverserRequirement.ONE_BULK));
+            return new DefaultTraverser<>(start, startStep, requirements.contains(TraverserRequirement.ONE_BULK)
? -1 : initialBulk, EmptyPath.instance(), true);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/3cddfd46/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MatchStepTest.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MatchStepTest.java
b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MatchStepTest.java
index 3d827e4..71dcd99 100644
--- a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MatchStepTest.java
+++ b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MatchStepTest.java
@@ -362,7 +362,7 @@ public class MatchStepTest extends StepTest {
         countMatchAlgorithm.recordEnd(EmptyTraverser.instance(), forthPattern);
         countMatchAlgorithm.recordEnd(EmptyTraverser.instance(), forthPattern);
         //
-        Traverser.Admin traverser = new DefaultTraverser<>(1, EmptyStep.instance(),
1l, ImmutablePath.make().extend(1, Collections.emptySet()), false, false); // TODO: SHOULD
WORK WITH ONLY LABELED PATHS
+        Traverser.Admin traverser = new DefaultTraverser<>(1, EmptyStep.instance(),
1l, ImmutablePath.make().extend(1, Collections.emptySet()), false); // TODO: SHOULD WORK WITH
ONLY LABELED PATHS
         traverser.addLabels(Collections.singleton("a"));
         assertEquals(firstPattern, countMatchAlgorithm.apply(traverser));
         traverser = traverser.split(1, EmptyStep.instance());


Mime
View raw message