Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refact: unify kout/kneighbor get method with post #1470

Merged
merged 1 commit into from
May 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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