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


##########
hugegraph-core/src/main/java/org/apache/hugegraph/traversal/algorithm/SameNeighborTraverser.java:
##########
@@ -46,15 +48,60 @@
         Id labelId = this.getEdgeLabelId(label);
 
         Set<Id> sourceNeighbors = IteratorUtils.set(this.adjacentVertices(
-                                  vertex, direction, labelId, degree));
+                vertex, direction, labelId, degree));
         Set<Id> targetNeighbors = IteratorUtils.set(this.adjacentVertices(
-                                  other, direction, labelId, degree));
+                other, direction, labelId, degree));
         Set<Id> sameNeighbors = (Set<Id>) CollectionUtil.intersect(
-                                sourceNeighbors, targetNeighbors);
+                sourceNeighbors, targetNeighbors);
+
+        this.vertexIterCounter.addAndGet(2L);
+        this.edgeIterCounter.addAndGet(sourceNeighbors.size());
+        this.edgeIterCounter.addAndGet(targetNeighbors.size());
+
         if (limit != NO_LIMIT) {
             int end = Math.min(sameNeighbors.size(), limit);
             sameNeighbors = CollectionUtil.subSet(sameNeighbors, 0, end);
         }
         return sameNeighbors;
     }
+
+    public Set<Id> sameNeighbors(List<Id> vertexIds, Directions direction,
+                                 List<String> labels, long degree, long limit) 
{
+        E.checkNotNull(vertexIds, "vertex ids");
+        E.checkArgument(vertexIds.size() >= 2, "vertex_list size can't " +
+                                               "be less than 2");
+        for (Id id : vertexIds) {
+            this.checkVertexExist(id, "vertex");
+        }
+        E.checkNotNull(direction, "direction");
+        checkDegree(degree);
+        checkLimit(limit);
+
+        List<Id> labelsId = new ArrayList<>();
+        if (labels != null) {
+            for (String label : labels) {
+                labelsId.add(this.getEdgeLabelId(label));
+            }
+        }
+
+        Set<Id> sameNeighbors = new HashSet<>();
+        for (int i = 0; i < vertexIds.size(); i++) {
+            Set<Id> vertexNeighbors = IteratorUtils.set(this.adjacentVertices(
+                    vertexIds.get(i), direction, labelsId, degree));
+            if (i == 0) {
+                sameNeighbors = vertexNeighbors;
+            } else {
+                sameNeighbors = (Set<Id>) CollectionUtil.intersect(
+                        sameNeighbors, vertexNeighbors);
+            }
+            this.vertexIterCounter.addAndGet(1L);
+            this.edgeIterCounter.addAndGet(vertexNeighbors.size());
+        }
+
+        if (limit != NO_LIMIT) {
+            int end = Math.min(sameNeighbors.size(), (int) limit);

Review Comment:
   fixed



-- 
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