Skip to content

Commit

Permalink
refact: unify kout/kneighbor get method with post (apache#1470)
Browse files Browse the repository at this point in the history
  • Loading branch information
imbajin authored and jadepeng committed Jun 25, 2021
1 parent 8a84180 commit fc132a5
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,10 @@ protected int concurrentDepth() {
return this.graph.option(CoreOptions.OLTP_CONCURRENT_DEPTH);
}

protected Set<Id> adjacentVertices(Set<Id> vertices, Directions dir,
Id label, Set<Id> excluded,
long degree, long limit) {
protected Set<Id> adjacentVertices(Id sourceV, Set<Id> vertices,
Directions dir, Id label,
Set<Id> excluded, long degree,
long limit) {
if (limit == 0) {
return ImmutableSet.of();
}
Expand All @@ -111,7 +112,10 @@ protected Set<Id> adjacentVertices(Set<Id> 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);
Expand Down Expand Up @@ -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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,14 @@ public Set<Id> kneighbor(Id sourceV, Directions dir,
Id labelId = this.getEdgeLabelId(label);

Set<Id> latest = newSet();
latest.add(sourceV);

Set<Id> 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,12 @@ public Set<Id> 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
Expand Down

0 comments on commit fc132a5

Please sign in to comment.