zyxxoo commented on code in PR #2262:
URL: 
https://github.com/apache/incubator-hugegraph/pull/2262#discussion_r1290951756


##########
hugegraph-core/src/main/java/org/apache/hugegraph/traversal/algorithm/CustomizedCrosspointsTraverser.java:
##########
@@ -24,26 +24,82 @@
 import java.util.Set;
 import java.util.stream.Collectors;
 
-import jakarta.ws.rs.core.MultivaluedMap;
-
 import org.apache.hugegraph.HugeGraph;
 import org.apache.hugegraph.backend.id.Id;
+import org.apache.hugegraph.structure.HugeEdge;
+import org.apache.hugegraph.structure.HugeVertex;
 import org.apache.hugegraph.traversal.algorithm.steps.EdgeStep;
 import org.apache.hugegraph.type.define.Directions;
+import org.apache.hugegraph.util.CollectionUtil;
+import org.apache.hugegraph.util.E;
 import org.apache.tinkerpop.gremlin.structure.Edge;
 import org.apache.tinkerpop.gremlin.structure.Vertex;
 
-import org.apache.hugegraph.structure.HugeEdge;
-import org.apache.hugegraph.structure.HugeVertex;
-import org.apache.hugegraph.util.CollectionUtil;
-import org.apache.hugegraph.util.E;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableSet;
 
+import jakarta.ws.rs.core.MultivaluedMap;
+
 public class CustomizedCrosspointsTraverser extends HugeTraverser {
 
+    private final EdgeRecord edgeRecord;
+
     public CustomizedCrosspointsTraverser(HugeGraph graph) {
         super(graph);
+        this.edgeRecord = new EdgeRecord(false);
+    }
+
+    private static CrosspointsPaths intersectionPaths(List<HugeVertex> sources,
+                                                      List<Path> paths,
+                                                      long limit) {
+        // Split paths by end vertices
+        MultivaluedMap<Id, Id> endVertices = newMultivalueMap();
+        for (Path path : paths) {
+            List<Id> vertices = path.vertices();
+            int length = vertices.size();
+            endVertices.add(vertices.get(0), vertices.get(length - 1));
+        }
+
+        Set<Id> sourceIds = sources.stream().map(HugeVertex::id)
+                                   .collect(Collectors.toSet());
+        Set<Id> ids = endVertices.keySet();
+        if (sourceIds.size() != ids.size() || !sourceIds.containsAll(ids)) {
+            return CrosspointsPaths.EMPTY;
+        }
+
+        // Get intersection of end vertices
+        Collection<Id> intersection = null;
+        for (List<Id> ends : endVertices.values()) {
+            if (intersection == null) {
+                intersection = ends;
+            } else {
+                intersection = CollectionUtil.intersect(intersection, ends);
+            }
+            if (intersection == null || intersection.isEmpty()) {
+                return CrosspointsPaths.EMPTY;
+            }
+        }
+        assert intersection != null;
+        // Limit intersection number to limit crosspoints vertices in result
+        int size = intersection.size();
+        if (limit != NO_LIMIT && size > limit) {
+            intersection = newList(intersection).subList(0, size - 1);
+        }
+
+        // Filter intersection paths
+        List<Path> results = newList();
+        for (Path path : paths) {
+            List<Id> vertices = path.vertices();
+            int length = vertices.size();
+            if (intersection.contains(vertices.get(length - 1))) {

Review Comment:
   try keep origin code



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to