Search in sources :

Example 1 with ObjectOpenHashSet

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;
}
Also used : ObjectOpenHashSet(it.unimi.dsi.fastutil.objects.ObjectOpenHashSet) HashSet(java.util.HashSet) Set(java.util.Set) ObjectOpenHashSet(it.unimi.dsi.fastutil.objects.ObjectOpenHashSet) Object2ObjectOpenHashMap(it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap) NodeIterable(org.gephi.graph.api.NodeIterable) EdgeIterable(org.gephi.graph.api.EdgeIterable) Node(org.gephi.graph.api.Node) Edge(org.gephi.graph.api.Edge)

Aggregations

Object2ObjectOpenHashMap (it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap)1 ObjectOpenHashSet (it.unimi.dsi.fastutil.objects.ObjectOpenHashSet)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 Edge (org.gephi.graph.api.Edge)1 EdgeIterable (org.gephi.graph.api.EdgeIterable)1 Node (org.gephi.graph.api.Node)1 NodeIterable (org.gephi.graph.api.NodeIterable)1