use of apoc.result.CCResult in project neo4j-apoc-procedures by neo4j-contrib.
the class WeaklyConnectedComponents method wcc.
@Deprecated
@Procedure("apoc.algo.wcc")
@Description("CALL apoc.algo.wcc() YIELD number of weakly connected components")
public Stream<CCResult> wcc() {
List<List<CCVar>> results = new LinkedList<List<CCVar>>();
ResourceIterator<Node> nodes = db.getAllNodes().iterator();
PrimitiveLongSet allNodes = Primitive.longSet(0);
while (nodes.hasNext()) {
Node node = nodes.next();
if (node.getDegree() == 0) {
List<CCVar> result = new LinkedList<CCVar>();
result.add(new CCVar(node.getId() + "", node.getLabels().iterator().next().name()));
results.add(result);
} else {
allNodes.add(node.getId());
}
}
nodes.close();
PrimitiveLongIterator it = allNodes.iterator();
while (it.hasNext()) {
try {
long n = it.next();
List<CCVar> result = new LinkedList<CCVar>();
PrimitiveLongIterator reachableIDs = go(db.getNodeById(n), Direction.BOTH, result).iterator();
while (reachableIDs.hasNext()) {
long id = (long) reachableIDs.next();
allNodes.remove(id);
}
results.add(result);
} catch (NoSuchElementException e) {
break;
}
it = allNodes.iterator();
}
allNodes.close();
return results.stream().map((x) -> new CCResult(x.stream().map((z) -> new Long(z.getId())).collect(Collectors.toList()), x.stream().collect(Collectors.groupingBy(CCVar::getType)).entrySet().stream().collect(Collectors.toMap(e -> e.getKey(), e -> e.getValue().size()))));
}
Aggregations