Changeset View
Changeset View
Standalone View
Standalone View
java/src/main/java/org/softwareheritage/graph/utils/ReadGraph.java
package org.softwareheritage.graph.utils; | package org.softwareheritage.graph.utils; | ||||
import it.unimi.dsi.big.webgraph.ImmutableGraph; | import it.unimi.dsi.big.webgraph.ImmutableGraph; | ||||
import it.unimi.dsi.big.webgraph.NodeIterator; | import it.unimi.dsi.big.webgraph.NodeIterator; | ||||
import org.softwareheritage.graph.maps.NodeIdMap; | import org.softwareheritage.graph.maps.NodeIdMap; | ||||
import java.io.IOException; | import java.io.IOException; | ||||
public class ReadGraph { | public class ReadGraph { | ||||
public static void main(String[] args) throws IOException { | public static void main(String[] args) throws IOException { | ||||
String graphPath = args[0]; | String graphPath = args[0]; | ||||
ImmutableGraph graph = ImmutableGraph.load(graphPath); | ImmutableGraph graph = ImmutableGraph.load(graphPath); | ||||
NodeIdMap nodeMap = new NodeIdMap(graphPath, graph.numNodes()); | NodeIdMap nodeMap = new NodeIdMap(graphPath); | ||||
NodeIterator it = graph.nodeIterator(); | NodeIterator it = graph.nodeIterator(); | ||||
while (it.hasNext()) { | while (it.hasNext()) { | ||||
long srcNode = it.nextLong(); | long srcNode = it.nextLong(); | ||||
var s = it.successors(); | var s = it.successors(); | ||||
long dstNode; | long dstNode; | ||||
while ((dstNode = s.nextLong()) >= 0) { | while ((dstNode = s.nextLong()) >= 0) { | ||||
System.out.format("%s %s\n", nodeMap.getSWHID(srcNode), nodeMap.getSWHID(dstNode)); | System.out.format("%s %s\n", nodeMap.getSWHID(srcNode), nodeMap.getSWHID(dstNode)); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
} | } |