use of com.baidu.hugegraph.traversal.algorithm.HugeTraverser.PathSet in project incubator-hugegraph by apache.
the class DoubleWayMultiPathsRecords method linkPath.
@Watched
protected final PathSet linkPath(int source, int target, boolean ring) {
PathSet paths = new PathSet();
PathSet sources = this.linkSourcePath(source);
PathSet targets = this.linkTargetPath(target);
for (Path tpath : targets) {
tpath.reverse();
for (Path spath : sources) {
if (!ring) {
// Avoid loop in path
if (CollectionUtils.containsAny(spath.vertices(), tpath.vertices())) {
continue;
}
}
List<Id> ids = new ArrayList<>(spath.vertices());
ids.addAll(tpath.vertices());
Id crosspoint = this.id(this.movingForward ? target : source);
paths.add(new Path(crosspoint, ids));
}
}
return paths;
}
use of com.baidu.hugegraph.traversal.algorithm.HugeTraverser.PathSet in project incubator-hugegraph by apache.
the class KoutRecords method paths.
@Override
public PathSet paths(long limit) {
PathSet paths = new PathSet();
Stack<Record> records = this.records();
IntIterator iterator = records.peek().keys();
while ((limit == NO_LIMIT || limit-- > 0L) && iterator.hasNext()) {
paths.add(this.linkPath(records.size() - 1, iterator.next()));
}
return paths;
}
use of com.baidu.hugegraph.traversal.algorithm.HugeTraverser.PathSet in project incubator-hugegraph by apache.
the class ShortestPathRecords method findPath.
@Override
public PathSet findPath(Id target, Function<Id, Boolean> filter, boolean all, boolean ring) {
assert !ring;
PathSet paths = new PathSet();
int targetCode = this.code(target);
int parentCode = this.current();
// If cross point exists, shortest path found, concat them
if (this.movingForward() && this.targetContains(targetCode) || !this.movingForward() && this.sourceContains(targetCode)) {
if (!filter.apply(target)) {
return paths;
}
paths.add(this.movingForward() ? this.linkPath(parentCode, targetCode) : this.linkPath(targetCode, parentCode));
this.pathFound = true;
if (!all) {
return paths;
}
}
/*
* Not found shortest path yet, node is added to current layer if:
* 1. not in sources and newVertices yet
* 2. path of node doesn't have loop
*/
if (!this.pathFound && this.isNew(targetCode)) {
this.addPath(targetCode, parentCode);
}
return paths;
}
use of com.baidu.hugegraph.traversal.algorithm.HugeTraverser.PathSet in project incubator-hugegraph by apache.
the class DoubleWayMultiPathsRecords method linkPathLayer.
private PathSet linkPathLayer(Stack<Record> all, int id, int layerIndex) {
PathSet results = new PathSet();
if (layerIndex == 0) {
Id sid = this.id(id);
results.add(new Path(Lists.newArrayList(sid)));
return results;
}
Id current = this.id(id);
Record layer = all.elementAt(layerIndex);
IntIterator iterator = layer.get(id);
while (iterator.hasNext()) {
int parent = iterator.next();
PathSet paths = this.linkPathLayer(all, parent, layerIndex - 1);
paths.append(current);
results.addAll(paths);
}
return results;
}
use of com.baidu.hugegraph.traversal.algorithm.HugeTraverser.PathSet in project incubator-hugegraph by apache.
the class KneighborRecords method paths.
@Override
public PathSet paths(long limit) {
PathSet paths = new PathSet();
Stack<Record> records = this.records();
for (int i = 1; i < records.size(); i++) {
IntIterator iterator = records.get(i).keys();
while ((limit == NO_LIMIT || limit > 0L) && iterator.hasNext()) {
paths.add(this.linkPath(i, iterator.next()));
limit--;
}
}
return paths;
}
Aggregations