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/04/24 22:07:50 UTC

[5/7] incubator-tinkerpop git commit: back to original serialization model for StarGraph now that adjacent labels are not required.

back to original serialization model for StarGraph now that adjacent labels are not required.


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

Branch: refs/heads/p-predicate-model
Commit: bd182de88b7bc8f24ee9261fb8e4f80914fc172a
Parents: 8048b1e
Author: Marko A. Rodriguez <ok...@gmail.com>
Authored: Fri Apr 24 14:01:29 2015 -0600
Committer: Marko A. Rodriguez <ok...@gmail.com>
Committed: Fri Apr 24 14:01:43 2015 -0600

----------------------------------------------------------------------
 .../gremlin/structure/io/gryo/GryoMapper.java   |  6 +-
 .../gremlin/structure/util/star/StarGraph.java  | 23 ++---
 .../util/star/StarGraphSerializer.java          | 17 ++--
 .../tinkerpop/gremlin/util/tools/BiMap.java     | 92 --------------------
 4 files changed, 14 insertions(+), 124 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/bd182de8/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoMapper.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoMapper.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoMapper.java
index 85b599a..9297f50 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoMapper.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoMapper.java
@@ -23,8 +23,8 @@ import org.apache.tinkerpop.gremlin.process.computer.util.MapMemory;
 import org.apache.tinkerpop.gremlin.process.traversal.Path;
 import org.apache.tinkerpop.gremlin.process.traversal.step.util.BulkSet;
 import org.apache.tinkerpop.gremlin.process.traversal.step.util.Tree;
-import org.apache.tinkerpop.gremlin.process.traversal.traverser.B_O_S_SE_SL_Traverser;
 import org.apache.tinkerpop.gremlin.process.traversal.traverser.B_O_P_S_SE_SL_Traverser;
+import org.apache.tinkerpop.gremlin.process.traversal.traverser.B_O_S_SE_SL_Traverser;
 import org.apache.tinkerpop.gremlin.process.traversal.traverser.B_O_Traverser;
 import org.apache.tinkerpop.gremlin.process.traversal.traverser.O_Traverser;
 import org.apache.tinkerpop.gremlin.process.traversal.traverser.util.TraverserSet;
@@ -52,7 +52,6 @@ import org.apache.tinkerpop.gremlin.structure.util.reference.ReferenceVertex;
 import org.apache.tinkerpop.gremlin.structure.util.reference.ReferenceVertexProperty;
 import org.apache.tinkerpop.gremlin.structure.util.star.StarGraph;
 import org.apache.tinkerpop.gremlin.structure.util.star.StarGraphSerializer;
-import org.apache.tinkerpop.gremlin.util.tools.BiMap;
 import org.apache.tinkerpop.shaded.kryo.Kryo;
 import org.apache.tinkerpop.shaded.kryo.KryoSerializable;
 import org.apache.tinkerpop.shaded.kryo.Serializer;
@@ -199,8 +198,7 @@ public final class GryoMapper implements Mapper<Kryo> {
             add(Triplet.<Class, Function<Kryo, Serializer>, Integer>with(ReferenceVertex.class, null, 84));
             add(Triplet.<Class, Function<Kryo, Serializer>, Integer>with(ReferencePath.class, null, 85));
 
-            add(Triplet.<Class, Function<Kryo, Serializer>, Integer>with(StarGraph.class, kryo -> StarGraphSerializer.with(Direction.BOTH), 86));
-            add(Triplet.<Class, Function<Kryo, Serializer>, Integer>with(BiMap.class, null, 87));// ***LAST ID**
+            add(Triplet.<Class, Function<Kryo, Serializer>, Integer>with(StarGraph.class, kryo -> StarGraphSerializer.with(Direction.BOTH), 86)); // ***LAST ID**
 
             add(Triplet.<Class, Function<Kryo, Serializer>, Integer>with(Edge.class, kryo -> new GraphSerializer.EdgeSerializer(), 65));
             add(Triplet.<Class, Function<Kryo, Serializer>, Integer>with(Vertex.class, kryo -> new GraphSerializer.VertexSerializer(), 66));

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/bd182de8/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/star/StarGraph.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/star/StarGraph.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/star/StarGraph.java
index 98e745c..d7562fb 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/star/StarGraph.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/star/StarGraph.java
@@ -37,7 +37,6 @@ import org.apache.tinkerpop.gremlin.structure.util.Attachable;
 import org.apache.tinkerpop.gremlin.structure.util.ElementHelper;
 import org.apache.tinkerpop.gremlin.structure.util.StringFactory;
 import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils;
-import org.apache.tinkerpop.gremlin.util.tools.BiMap;
 
 import java.io.Serializable;
 import java.util.ArrayList;
@@ -64,8 +63,6 @@ public final class StarGraph implements Graph, Serializable {
     protected StarVertex starVertex = null;
     protected Map<Object, Map<String, Object>> edgeProperties = null;
     protected Map<Object, Map<String, Object>> metaProperties = null;
-    protected BiMap<Short, String> labelsAndKeys = new BiMap<>();
-    protected short nextLabelsAndKeysId = Short.MIN_VALUE;  // 64k unique labels allowed
 
     private StarGraph() {
     }
@@ -202,15 +199,11 @@ public final class StarGraph implements Graph, Serializable {
     public abstract class StarElement<E extends Element> implements Element, Attachable<E> {
 
         protected final Object id;
-        protected final short labelId;
+        protected final String label;
 
         protected StarElement(final Object id, final String label) {
             this.id = id;
-            if (!labelsAndKeys.containsValue(label.intern())) {
-                this.labelId = nextLabelsAndKeysId++;
-                labelsAndKeys.put(this.labelId, label.intern());
-            } else
-                this.labelId = labelsAndKeys.getKey(label.intern());
+            this.label = label.intern();
         }
 
         @Override
@@ -220,7 +213,7 @@ public final class StarGraph implements Graph, Serializable {
 
         @Override
         public String label() {
-            return labelsAndKeys.getValue(this.labelId);
+            return this.label;
         }
 
         @Override
@@ -659,23 +652,19 @@ public final class StarGraph implements Graph, Serializable {
 
     public final class StarProperty<V> implements Property<V>, Attachable<Property<V>> {
 
-        private final short keyId;
+        private final String key;
         private final V value;
         private final Element element;
 
         private StarProperty(final String key, final V value, final Element element) {
-            if (!labelsAndKeys.containsValue(key.intern())) {
-                this.keyId = nextLabelsAndKeysId++;
-                labelsAndKeys.put(this.keyId, key.intern());
-            } else
-                this.keyId = labelsAndKeys.getKey(key.intern());
+            this.key = key.intern();
             this.value = value;
             this.element = element;
         }
 
         @Override
         public String key() {
-            return labelsAndKeys.getValue(this.keyId);
+            return this.key();
         }
 
         @Override

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/bd182de8/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/star/StarGraphSerializer.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/star/StarGraphSerializer.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/star/StarGraphSerializer.java
index 9107142..8ab1d4b 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/star/StarGraphSerializer.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/star/StarGraphSerializer.java
@@ -25,7 +25,6 @@ import org.apache.tinkerpop.gremlin.structure.Direction;
 import org.apache.tinkerpop.gremlin.structure.Edge;
 import org.apache.tinkerpop.gremlin.structure.T;
 import org.apache.tinkerpop.gremlin.structure.VertexProperty;
-import org.apache.tinkerpop.gremlin.util.tools.BiMap;
 import org.apache.tinkerpop.shaded.kryo.Kryo;
 import org.apache.tinkerpop.shaded.kryo.Serializer;
 import org.apache.tinkerpop.shaded.kryo.io.Input;
@@ -69,17 +68,15 @@ public final class StarGraphSerializer extends Serializer<StarGraph> {
         kryo.writeObject(output, starGraph.nextId);
         kryo.writeObjectOrNull(output, starGraph.edgeProperties, HashMap.class);
         kryo.writeObjectOrNull(output, starGraph.metaProperties, HashMap.class);
-        kryo.writeObject(output, starGraph.labelsAndKeys);
-        kryo.writeObject(output, starGraph.nextLabelsAndKeysId);
         kryo.writeClassAndObject(output, starGraph.starVertex.id);
-        kryo.writeObject(output, starGraph.starVertex.labelId);
+        kryo.writeObject(output, starGraph.starVertex.label);
         writeEdges(kryo, output, starGraph, Direction.IN);
         writeEdges(kryo, output, starGraph, Direction.OUT);
         kryo.writeObject(output, null != starGraph.starVertex.vertexProperties);
         if (null != starGraph.starVertex.vertexProperties) {
             kryo.writeObject(output, starGraph.starVertex.vertexProperties.size());
             for (final Map.Entry<String, List<VertexProperty>> vertexProperties : starGraph.starVertex.vertexProperties.entrySet()) {
-                kryo.writeObject(output, starGraph.labelsAndKeys.getKey(vertexProperties.getKey()));
+                kryo.writeObject(output, vertexProperties.getKey());
                 kryo.writeObject(output, vertexProperties.getValue().size());
                 for (final VertexProperty vertexProperty : vertexProperties.getValue()) {
                     kryo.writeClassAndObject(output, vertexProperty.id());
@@ -95,15 +92,13 @@ public final class StarGraphSerializer extends Serializer<StarGraph> {
         starGraph.nextId = kryo.readObject(input, Long.class);
         starGraph.edgeProperties = kryo.readObjectOrNull(input, HashMap.class);
         starGraph.metaProperties = kryo.readObjectOrNull(input, HashMap.class);
-        starGraph.labelsAndKeys = kryo.readObject(input, BiMap.class);
-        starGraph.nextLabelsAndKeysId = kryo.readObject(input, Short.class);
-        starGraph.addVertex(T.id, kryo.readClassAndObject(input), T.label, starGraph.labelsAndKeys.getValue(kryo.readObject(input, Short.class)));
+        starGraph.addVertex(T.id, kryo.readClassAndObject(input), T.label, kryo.readObject(input, String.class));
         readEdges(kryo, input, starGraph, Direction.IN);
         readEdges(kryo, input, starGraph, Direction.OUT);
         if (kryo.readObject(input, Boolean.class)) {
             final int numberOfUniqueKeys = kryo.readObject(input, Integer.class);
             for (int i = 0; i < numberOfUniqueKeys; i++) {
-                final String vertexPropertyKey = starGraph.labelsAndKeys.getValue(kryo.readObject(input, Short.class));
+                final String vertexPropertyKey = kryo.readObject(input, String.class);
                 final int numberOfVertexPropertiesWithKey = kryo.readObject(input, Integer.class);
                 for (int j = 0; j < numberOfVertexPropertiesWithKey; j++) {
                     final Object id = kryo.readClassAndObject(input);
@@ -125,7 +120,7 @@ public final class StarGraphSerializer extends Serializer<StarGraph> {
         if (writeEdges) {
             kryo.writeObject(output, starEdges.size());
             for (final Map.Entry<String, List<Edge>> edges : starEdges.entrySet()) {
-                kryo.writeObject(output, starGraph.labelsAndKeys.getKey(edges.getKey()));
+                kryo.writeObject(output, edges.getKey());
                 kryo.writeObject(output, edges.getValue().size());
                 for (final Edge edge : edges.getValue()) {
                     kryo.writeClassAndObject(output, edge.id());
@@ -139,7 +134,7 @@ public final class StarGraphSerializer extends Serializer<StarGraph> {
         if (kryo.readObject(input, Boolean.class)) {
             final int numberOfUniqueLabels = kryo.readObject(input, Integer.class);
             for (int i = 0; i < numberOfUniqueLabels; i++) {
-                final String edgeLabel = starGraph.labelsAndKeys.getValue(kryo.readObject(input, Short.class));
+                final String edgeLabel = kryo.readObject(input, String.class);
                 final int numberOfEdgesWithLabel = kryo.readObject(input, Integer.class);
                 for (int j = 0; j < numberOfEdgesWithLabel; j++) {
                     final Object edgeId = kryo.readClassAndObject(input);

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/bd182de8/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/util/tools/BiMap.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/util/tools/BiMap.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/util/tools/BiMap.java
deleted file mode 100644
index 29dc4cf..0000000
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/util/tools/BiMap.java
+++ /dev/null
@@ -1,92 +0,0 @@
-/*
- *
- *  * Licensed to the Apache Software Foundation (ASF) under one
- *  * or more contributor license agreements.  See the NOTICE file
- *  * distributed with this work for additional information
- *  * regarding copyright ownership.  The ASF licenses this file
- *  * to you under the Apache License, Version 2.0 (the
- *  * "License"); you may not use this file except in compliance
- *  * with the License.  You may obtain a copy of the License at
- *  *
- *  * http://www.apache.org/licenses/LICENSE-2.0
- *  *
- *  * Unless required by applicable law or agreed to in writing,
- *  * software distributed under the License is distributed on an
- *  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- *  * KIND, either express or implied.  See the License for the
- *  * specific language governing permissions and limitations
- *  * under the License.
- *
- */
-
-package org.apache.tinkerpop.gremlin.util.tools;
-
-import java.io.Serializable;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Set;
-
-/**
- * @author Marko A. Rodriguez (http://markorodriguez.com)
- */
-public class BiMap<K, V> implements Serializable {
-
-    private Map<K, V> leftMap = new HashMap<>();
-    private Map<V, K> rightMap = new HashMap<>();
-
-    public int size() {
-        return this.leftMap.size();
-    }
-
-    public boolean isEmpty() {
-        return this.leftMap.isEmpty();
-    }
-
-    public boolean containsKey(final K key) {
-        return this.leftMap.containsKey(key);
-    }
-
-    public boolean containsValue(final V value) {
-        return this.rightMap.containsKey(value);
-    }
-
-    public V getValue(final K key) {
-        return this.leftMap.get(key);
-    }
-
-    public K getKey(final V value) {
-        return this.rightMap.get(value);
-    }
-
-    public V put(final K key, final V value) {
-        this.rightMap.put(value, key);
-        return this.leftMap.put(key, value);
-    }
-
-    public V removeKey(final K key) {
-        final V v = this.leftMap.remove(key);
-        if (null != v)
-            this.rightMap.remove(v);
-        return v;
-    }
-
-    public K removeValue(final V value) {
-        final K k = this.rightMap.remove(value);
-        if (null != k)
-            this.leftMap.remove(k);
-        return k;
-    }
-
-    public void clear() {
-        this.leftMap.clear();
-        this.rightMap.clear();
-    }
-
-    public Set<K> keySet() {
-        return this.leftMap.keySet();
-    }
-
-    public Set<V> valueSet() {
-        return this.rightMap.keySet();
-    }
-}