use of com.baidu.hugegraph.traversal.algorithm.HugeTraverser.Path 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.Path in project incubator-hugegraph by apache.
the class ShortestPathRecords method linkPath.
private Path linkPath(int source, int target) {
Path sourcePath = this.linkSourcePath(source);
Path targetPath = this.linkTargetPath(target);
sourcePath.reverse();
List<Id> ids = new ArrayList<>(sourcePath.vertices());
ids.addAll(targetPath.vertices());
return new Path(ids);
}
use of com.baidu.hugegraph.traversal.algorithm.HugeTraverser.Path in project incubator-hugegraph by apache.
the class SingleWayMultiPathsRecords method linkPath.
protected final Path linkPath(int layerIndex, int target) {
List<Id> ids = CollectionFactory.newList(CollectionType.EC);
IntMap layer = this.layer(layerIndex);
if (!layer.containsKey(target)) {
throw new HugeException("Failed to get path for %s", this.id(target));
}
// Collect self node
ids.add(this.id(target));
// Concat parents
for (int i = layerIndex; i > 0; i--) {
layer = this.layer(i);
// Uptrack parents
target = layer.get(target);
ids.add(this.id(target));
}
Collections.reverse(ids);
return new Path(ids);
}
use of com.baidu.hugegraph.traversal.algorithm.HugeTraverser.Path 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.Path in project incubator-hugegraph by apache.
the class ShortestPathRecords method linkPath.
private Path linkPath(Stack<Record> all, int node) {
int size = all.size();
List<Id> ids = new ArrayList<>(size);
ids.add(this.id(node));
int value = node;
for (int i = size - 1; i > 0; i--) {
IntMap layer = ((Int2IntRecord) all.elementAt(i)).layer();
value = layer.get(value);
ids.add(this.id(value));
}
return new Path(ids);
}
Aggregations