You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hugegraph.apache.org by ji...@apache.org on 2022/11/09 10:25:24 UTC

[incubator-hugegraph] 21/33: fix DegreeCentrality degree count limit OOL (#39)

This is an automated email from the ASF dual-hosted git repository.

jin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-hugegraph.git

commit 37bd25170827b1d3d0fc8196499e5abf29916767
Author: Jermy Li <li...@baidu.com>
AuthorDate: Sun Aug 16 19:30:16 2020 +0800

    fix DegreeCentrality degree count limit OOL (#39)
    
    Change-Id: I1b055130c75edce039a97822d9154e1214bc80c2
---
 .../job/algorithm/cent/DegreeCentralityAlgorithm.java        | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/job/algorithm/cent/DegreeCentralityAlgorithm.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/job/algorithm/cent/DegreeCentralityAlgorithm.java
index b2030e845..54b72c2bf 100644
--- a/hugegraph-core/src/main/java/com/baidu/hugegraph/job/algorithm/cent/DegreeCentralityAlgorithm.java
+++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/job/algorithm/cent/DegreeCentralityAlgorithm.java
@@ -19,16 +19,18 @@
 
 package com.baidu.hugegraph.job.algorithm.cent;
 
+import java.util.Arrays;
 import java.util.Iterator;
+import java.util.List;
 import java.util.Map;
 
 import org.apache.tinkerpop.gremlin.structure.Edge;
 import org.apache.tinkerpop.gremlin.structure.Vertex;
-import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils;
 
 import com.baidu.hugegraph.backend.id.Id;
 import com.baidu.hugegraph.job.UserJob;
 import com.baidu.hugegraph.structure.HugeEdge;
+import com.baidu.hugegraph.traversal.algorithm.EdgeStep;
 import com.baidu.hugegraph.type.define.Directions;
 
 public class DegreeCentralityAlgorithm extends AbstractCentAlgorithm {
@@ -153,10 +155,10 @@ public class DegreeCentralityAlgorithm extends AbstractCentAlgorithm {
         }
 
         private long degree(Id source, String label) {
-            Id labelId = this.getEdgeLabelId(label);
-            Iterator<Edge> edges = this.edgesOfVertex(source, Directions.BOTH,
-                                                      labelId, NO_LIMIT);
-            return IteratorUtils.count(edges);
+            List<String> labels = label == null ? null : Arrays.asList(label);
+            EdgeStep step = new EdgeStep(this.graph(), Directions.BOTH,
+                                         labels, null, NO_LIMIT, 0);
+            return this.edgesCount(source, step);
         }
     }
 }