You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by ok...@apache.org on 2015/03/17 21:09:16 UTC
incubator-tinkerpop git commit: a big optimization for star-graph
usage of TinkerGraph. The adjacent vertices don't need to have outEdges. Save
a HashMap on each edge of each Vertex in that case.
Repository: incubator-tinkerpop
Updated Branches:
refs/heads/master 252b3f0d3 -> 67f112f6e
a big optimization for star-graph usage of TinkerGraph. The adjacent vertices don't need to have outEdges. Save a HashMap on each edge of each Vertex in that case.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/67f112f6
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/67f112f6
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/67f112f6
Branch: refs/heads/master
Commit: 67f112f6e0162bd3ce4b4b2341fa39628adfd0f9
Parents: 252b3f0
Author: Marko A. Rodriguez <ok...@gmail.com>
Authored: Tue Mar 17 14:09:11 2015 -0600
Committer: Marko A. Rodriguez <ok...@gmail.com>
Committed: Tue Mar 17 14:09:11 2015 -0600
----------------------------------------------------------------------
.../tinkergraph/structure/TinkerEdge.java | 5 +-
.../tinkergraph/structure/TinkerElement.java | 1 -
.../tinkergraph/structure/TinkerHelper.java | 63 ++++++++++++--------
.../tinkergraph/structure/TinkerVertex.java | 5 +-
.../structure/TinkerVertexProperty.java | 8 +--
5 files changed, 45 insertions(+), 37 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/67f112f6/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerEdge.java
----------------------------------------------------------------------
diff --git a/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerEdge.java b/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerEdge.java
index c08bb81..a1916b4 100644
--- a/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerEdge.java
+++ b/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerEdge.java
@@ -67,13 +67,12 @@ public class TinkerEdge extends TinkerElement implements Edge {
@Override
public <V> Property<V> property(final String key) {
if (this.removed) throw Element.Exceptions.elementAlreadyRemoved(this.getClass(), this.id);
- return null != this.properties && this.properties.containsKey(key) ? this.properties.get(key) : Property.<V>empty();
+ return null == this.properties ? Property.<V>empty() : this.properties.getOrDefault(key, Property.<V>empty());
}
@Override
public Set<String> keys() {
- if (null == this.properties) return Collections.emptySet();
- return this.properties.keySet();
+ return null == this.properties ? Collections.emptySet() : this.properties.keySet();
}
@Override
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/67f112f6/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerElement.java
----------------------------------------------------------------------
diff --git a/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerElement.java b/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerElement.java
index 3b64ced..fcdb09d 100644
--- a/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerElement.java
+++ b/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerElement.java
@@ -26,7 +26,6 @@ import org.apache.tinkerpop.gremlin.structure.util.ElementHelper;
*/
public abstract class TinkerElement implements Element {
-
protected final Object id;
protected final String label;
protected boolean removed = false;
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/67f112f6/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerHelper.java
----------------------------------------------------------------------
diff --git a/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerHelper.java b/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerHelper.java
index 5f4d682..33e5c01 100644
--- a/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerHelper.java
+++ b/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerHelper.java
@@ -29,6 +29,7 @@ import org.apache.tinkerpop.gremlin.tinkergraph.process.computer.TinkerGraphView
import java.util.ArrayList;
import java.util.Collections;
+import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
@@ -73,6 +74,7 @@ public final class TinkerHelper {
}
protected static void addOutEdge(final TinkerVertex vertex, final String label, final Edge edge) {
+ if (null == vertex.outEdges) vertex.outEdges = new HashMap<>();
Set<Edge> edges = vertex.outEdges.get(label);
if (null == edges) {
edges = new HashSet<>();
@@ -82,6 +84,7 @@ public final class TinkerHelper {
}
protected static void addInEdge(final TinkerVertex vertex, final String label, final Edge edge) {
+ if (null == vertex.inEdges) vertex.inEdges = new HashMap<>();
Set<Edge> edges = vertex.inEdges.get(label);
if (null == edges) {
edges = new HashSet<>();
@@ -146,44 +149,52 @@ public final class TinkerHelper {
graph.edgeIndex.remove(key, value, edge);
}
- public static final Iterator<TinkerEdge> getEdges(final TinkerVertex vertex, final Direction direction, final String... edgeLabels) {
+ public static Iterator<TinkerEdge> getEdges(final TinkerVertex vertex, final Direction direction, final String... edgeLabels) {
final List<Edge> edges = new ArrayList<>();
if (direction.equals(Direction.OUT) || direction.equals(Direction.BOTH)) {
- if (edgeLabels.length == 0)
- vertex.outEdges.values().forEach(edges::addAll);
- else if (edgeLabels.length == 1)
- edges.addAll(vertex.outEdges.getOrDefault(edgeLabels[0], Collections.emptySet()));
- else
- Stream.of(edgeLabels).map(vertex.outEdges::get).filter(Objects::nonNull).forEach(edges::addAll);
+ if (vertex.outEdges != null) {
+ if (edgeLabels.length == 0)
+ vertex.outEdges.values().forEach(edges::addAll);
+ else if (edgeLabels.length == 1)
+ edges.addAll(vertex.outEdges.getOrDefault(edgeLabels[0], Collections.emptySet()));
+ else
+ Stream.of(edgeLabels).map(vertex.outEdges::get).filter(Objects::nonNull).forEach(edges::addAll);
+ }
}
if (direction.equals(Direction.IN) || direction.equals(Direction.BOTH)) {
- if (edgeLabels.length == 0)
- vertex.inEdges.values().forEach(edges::addAll);
- else if (edgeLabels.length == 1)
- edges.addAll(vertex.inEdges.getOrDefault(edgeLabels[0], Collections.emptySet()));
- else
- Stream.of(edgeLabels).map(vertex.inEdges::get).filter(Objects::nonNull).forEach(edges::addAll);
+ if (vertex.inEdges != null) {
+ if (edgeLabels.length == 0)
+ vertex.inEdges.values().forEach(edges::addAll);
+ else if (edgeLabels.length == 1)
+ edges.addAll(vertex.inEdges.getOrDefault(edgeLabels[0], Collections.emptySet()));
+ else
+ Stream.of(edgeLabels).map(vertex.inEdges::get).filter(Objects::nonNull).forEach(edges::addAll);
+ }
}
return (Iterator) edges.iterator();
}
- public static final Iterator<TinkerVertex> getVertices(final TinkerVertex vertex, final Direction direction, final String... edgeLabels) {
+ public static Iterator<TinkerVertex> getVertices(final TinkerVertex vertex, final Direction direction, final String... edgeLabels) {
final List<Vertex> vertices = new ArrayList<>();
if (direction.equals(Direction.OUT) || direction.equals(Direction.BOTH)) {
- if (edgeLabels.length == 0)
- vertex.outEdges.values().forEach(set -> set.forEach(edge -> vertices.add(((TinkerEdge) edge).inVertex)));
- else if (edgeLabels.length == 1)
- vertex.outEdges.getOrDefault(edgeLabels[0], Collections.emptySet()).forEach(edge -> vertices.add(((TinkerEdge) edge).inVertex));
- else
- Stream.of(edgeLabels).map(vertex.outEdges::get).filter(Objects::nonNull).flatMap(Set::stream).forEach(edge -> vertices.add(((TinkerEdge) edge).inVertex));
+ if (vertex.outEdges != null) {
+ if (edgeLabels.length == 0)
+ vertex.outEdges.values().forEach(set -> set.forEach(edge -> vertices.add(((TinkerEdge) edge).inVertex)));
+ else if (edgeLabels.length == 1)
+ vertex.outEdges.getOrDefault(edgeLabels[0], Collections.emptySet()).forEach(edge -> vertices.add(((TinkerEdge) edge).inVertex));
+ else
+ Stream.of(edgeLabels).map(vertex.outEdges::get).filter(Objects::nonNull).flatMap(Set::stream).forEach(edge -> vertices.add(((TinkerEdge) edge).inVertex));
+ }
}
if (direction.equals(Direction.IN) || direction.equals(Direction.BOTH)) {
- if (edgeLabels.length == 0)
- vertex.inEdges.values().forEach(set -> set.forEach(edge -> vertices.add(((TinkerEdge) edge).outVertex)));
- else if (edgeLabels.length == 1)
- vertex.inEdges.getOrDefault(edgeLabels[0], Collections.emptySet()).forEach(edge -> vertices.add(((TinkerEdge) edge).outVertex));
- else
- Stream.of(edgeLabels).map(vertex.inEdges::get).filter(Objects::nonNull).flatMap(Set::stream).forEach(edge -> vertices.add(((TinkerEdge) edge).outVertex));
+ if (vertex.inEdges != null) {
+ if (edgeLabels.length == 0)
+ vertex.inEdges.values().forEach(set -> set.forEach(edge -> vertices.add(((TinkerEdge) edge).outVertex)));
+ else if (edgeLabels.length == 1)
+ vertex.inEdges.getOrDefault(edgeLabels[0], Collections.emptySet()).forEach(edge -> vertices.add(((TinkerEdge) edge).outVertex));
+ else
+ Stream.of(edgeLabels).map(vertex.inEdges::get).filter(Objects::nonNull).flatMap(Set::stream).forEach(edge -> vertices.add(((TinkerEdge) edge).outVertex));
+ }
}
return (Iterator) vertices.iterator();
}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/67f112f6/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerVertex.java
----------------------------------------------------------------------
diff --git a/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerVertex.java b/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerVertex.java
index c99339b..0924ae0 100644
--- a/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerVertex.java
+++ b/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerVertex.java
@@ -22,7 +22,6 @@ import org.apache.tinkerpop.gremlin.structure.Direction;
import org.apache.tinkerpop.gremlin.structure.Edge;
import org.apache.tinkerpop.gremlin.structure.Element;
import org.apache.tinkerpop.gremlin.structure.Graph;
-import org.apache.tinkerpop.gremlin.structure.Property;
import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.apache.tinkerpop.gremlin.structure.VertexProperty;
import org.apache.tinkerpop.gremlin.structure.util.ElementHelper;
@@ -45,8 +44,8 @@ import java.util.stream.Collectors;
public class TinkerVertex extends TinkerElement implements Vertex {
protected Map<String, List<VertexProperty>> properties;
- protected Map<String, Set<Edge>> outEdges = new HashMap<>();
- protected Map<String, Set<Edge>> inEdges = new HashMap<>();
+ protected Map<String, Set<Edge>> outEdges;
+ protected Map<String, Set<Edge>> inEdges;
private static final Object[] EMPTY_ARGS = new Object[0];
private final TinkerGraph graph;
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/67f112f6/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerVertexProperty.java
----------------------------------------------------------------------
diff --git a/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerVertexProperty.java b/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerVertexProperty.java
index 31f11aa..66f15ea 100644
--- a/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerVertexProperty.java
+++ b/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerVertexProperty.java
@@ -87,6 +87,7 @@ public class TinkerVertexProperty<V> extends TinkerElement implements VertexProp
return this.id;
}
+ @SuppressWarnings("EqualsWhichDoesntCheckParameterClass")
@Override
public boolean equals(final Object object) {
return ElementHelper.areEqual(this, object);
@@ -94,19 +95,18 @@ public class TinkerVertexProperty<V> extends TinkerElement implements VertexProp
@Override
public Set<String> keys() {
- if (null == this.properties) return Collections.emptySet();
- return this.properties.keySet();
+ return null == this.properties ? Collections.emptySet() : this.properties.keySet();
}
@Override
public <U> Property<U> property(final String key) {
if (this.removed) throw Element.Exceptions.elementAlreadyRemoved(this.getClass(), this.id);
- return null != this.properties && this.properties.containsKey(key) ? this.properties.get(key) : Property.<U>empty();
+ return null == this.properties ? Property.<U>empty() : this.properties.getOrDefault(key, Property.<U>empty());
}
@Override
public <U> Property<U> property(final String key, final U value) {
- final Property<U> property = new TinkerProperty<U>(this, key, value);
+ final Property<U> property = new TinkerProperty<>(this, key, value);
if (this.properties == null) this.properties = new HashMap<>();
this.properties.put(key, property);
return property;