Skip to content

Commit

Permalink
keep depth and degree consistent for traverser api
Browse files Browse the repository at this point in the history
fixed: #250

Change-Id: I0b429c00032c0cdf80090b8350be90f6f2b3f74b
  • Loading branch information
zhoney authored and Linary committed Dec 17, 2018
1 parent a1e56a5 commit 2480347
Show file tree
Hide file tree
Showing 11 changed files with 66 additions and 66 deletions.
2 changes: 1 addition & 1 deletion hugegraph-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
</addDefaultSpecificationEntries>
</manifest>
<manifestEntries>
<Implementation-Version>0.31.0.0</Implementation-Version>
<Implementation-Version>0.32.0.0</Implementation-Version>
</manifestEntries>
</archive>
</configuration>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,15 @@ public String get(@Context GraphManager manager,
@QueryParam("target") String target,
@QueryParam("direction") String direction,
@QueryParam("label") String edgeLabel,
@QueryParam("max_depth") int maxDepth,
@QueryParam("degree") @DefaultValue("-1") long degree,
@QueryParam("max_depth") int depth,
@QueryParam("max_degree") @DefaultValue("-1") long degree,
@QueryParam("capacity") @DefaultValue("-1") long capacity,
@QueryParam("limit") @DefaultValue("10") long limit) {
LOG.debug("Graph [{}] get crosspoints with paths from '{}', to '{}' " +
"with direction '{}', edge label '{}', max depth '{}', " +
"degree '{}', capacity '{}' and limit '{}'",
"max degree '{}', capacity '{}' and limit '{}'",
graph, source, target, direction, edgeLabel,
maxDepth, degree, capacity, limit);
depth, degree, capacity, limit);

Id sourceId = VertexAPI.checkAndParseVertexId(source);
Id targetId = VertexAPI.checkAndParseVertexId(target);
Expand All @@ -77,9 +77,9 @@ public String get(@Context GraphManager manager,
HugeTraverser traverser = new HugeTraverser(g);
Set<HugeTraverser.Path> paths = traverser.paths(sourceId, dir,
targetId, dir,
edgeLabel, maxDepth,
edgeLabel, depth,
degree, capacity,
limit);
return manager.serializer(g).writePaths("crosspoints", paths, true);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ public String get(@Context GraphManager manager,
@QueryParam("source") String sourceV,
@QueryParam("direction") String direction,
@QueryParam("label") String edgeLabel,
@QueryParam("depth") int depth,
@QueryParam("degree") @DefaultValue("-1") long degree,
@QueryParam("max_depth") int depth,
@QueryParam("max_degree") @DefaultValue("-1") long degree,
@QueryParam("limit") @DefaultValue("-1") long limit) {
LOG.debug("Graph [{}] get k-neighbor from '{}' with " +
"direction '{}', edge label '{}', depth '{}', " +
"degree '{}' and limit '{}'",
"direction '{}', edge label '{}', max depth '{}', " +
"max degree '{}' and limit '{}'",
graph, sourceV, direction, edgeLabel, depth,
degree, limit);

Expand All @@ -77,4 +77,4 @@ public String get(@Context GraphManager manager,
degree, limit);
return manager.serializer(g).writeIds("vertices", ids);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,15 @@ public String get(@Context GraphManager manager,
@QueryParam("source") String source,
@QueryParam("direction") String direction,
@QueryParam("label") String edgeLabel,
@QueryParam("depth") int depth,
@QueryParam("max_depth") int depth,
@QueryParam("nearest")
@DefaultValue("true") boolean nearest,
@QueryParam("degree") @DefaultValue("-1") long degree,
@QueryParam("max_degree") @DefaultValue("-1") long degree,
@QueryParam("capacity") @DefaultValue("-1") long capacity,
@QueryParam("limit") @DefaultValue("-1") long limit) {
LOG.debug("Graph [{}] get k-out from '{}' with " +
"direction '{}', edge label '{}', depth '{}', nearest '{}'," +
" degree '{}', capacity '{}' and limit '{}'",
"direction '{}', edge label '{}', max depth '{}', nearest " +
"'{}', max degree '{}', capacity '{}' and limit '{}'",
graph, source, direction, edgeLabel, depth, nearest,
degree, capacity, limit);

Expand All @@ -80,4 +80,4 @@ public String get(@Context GraphManager manager,
nearest, degree, capacity, limit);
return manager.serializer(g).writeIds("vertices", ids);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,14 @@ public String get(@Context GraphManager manager,
@QueryParam("target") String target,
@QueryParam("direction") String direction,
@QueryParam("label") String edgeLabel,
@QueryParam("max_depth") int maxDepth,
@QueryParam("degree") @DefaultValue("-1") long degree,
@QueryParam("max_depth") int depth,
@QueryParam("max_degree") @DefaultValue("-1") long degree,
@QueryParam("capacity") @DefaultValue("-1") long capacity,
@QueryParam("limit") @DefaultValue("10") long limit) {
LOG.debug("Graph [{}] get paths from '{}', to '{}' with " +
"direction {}, edge label {}, max depth '{}', " +
"degree '{}', capacity '{}' and limit '{}'",
graph, source, target, direction, edgeLabel, maxDepth,
"max degree '{}', capacity '{}' and limit '{}'",
graph, source, target, direction, edgeLabel, depth,
degree, capacity, limit);

Id sourceId = VertexAPI.checkAndParseVertexId(source);
Expand All @@ -77,7 +77,7 @@ public String get(@Context GraphManager manager,
HugeTraverser traverser = new HugeTraverser(g);
Set<HugeTraverser.Path> paths;
paths = traverser.paths(sourceId, dir, targetId, dir.opposite(),
edgeLabel, maxDepth, degree, capacity, limit);
edgeLabel, depth, degree, capacity, limit);
return manager.serializer(g).writePaths("paths", paths, false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@ public String get(@Context GraphManager manager,
@QueryParam("source") String sourceV,
@QueryParam("direction") String direction,
@QueryParam("label") String edgeLabel,
@QueryParam("depth") int depth,
@QueryParam("degree") @DefaultValue("-1") long degree,
@QueryParam("max_depth") int depth,
@QueryParam("max_degree") @DefaultValue("-1") long degree,
@QueryParam("capacity") @DefaultValue("-1") long capacity,
@QueryParam("limit") @DefaultValue("-1") long limit) {
LOG.debug("Graph [{}] get rays paths from '{}' with " +
"direction '{}', edge label '{}', depth '{}', " +
"degree '{}' and limit '{}'",
"direction '{}', edge label '{}', max depth '{}', " +
"max degree '{}' and limit '{}'",
graph, sourceV, direction, edgeLabel, depth, degree, limit);

Id source = VertexAPI.checkAndParseVertexId(sourceV);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@ public String get(@Context GraphManager manager,
@QueryParam("source") String sourceV,
@QueryParam("direction") String direction,
@QueryParam("label") String edgeLabel,
@QueryParam("depth") int depth,
@QueryParam("degree") @DefaultValue("-1") long degree,
@QueryParam("max_depth") int depth,
@QueryParam("max_degree") @DefaultValue("-1") long degree,
@QueryParam("capacity") @DefaultValue("-1") long capacity,
@QueryParam("limit") @DefaultValue("-1") long limit) {
LOG.debug("Graph [{}] get rings paths reachable from '{}' with " +
"direction '{}', edge label '{}', depth '{}', " +
"degree '{}' and limit '{}'",
"direction '{}', edge label '{}', max depth '{}', " +
"max degree '{}' and limit '{}'",
graph, sourceV, direction, edgeLabel, depth, degree, limit);

Id source = VertexAPI.checkAndParseVertexId(sourceV);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,14 @@ public String get(@Context GraphManager manager,
@QueryParam("target") String target,
@QueryParam("direction") String direction,
@QueryParam("label") String edgeLabel,
@QueryParam("max_depth") int maxDepth,
@QueryParam("degree") @DefaultValue("-1") long degree,
@QueryParam("max_depth") int depth,
@QueryParam("max_degree") @DefaultValue("-1") long degree,
@QueryParam("capacity")
@DefaultValue("-1") long capacity) {
LOG.debug("Graph [{}] get shortest path from '{}', to '{}' with " +
"direction {}, edge label {}, max depth '{}', " +
"degree '{}' and capacity '{}'",
graph, source, target, direction, edgeLabel, maxDepth,
"max degree '{}' and capacity '{}'",
graph, source, target, direction, edgeLabel, depth,
degree, capacity);

Id sourceId = VertexAPI.checkAndParseVertexId(source);
Expand All @@ -77,8 +77,8 @@ public String get(@Context GraphManager manager,

HugeTraverser traverser = new HugeTraverser(g);
List<Id> path = traverser.shortestPath(sourceId, targetId, dir,
edgeLabel, maxDepth,
degree, capacity);
edgeLabel, depth, degree,
capacity);
return manager.serializer(g).writeIds("path", path);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,11 @@ public final class ApiVersion {
* [0.29] Issue-39: Add rays and rings RESTful API
* [0.30] Issue-32: Change index create API to return indexLabel and task id
* [0.31] Issue-182: Support restore graph in restoring and merging mode
* [0.32] Issue-250: Keep depth and degree consistent for traverser api
*/

// The second parameter of Version.of() is for IDE running without JAR
public static final Version VERSION = Version.of(ApiVersion.class, "0.31");
public static final Version VERSION = Version.of(ApiVersion.class, "0.32");

public static final void check() {
// Check version of hugegraph-core. Firstly do check from version 0.3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,7 @@ public boolean indexValueChanged(Vertex oldV, HugeVertex newV) {
return false;
}

@SuppressWarnings("unused")
private void deleteIndex(HugeVertex vertex) {
// Delete the old record if exist
Iterator<Vertex> old = this.queryVertices(vertex.id());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ public HugeTraverser(HugeGraph graph) {
}

public List<Id> shortestPath(Id sourceV, Id targetV, Directions dir,
String label, int maxDepth,
long degree, long capacity) {
String label, int depth, long degree,
long capacity) {
E.checkNotNull(sourceV, "source vertex id");
E.checkNotNull(targetV, "target vertex id");
E.checkNotNull(dir, "direction");
checkPositive(maxDepth, "Shortest path max depth");
checkPositive(depth, "max depth");
checkDegree(degree);
checkCapacity(capacity);

Expand All @@ -81,12 +81,12 @@ public List<Id> shortestPath(Id sourceV, Id targetV, Directions dir,
while (true) {
// Found, reach max depth or reach capacity, stop searching
if ((path = traverser.forward()) != PATH_NONE ||
--maxDepth <= 0 || traverser.reachCapacity()) {
--depth <= 0 || traverser.reachCapacity()) {
break;
}

if ((path = traverser.backward()) != PATH_NONE ||
--maxDepth <= 0 || traverser.reachCapacity()) {
--depth <= 0 || traverser.reachCapacity()) {
Collections.reverse(path);
break;
}
Expand All @@ -95,9 +95,8 @@ public List<Id> shortestPath(Id sourceV, Id targetV, Directions dir,
}

public Set<Path> paths(Id sourceV, Directions sourceDir,
Id targetV, Directions targetDir,
String label, int maxDepth,
long degree, long capacity, long limit) {
Id targetV, Directions targetDir, String label,
int depth, long degree, long capacity, long limit) {
E.checkNotNull(sourceV, "source vertex id");
E.checkNotNull(targetV, "target vertex id");
E.checkNotNull(sourceDir, "source direction");
Expand All @@ -106,7 +105,7 @@ public Set<Path> paths(Id sourceV, Directions sourceDir,
sourceDir == targetDir.opposite(),
"Source direction must equal to target direction," +
"or opposite to target direction");
checkPositive(maxDepth, "Paths max depth");
checkPositive(depth, "max depth");
checkDegree(degree);
checkCapacity(capacity);
checkLimit(limit);
Expand All @@ -120,13 +119,13 @@ public Set<Path> paths(Id sourceV, Directions sourceDir,
PathsTraverser traverser = new PathsTraverser(sourceV, targetV, labelId,
degree, capacity, limit);
while (true) {
if (--maxDepth < 0 || traverser.reachLimit()) {
if (--depth < 0 || traverser.reachLimit()) {
break;
}
List<Path> foundPaths = traverser.forward(sourceDir);
paths.addAll(foundPaths);

if (--maxDepth < 0 || traverser.reachLimit()) {
if (--depth < 0 || traverser.reachLimit()) {
break;
}
foundPaths = traverser.backward(targetDir);
Expand All @@ -139,25 +138,23 @@ public Set<Path> paths(Id sourceV, Directions sourceDir,
}

public List<Path> rays(Id sourceV, Directions dir, String label,
int maxDepth, long degree, long capacity,
long limit) {
return this.subGraphPaths(sourceV, dir, label, maxDepth, degree,
int depth, long degree, long capacity, long limit) {
return this.subGraphPaths(sourceV, dir, label, depth, degree,
capacity, limit, false);
}

public List<Path> rings(Id sourceV, Directions dir, String label,
int maxDepth, long degree, long capacity,
long limit) {
return this.subGraphPaths(sourceV, dir, label, maxDepth, degree,
int depth, long degree, long capacity, long limit) {
return this.subGraphPaths(sourceV, dir, label, depth, degree,
capacity, limit, true);
}

private List<Path> subGraphPaths(Id sourceV, Directions dir, String label,
int maxDepth, long degree, long capacity,
int depth, long degree, long capacity,
long limit, boolean rings) {
E.checkNotNull(sourceV, "source vertex id");
E.checkNotNull(dir, "direction");
checkPositive(maxDepth, "Paths max depth");
checkPositive(depth, "max depth");
checkDegree(degree);
checkCapacity(capacity);
checkLimit(limit);
Expand All @@ -169,7 +166,7 @@ private List<Path> subGraphPaths(Id sourceV, Directions dir, String label,
List<Path> paths = new ArrayList<>();
while (true) {
paths.addAll(traverser.forward(dir));
if (--maxDepth < 0 || traverser.reachLimit() ||
if (--depth < 0 || traverser.reachLimit() ||
traverser.finished()) {
break;
}
Expand All @@ -182,7 +179,7 @@ public Set<Id> kout(Id sourceV, Directions dir, String label,
long degree, long capacity, long limit) {
E.checkNotNull(sourceV, "source vertex id");
E.checkNotNull(dir, "direction");
checkPositive(depth, "K-out depth");
checkPositive(depth, "k-out depth");
checkDegree(degree);
checkCapacity(capacity);
checkLimit(limit);
Expand Down Expand Up @@ -238,7 +235,7 @@ public Set<Id> kneighbor(Id sourceV, Directions dir,
long degree, long limit) {
E.checkNotNull(sourceV, "source vertex id");
E.checkNotNull(dir, "direction");
checkPositive(depth, "K-neighbor depth");
checkPositive(depth, "k-neighbor depth");
checkDegree(degree);
checkLimit(limit);

Expand Down Expand Up @@ -312,24 +309,25 @@ private Id getEdgeLabelId(Object label) {

private static void checkPositive(int value, String name) {
E.checkArgument(value > 0,
"%s must be > 0, but got '%s'", name, value);
"The %s parameter must be > 0, but got '%s'",
name, value);
}

private static void checkDegree(long degree) {
checkLimit(degree, "Degree");
checkPositiveOrNoLimit(degree, "max degree");
}

private static void checkCapacity(long capacity) {
checkLimit(capacity, "Capacity");
checkPositiveOrNoLimit(capacity, "capacity");
}

private static void checkLimit(long limit) {
checkLimit(limit, "Limit");
checkPositiveOrNoLimit(limit, "limit");
}

private static void checkLimit(long value, String name) {
private static void checkPositiveOrNoLimit(long value, String name) {
E.checkArgument(value > 0 || value == NO_LIMIT,
"%s must be > 0 or == %s, but got: %s",
"The %s parameter must be > 0 or == %s, but got: %s",
name, NO_LIMIT, value);
}

Expand Down

0 comments on commit 2480347

Please sign in to comment.