use of it.unimi.dsi.fastutil.objects.ObjectOpenHashSet in project gephi by gephi.
the class PageRank method calculateInNeighborsPerNode.
private Map<Node, Set<Node>> calculateInNeighborsPerNode(Graph graph, boolean directed) {
Map<Node, Set<Node>> inNeighborsPerNode = new Object2ObjectOpenHashMap<>();
NodeIterable nodesIterable = graph.getNodes();
for (Node node : nodesIterable) {
Set<Node> nodeInNeighbors = new ObjectOpenHashSet<>();
EdgeIterable edgesIterable;
if (directed) {
edgesIterable = ((DirectedGraph) graph).getInEdges(node);
} else {
edgesIterable = graph.getEdges(node);
}
for (Edge edge : edgesIterable) {
if (!edge.isSelfLoop()) {
Node neighbor = graph.getOpposite(node, edge);
nodeInNeighbors.add(neighbor);
}
if (isCanceled) {
edgesIterable.doBreak();
break;
}
}
inNeighborsPerNode.put(node, nodeInNeighbors);
if (isCanceled) {
nodesIterable.doBreak();
break;
}
}
return inNeighborsPerNode;
}
Aggregations