diff --git a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/traversers/CountAPI.java b/hugegraph-api/src/main/java/com/baidu/hugegraph/api/traversers/CountAPI.java index 43eaaada71..ecda4ad32d 100644 --- a/hugegraph-api/src/main/java/com/baidu/hugegraph/api/traversers/CountAPI.java +++ b/hugegraph-api/src/main/java/com/baidu/hugegraph/api/traversers/CountAPI.java @@ -141,7 +141,8 @@ public String toString() { private EdgeStep jsonToStep(HugeGraph graph) { return new EdgeStep(graph, this.direction, this.labels, - this.properties, this.maxDegree, this.skipDegree); + this.properties, this.maxDegree, + this.skipDegree); } } } diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/algorithm/HugeTraverser.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/algorithm/HugeTraverser.java index 0c85111d6c..3ec1362b8b 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/algorithm/HugeTraverser.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/algorithm/HugeTraverser.java @@ -97,9 +97,10 @@ protected int concurrentDepth() { return this.graph.option(CoreOptions.OLTP_CONCURRENT_DEPTH); } - protected Set adjacentVertices(Set vertices, Directions dir, - Id label, Set excluded, - long degree, long limit) { + protected Set adjacentVertices(Id sourceV, Set vertices, + Directions dir, Id label, + Set excluded, long degree, + long limit) { if (limit == 0) { return ImmutableSet.of(); } @@ -111,7 +112,10 @@ protected Set adjacentVertices(Set vertices, Directions dir, while (edges.hasNext()) { HugeEdge e = (HugeEdge) edges.next(); Id target = e.id().otherVertexId(); - if (excluded != null && excluded.contains(target)) { + boolean matchExcluded = (excluded != null && + excluded.contains(target)); + if (matchExcluded || neighbors.contains(target) || + sourceV.equals(target)) { continue; } neighbors.add(target); @@ -376,8 +380,8 @@ public static void checkSkipDegree(long skipDegree, long degree, } if (skipDegree > 0L) { E.checkArgument(degree != NO_LIMIT && skipDegree >= degree, - "The skipped degree must be >= degree, " + - "but got skipped degree '%s' and degree '%s'", + "The skipped degree must be >= max degree, " + + "but got skipped degree '%s' and max degree '%s'", skipDegree, degree); } } diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/algorithm/KneighborTraverser.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/algorithm/KneighborTraverser.java index 189394ec12..3403a53c25 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/algorithm/KneighborTraverser.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/algorithm/KneighborTraverser.java @@ -47,15 +47,14 @@ public Set kneighbor(Id sourceV, Directions dir, Id labelId = this.getEdgeLabelId(label); Set latest = newSet(); - latest.add(sourceV); - Set all = newSet(); - all.add(sourceV); + + latest.add(sourceV); while (depth-- > 0) { long remaining = limit == NO_LIMIT ? NO_LIMIT : limit - all.size(); - latest = this.adjacentVertices(latest, dir, labelId, all, - degree, remaining); + latest = this.adjacentVertices(sourceV, latest, dir, labelId, + all, degree, remaining); all.addAll(latest); if (limit != NO_LIMIT && all.size() >= limit) { break; diff --git a/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/algorithm/KoutTraverser.java b/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/algorithm/KoutTraverser.java index f7a2a276f0..ec8e108c94 100644 --- a/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/algorithm/KoutTraverser.java +++ b/hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/algorithm/KoutTraverser.java @@ -70,12 +70,12 @@ public Set kout(Id sourceV, Directions dir, String label, remaining = limit; } if (nearest) { - latest = this.adjacentVertices(latest, dir, labelId, all, - degree, remaining); + latest = this.adjacentVertices(sourceV, latest, dir, labelId, + all, degree, remaining); all.addAll(latest); } else { - latest = this.adjacentVertices(latest, dir, labelId, null, - degree, remaining); + latest = this.adjacentVertices(sourceV, latest, dir, labelId, + null, degree, remaining); } if (capacity != NO_LIMIT) { // Update 'remaining' value to record remaining capacity