Differential D4028 Diff 14692 java/src/main/java/org/softwareheritage/graph/experiments/forks/ListEmptyOrigins.java
Changeset View
Changeset View
Standalone View
Standalone View
java/src/main/java/org/softwareheritage/graph/experiments/forks/ListEmptyOrigins.java
Show All 10 Lines | |||||
public class ListEmptyOrigins { | public class ListEmptyOrigins { | ||||
private Graph graph; | private Graph graph; | ||||
private Long emptySnapshot; | private Long emptySnapshot; | ||||
private static JSAPResult parse_args(String[] args) { | private static JSAPResult parse_args(String[] args) { | ||||
JSAPResult config = null; | JSAPResult config = null; | ||||
try { | try { | ||||
SimpleJSAP jsap = new SimpleJSAP( | SimpleJSAP jsap = new SimpleJSAP(ListEmptyOrigins.class.getName(), "", | ||||
ListEmptyOrigins.class.getName(), | new Parameter[]{new FlaggedOption("graphPath", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.REQUIRED, | ||||
"", | 'g', "graph", "Basename of the compressed graph"),}); | ||||
new Parameter[]{ | |||||
new FlaggedOption("graphPath", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.REQUIRED, | |||||
'g', "graph", "Basename of the compressed graph"), | |||||
} | |||||
); | |||||
config = jsap.parse(args); | config = jsap.parse(args); | ||||
if (jsap.messagePrinted()) { | if (jsap.messagePrinted()) { | ||||
System.exit(1); | System.exit(1); | ||||
} | } | ||||
} catch (JSAPException e) { | } catch (JSAPException e) { | ||||
e.printStackTrace(); | e.printStackTrace(); | ||||
} | } | ||||
Show All 21 Lines | private void load_graph(String graphBasename) throws IOException { | ||||
System.err.println("Loading graph " + graphBasename + " ..."); | System.err.println("Loading graph " + graphBasename + " ..."); | ||||
this.graph = new Graph(graphBasename); | this.graph = new Graph(graphBasename); | ||||
System.err.println("Graph loaded."); | System.err.println("Graph loaded."); | ||||
this.emptySnapshot = null; | this.emptySnapshot = null; | ||||
} | } | ||||
private boolean nodeIsEmptySnapshot(Long node) { | private boolean nodeIsEmptySnapshot(Long node) { | ||||
System.err.println(this.graph.getNodeType(node) + " " + this.graph.outdegree(node) + " " + node); | System.err.println(this.graph.getNodeType(node) + " " + this.graph.outdegree(node) + " " + node); | ||||
if (this.emptySnapshot == null | if (this.emptySnapshot == null && this.graph.getNodeType(node) == Node.Type.SNP | ||||
&& this.graph.getNodeType(node) == Node.Type.SNP | |||||
&& this.graph.outdegree(node) == 0) { | && this.graph.outdegree(node) == 0) { | ||||
System.err.println("Found empty snapshot: " + node); | System.err.println("Found empty snapshot: " + node); | ||||
this.emptySnapshot = node; | this.emptySnapshot = node; | ||||
} | } | ||||
return node.equals(this.emptySnapshot); | return node.equals(this.emptySnapshot); | ||||
} | } | ||||
private ArrayList<Long> compute(ImmutableGraph graph) { | private ArrayList<Long> compute(ImmutableGraph graph) { | ||||
final long n = graph.numNodes(); | final long n = graph.numNodes(); | ||||
ArrayList<Long> bad = new ArrayList<>(); | ArrayList<Long> bad = new ArrayList<>(); | ||||
for (long i = 0; i < n; i++) { | for (long i = 0; i < n; i++) { | ||||
Node.Type nt = this.graph.getNodeType(i); | Node.Type nt = this.graph.getNodeType(i); | ||||
if (nt != Node.Type.ORI) continue; | if (nt != Node.Type.ORI) | ||||
continue; | |||||
final LazyLongIterator iterator = graph.successors(i); | final LazyLongIterator iterator = graph.successors(i); | ||||
long succ; | long succ; | ||||
boolean found = false; | boolean found = false; | ||||
while ((succ = iterator.nextLong()) != -1) { | while ((succ = iterator.nextLong()) != -1) { | ||||
if (this.graph.outdegree(succ) > 0) { | if (this.graph.outdegree(succ) > 0) { | ||||
found = true; | found = true; | ||||
} | } | ||||
} | } | ||||
if (!found) | if (!found) | ||||
bad.add(i); | bad.add(i); | ||||
} | } | ||||
return bad; | return bad; | ||||
} | } | ||||
} | } |