diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -37,6 +37,15 @@ hooks: - id: black +- repo: local + hooks: + - id: java-coding-style + name: java style + entry: mvn + args: ["-f", "java/pom.xml", "spotless:apply"] + pass_filenames: false + language: system + # unfortunately, we are far from being able to enable this... # - repo: https://github.com/PyCQA/pydocstyle.git # rev: 4.0.0 diff --git a/java/.clang-format b/java/.clang-format deleted file mode 100644 --- a/java/.clang-format +++ /dev/null @@ -1,4 +0,0 @@ ---- -BasedOnStyle: Google ---- -Language: Java diff --git a/java/.coding-style.xml b/java/.coding-style.xml new file mode 100644 --- /dev/null +++ b/java/.coding-style.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + diff --git a/java/pom.xml b/java/pom.xml --- a/java/pom.xml +++ b/java/pom.xml @@ -186,7 +186,36 @@ - + + + + com.diffplug.spotless + spotless-maven-plugin + 2.4.1 + + + + + *.md + .gitignore + + + + + true + 4 + + + + + + + 4.16.0 + .coding-style.xml + + + + diff --git a/java/src/main/java/org/softwareheritage/graph/AllowedEdges.java b/java/src/main/java/org/softwareheritage/graph/AllowedEdges.java --- a/java/src/main/java/org/softwareheritage/graph/AllowedEdges.java +++ b/java/src/main/java/org/softwareheritage/graph/AllowedEdges.java @@ -7,8 +7,8 @@ *

* Software Heritage * graph contains multiple node types (contents, directories, revisions, ...) and restricting - * the traversal to specific node types is necessary for many querying operations: use cases. + * the traversal to specific node types is necessary for many querying operations: + * use cases. * * @author The Software Heritage developers */ @@ -16,16 +16,17 @@ public class AllowedEdges { /** * 2D boolean matrix storing access rights for all combination of src/dst node types (first - * dimension is source, second dimension is destination), when edge restriction is not enforced - * this array is set to null for early bypass. + * dimension is source, second dimension is destination), when edge restriction is not enforced this + * array is set to null for early bypass. */ public boolean[][] restrictedTo; /** * Constructor. * - * @param edgesFmt a formatted string describing allowed edges + * @param edgesFmt a formatted string describing allowed + * edges */ public AllowedEdges(String edgesFmt) { int nbNodeTypes = Node.Type.values().length; diff --git a/java/src/main/java/org/softwareheritage/graph/Entry.java b/java/src/main/java/org/softwareheritage/graph/Entry.java --- a/java/src/main/java/org/softwareheritage/graph/Entry.java +++ b/java/src/main/java/org/softwareheritage/graph/Entry.java @@ -140,16 +140,14 @@ close(); } - public void visit_paths(String direction, String edgesFmt, - long srcNodeId) { + public void visit_paths(String direction, String edgesFmt, long srcNodeId) { open(); Traversal t = new Traversal(this.graph, direction, edgesFmt); t.visitPathsVisitor(srcNodeId, this::writePath); close(); } - public void walk(String direction, String edgesFmt, String algorithm, - long srcNodeId, long dstNodeId) { + public void walk(String direction, String edgesFmt, String algorithm, long srcNodeId, long dstNodeId) { open(); Traversal t = new Traversal(this.graph, direction, edgesFmt); for (Long nodeId : t.walk(srcNodeId, dstNodeId, algorithm)) { @@ -158,8 +156,7 @@ close(); } - public void walk_type(String direction, String edgesFmt, String algorithm, - long srcNodeId, String dst) { + public void walk_type(String direction, String edgesFmt, String algorithm, long srcNodeId, String dst) { open(); Node.Type dstType = Node.Type.fromStr(dst); Traversal t = new Traversal(this.graph, direction, edgesFmt); @@ -169,8 +166,7 @@ close(); } - public void random_walk(String direction, String edgesFmt, int retries, - long srcNodeId, long dstNodeId) { + public void random_walk(String direction, String edgesFmt, int retries, long srcNodeId, long dstNodeId) { open(); Traversal t = new Traversal(this.graph, direction, edgesFmt); for (Long nodeId : t.randomWalk(srcNodeId, dstNodeId, retries)) { @@ -179,8 +175,7 @@ close(); } - public void random_walk_type(String direction, String edgesFmt, int retries, - long srcNodeId, String dst) { + public void random_walk_type(String direction, String edgesFmt, int retries, long srcNodeId, String dst) { open(); Node.Type dstType = Node.Type.fromStr(dst); Traversal t = new Traversal(this.graph, direction, edgesFmt); diff --git a/java/src/main/java/org/softwareheritage/graph/Graph.java b/java/src/main/java/org/softwareheritage/graph/Graph.java --- a/java/src/main/java/org/softwareheritage/graph/Graph.java +++ b/java/src/main/java/org/softwareheritage/graph/Graph.java @@ -12,13 +12,13 @@ * Main class storing the compressed graph and node id mappings. *

* The compressed graph is stored using the WebGraph - * ecosystem. Additional mappings are necessary because Software Heritage uses string based persistent - * identifiers (SWHID) while WebGraph uses integers internally. These two mappings (long id ↔ - * SWHID) are used for the input (users refer to the graph using SWHID) and the output (convert back to - * SWHID for users results). However, since graph traversal can be restricted depending on the node - * type (see {@link AllowedEdges}), a long id → node type map is stored as well to avoid a full - * SWHID lookup. + * ecosystem. Additional mappings are necessary because Software Heritage uses string based persistent + * identifiers (SWHID) while WebGraph uses integers internally. These two mappings (long id + * ↔ SWHID) are used for the input (users refer to the graph using SWHID) and the output + * (convert back to SWHID for users results). However, since graph traversal can be restricted + * depending on the node type (see {@link AllowedEdges}), a long id → node type map is stored + * as well to avoid a full SWHID lookup. * * @author The Software Heritage developers * @see org.softwareheritage.graph.AllowedEdges @@ -58,8 +58,8 @@ this.nodeIdMap = new NodeIdMap(path, numNodes()); } - protected Graph(ImmutableGraph graph, ImmutableGraph graphTransposed, - String path, NodeIdMap nodeIdMap, NodeTypesMap nodeTypesMap) { + protected Graph(ImmutableGraph graph, ImmutableGraph graphTransposed, String path, NodeIdMap nodeIdMap, + NodeTypesMap nodeTypesMap) { this.graph = graph; this.graphTransposed = graphTransposed; this.path = path; @@ -126,8 +126,8 @@ * Returns lazy iterator of successors of a node. * * @param nodeId node specified as a long id - * @return lazy iterator of successors of the node, specified as a WebGraph LazyLongIterator + * @return lazy iterator of successors of the node, specified as a + * WebGraph LazyLongIterator */ @Override public LazyLongIterator successors(long nodeId) { @@ -139,8 +139,8 @@ * * @param nodeId node specified as a long id * @param allowedEdges the specification of which edges can be traversed - * @return lazy iterator of successors of the node, specified as a WebGraph LazyLongIterator + * @return lazy iterator of successors of the node, specified as a + * WebGraph LazyLongIterator */ public LazyLongIterator successors(long nodeId, AllowedEdges allowedEdges) { if (allowedEdges.restrictedTo == null) { @@ -164,7 +164,8 @@ @Override public long skip(final long n) { long i; - for (i = 0; i < n && nextLong() != -1; i++) ; + for (i = 0; i < n && nextLong() != -1; i++) + ; return i; } }; @@ -186,8 +187,8 @@ * Returns lazy iterator of predecessors of a node. * * @param nodeId node specified as a long id - * @return lazy iterator of predecessors of the node, specified as a WebGraph LazyLongIterator + * @return lazy iterator of predecessors of the node, specified as a + * WebGraph LazyLongIterator */ public LazyLongIterator predecessors(long nodeId) { return this.transpose().successors(nodeId); diff --git a/java/src/main/java/org/softwareheritage/graph/Node.java b/java/src/main/java/org/softwareheritage/graph/Node.java --- a/java/src/main/java/org/softwareheritage/graph/Node.java +++ b/java/src/main/java/org/softwareheritage/graph/Node.java @@ -93,9 +93,8 @@ } /** - * Parses SWH node type possible values from formatted string (see the API - * syntax). + * Parses SWH node type possible values from formatted string (see the + * API syntax). * * @param strFmtType node types represented as a formatted string * @return a list containing the {@link Node.Type} values diff --git a/java/src/main/java/org/softwareheritage/graph/SWHID.java b/java/src/main/java/org/softwareheritage/graph/SWHID.java --- a/java/src/main/java/org/softwareheritage/graph/SWHID.java +++ b/java/src/main/java/org/softwareheritage/graph/SWHID.java @@ -5,8 +5,8 @@ import org.apache.commons.codec.binary.Hex; /** - * A Software Heritage persistent identifier (SWHID), see persistent + * A Software Heritage persistent identifier (SWHID), see persistent * identifier documentation. * * @author The Software Heritage developers @@ -43,19 +43,14 @@ /** * Creates a SWHID from a compact binary representation. *

- * The binary format is specified in the Python module - * swh.graph.swhid:str_to_bytes . + * The binary format is specified in the Python module swh.graph.swhid:str_to_bytes . */ public static SWHID fromBytes(byte[] input) { byte[] digest = new byte[20]; System.arraycopy(input, 2, digest, 0, digest.length); - String swhidStr = String.format( - "swh:%d:%s:%s", - input[0], - Node.Type.fromInt(input[1]).toString().toLowerCase(), - Hex.encodeHexString(digest) - ); + String swhidStr = String.format("swh:%d:%s:%s", input[0], Node.Type.fromInt(input[1]).toString().toLowerCase(), + Hex.encodeHexString(digest)); return new SWHID(swhidStr); } @@ -83,17 +78,16 @@ /** * Converts SWHID to a compact binary representation. *

- * The binary format is specified in the Python module - * swh.graph.swhid:str_to_bytes . + * The binary format is specified in the Python module swh.graph.swhid:str_to_bytes . */ public byte[] toBytes() { byte[] bytes = new byte[22]; byte[] digest; - bytes[0] = (byte) 1; // namespace version - bytes[1] = (byte) Node.Type.toInt(this.type); // SWHID type + bytes[0] = (byte) 1; // namespace version + bytes[1] = (byte) Node.Type.toInt(this.type); // SWHID type try { - digest = Hex.decodeHex(this.swhid.substring(10)); // SHA1 hash + digest = Hex.decodeHex(this.swhid.substring(10)); // SHA1 hash System.arraycopy(digest, 0, bytes, 2, digest.length); } catch (DecoderException e) { throw new IllegalArgumentException("invalid hex sequence in SWHID: " + this.swhid); diff --git a/java/src/main/java/org/softwareheritage/graph/Stats.java b/java/src/main/java/org/softwareheritage/graph/Stats.java --- a/java/src/main/java/org/softwareheritage/graph/Stats.java +++ b/java/src/main/java/org/softwareheritage/graph/Stats.java @@ -7,8 +7,8 @@ /** * Statistics on the compressed graph. *

- * These statistics are not computed but directly read from WebGraph generated .stats and .properties files. + * These statistics are not computed but directly read from + * WebGraph generated .stats and .properties files. * * @author The Software Heritage developers */ diff --git a/java/src/main/java/org/softwareheritage/graph/Traversal.java b/java/src/main/java/org/softwareheritage/graph/Traversal.java --- a/java/src/main/java/org/softwareheritage/graph/Traversal.java +++ b/java/src/main/java/org/softwareheritage/graph/Traversal.java @@ -38,8 +38,9 @@ * * @param graph graph used in the traversal * @param direction a string (either "forward" or "backward") specifying edge orientation - * @param edgesFmt a formatted string describing allowed edges + * @param edgesFmt a formatted string describing allowed + * edges */ public Traversal(Graph graph, String direction, String edgesFmt) { if (!direction.matches("forward|backward")) { @@ -93,7 +94,7 @@ long neighborsCnt = 0; nbEdgesAccessed += graph.outdegree(currentNodeId); LazyLongIterator it = graph.successors(currentNodeId, edges); - for (long neighborNodeId; (neighborNodeId = it.nextLong()) != -1; ) { + for (long neighborNodeId; (neighborNodeId = it.nextLong()) != -1;) { neighborsCnt++; if (!visited.contains(neighborNodeId)) { stack.push(neighborNodeId); @@ -120,13 +121,12 @@ } /** - * Push version of {@link #neighbors}: will fire passed callback on each - * neighbor. + * Push version of {@link #neighbors}: will fire passed callback on each neighbor. */ public void neighborsVisitor(long srcNodeId, NodeIdConsumer cb) { this.nbEdgesAccessed = graph.outdegree(srcNodeId); LazyLongIterator it = graph.successors(srcNodeId, edges); - for (long neighborNodeId; (neighborNodeId = it.nextLong()) != -1; ) { + for (long neighborNodeId; (neighborNodeId = it.nextLong()) != -1;) { cb.accept(neighborNodeId); } } @@ -144,8 +144,7 @@ } /** - * Push version of {@link #visitNodes}: will fire passed callback on each - * visited node. + * Push version of {@link #visitNodes}: will fire passed callback on each visited node. */ public void visitNodesVisitor(long srcNodeId, NodeIdConsumer nodeCb, EdgeIdConsumer edgeCb) { Stack stack = new Stack<>(); @@ -162,7 +161,7 @@ nbEdgesAccessed += graph.outdegree(currentNodeId); LazyLongIterator it = graph.successors(currentNodeId, edges); - for (long neighborNodeId; (neighborNodeId = it.nextLong()) != -1; ) { + for (long neighborNodeId; (neighborNodeId = it.nextLong()) != -1;) { if (edgeCb != null) { edgeCb.accept(currentNodeId, neighborNodeId); } @@ -192,8 +191,8 @@ } /** - * Push version of {@link #visitPaths}: will fire passed callback on each - * discovered (complete) path. + * Push version of {@link #visitPaths}: will fire passed callback on each discovered (complete) + * path. */ public void visitPathsVisitor(long srcNodeId, PathConsumer cb) { Stack currentPath = new Stack<>(); @@ -213,15 +212,13 @@ return paths; } - private void visitPathsInternalVisitor(long currentNodeId, - Stack currentPath, - PathConsumer cb) { + private void visitPathsInternalVisitor(long currentNodeId, Stack currentPath, PathConsumer cb) { currentPath.push(currentNodeId); long visitedNeighbors = 0; nbEdgesAccessed += graph.outdegree(currentNodeId); LazyLongIterator it = graph.successors(currentNodeId, edges); - for (long neighborNodeId; (neighborNodeId = it.nextLong()) != -1; ) { + for (long neighborNodeId; (neighborNodeId = it.nextLong()) != -1;) { visitPathsInternalVisitor(neighborNodeId, currentPath, cb); visitedNeighbors++; } @@ -235,8 +232,8 @@ } /** - * Performs a graph traversal with backtracking, and returns the first - * found path from source to destination. + * Performs a graph traversal with backtracking, and returns the first found path from source to + * destination. * * @param srcNodeId source node * @param dst destination (either a node or a node type) @@ -260,29 +257,27 @@ } /** - * Performs a random walk (picking a random successor at each step) from - * source to destination. + * Performs a random walk (picking a random successor at each step) from source to destination. * * @param srcNodeId source node * @param dst destination (either a node or a node type) - * @return found path as a list of node ids or an empty path to indicate - * that no suitable path have been found + * @return found path as a list of node ids or an empty path to indicate that no suitable path have + * been found */ public ArrayList randomWalk(long srcNodeId, T dst) { return randomWalk(srcNodeId, dst, 0); } /** - * Performs a stubborn random walk (picking a random successor at each - * step) from source to destination. The walk is "stubborn" in the sense - * that it will not give up the first time if a satisfying target node is - * found, but it will retry up to a limited amount of times. + * Performs a stubborn random walk (picking a random successor at each step) from source to + * destination. The walk is "stubborn" in the sense that it will not give up the first time if a + * satisfying target node is found, but it will retry up to a limited amount of times. * * @param srcNodeId source node * @param dst destination (either a node or a node type) * @param retries number of times to retry; 0 means no retries (single walk) - * @return found path as a list of node ids or an empty path to indicate - * that no suitable path have been found + * @return found path as a list of node ids or an empty path to indicate that no suitable path have + * been found */ public ArrayList randomWalk(long srcNodeId, T dst, int retries) { long curNodeId = srcNodeId; @@ -311,17 +306,16 @@ if (found) { return path; - } else if (retries > 0) { // try again + } else if (retries > 0) { // try again return randomWalk(srcNodeId, dst, retries - 1); - } else { // not found and no retries left + } else { // not found and no retries left path.clear(); return path; } } /** - * Randomly choose an element from an iterator over Longs using reservoir - * sampling + * Randomly choose an element from an iterator over Longs using reservoir sampling * * @param elements iterator over selection domain * @return randomly chosen element or -1 if no suitable element was found @@ -330,7 +324,7 @@ long curPick = -1; long seenCandidates = 0; - for (long element; (element = elements.nextLong()) != -1; ) { + for (long element; (element = elements.nextLong()) != -1;) { seenCandidates++; if (Math.round(rng.nextFloat() * (seenCandidates - 1)) == 0) { curPick = element; @@ -362,7 +356,7 @@ nbEdgesAccessed += graph.outdegree(currentNodeId); LazyLongIterator it = graph.successors(currentNodeId, edges); - for (long neighborNodeId; (neighborNodeId = it.nextLong()) != -1; ) { + for (long neighborNodeId; (neighborNodeId = it.nextLong()) != -1;) { if (!visited.contains(neighborNodeId)) { stack.push(neighborNodeId); visited.add(neighborNodeId); @@ -396,7 +390,7 @@ nbEdgesAccessed += graph.outdegree(currentNodeId); LazyLongIterator it = graph.successors(currentNodeId, edges); - for (long neighborNodeId; (neighborNodeId = it.nextLong()) != -1; ) { + for (long neighborNodeId; (neighborNodeId = it.nextLong()) != -1;) { if (!visited.contains(neighborNodeId)) { queue.add(neighborNodeId); visited.add(neighborNodeId); @@ -471,7 +465,7 @@ curNode = lhsStack.poll(); nbEdgesAccessed += graph.outdegree(curNode); LazyLongIterator it = graph.successors(curNode, edges); - for (long neighborNodeId; (neighborNodeId = it.nextLong()) != -1; ) { + for (long neighborNodeId; (neighborNodeId = it.nextLong()) != -1;) { if (!lhsVisited.contains(neighborNodeId)) { if (rhsVisited.contains(neighborNodeId)) return neighborNodeId; @@ -485,7 +479,7 @@ curNode = rhsStack.poll(); nbEdgesAccessed += graph.outdegree(curNode); LazyLongIterator it = graph.successors(curNode, edges); - for (long neighborNodeId; (neighborNodeId = it.nextLong()) != -1; ) { + for (long neighborNodeId; (neighborNodeId = it.nextLong()) != -1;) { if (!rhsVisited.contains(neighborNodeId)) { if (lhsVisited.contains(neighborNodeId)) return neighborNodeId; @@ -501,24 +495,21 @@ public interface NodeIdConsumer extends LongConsumer { /** - * Callback for incrementally receiving node identifiers during a graph - * visit. + * Callback for incrementally receiving node identifiers during a graph visit. */ void accept(long nodeId); } public interface EdgeIdConsumer { /** - * Callback for incrementally receiving edge identifiers during a graph - * visit. + * Callback for incrementally receiving edge identifiers during a graph visit. */ void accept(long srcId, long dstId); } public interface PathConsumer extends Consumer> { /** - * Callback for incrementally receiving node paths (made of node - * identifiers) during a graph visit. + * Callback for incrementally receiving node paths (made of node identifiers) during a graph visit. */ void accept(ArrayList path); } diff --git a/java/src/main/java/org/softwareheritage/graph/benchmark/BFS.java b/java/src/main/java/org/softwareheritage/graph/benchmark/BFS.java --- a/java/src/main/java/org/softwareheritage/graph/benchmark/BFS.java +++ b/java/src/main/java/org/softwareheritage/graph/benchmark/BFS.java @@ -15,7 +15,6 @@ import java.io.File; import java.io.IOException; - public class BFS { private final static Logger LOGGER = LoggerFactory.getLogger(BFS.class); private final ImmutableGraph graph; @@ -27,17 +26,13 @@ private static JSAPResult parse_args(String[] args) { JSAPResult config = null; try { - SimpleJSAP jsap = new SimpleJSAP( - BFS.class.getName(), - "", + SimpleJSAP jsap = new SimpleJSAP(BFS.class.getName(), "", new Parameter[]{ - new FlaggedOption("graphPath", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.REQUIRED, - 'g', "graph", "Basename of the compressed graph"), + new FlaggedOption("graphPath", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.REQUIRED, 'g', + "graph", "Basename of the compressed graph"), - new FlaggedOption("useTransposed", JSAP.BOOLEAN_PARSER, "false", JSAP.NOT_REQUIRED, - 'T', "transposed", "Use transposed graph (default: false)"), - } - ); + new FlaggedOption("useTransposed", JSAP.BOOLEAN_PARSER, "false", JSAP.NOT_REQUIRED, 'T', + "transposed", "Use transposed graph (default: false)"),}); config = jsap.parse(args); if (jsap.messagePrinted()) { @@ -84,7 +79,8 @@ pl.start("Starting breadth-first visit..."); for (long i = 0; i < n; i++) { - if (visited.getBoolean(i)) continue; + if (visited.getBoolean(i)) + continue; queue.enqueue(Longs.toByteArray(i)); visited.set(i); diff --git a/java/src/main/java/org/softwareheritage/graph/benchmark/Benchmark.java b/java/src/main/java/org/softwareheritage/graph/benchmark/Benchmark.java --- a/java/src/main/java/org/softwareheritage/graph/benchmark/Benchmark.java +++ b/java/src/main/java/org/softwareheritage/graph/benchmark/Benchmark.java @@ -48,9 +48,8 @@ "nb-nodes", "Number of random nodes used to do the benchmark."), new FlaggedOption("logFile", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.REQUIRED, 'l', "log-file", "File name to output CSV format benchmark log."), - new FlaggedOption("seed", JSAP.LONG_PARSER, JSAP.NO_DEFAULT, JSAP.NOT_REQUIRED, 's', - "seed", "Random generator seed."), - }); + new FlaggedOption("seed", JSAP.LONG_PARSER, JSAP.NO_DEFAULT, JSAP.NOT_REQUIRED, 's', "seed", + "Random generator seed."),}); JSAPResult config = jsap.parse(args); if (jsap.messagePrinted()) { @@ -69,12 +68,8 @@ public void createCSVLogFile() throws IOException { try (Writer csvLog = new BufferedWriter(new FileWriter(args.logFile))) { StringJoiner csvHeader = new StringJoiner(CSV_SEPARATOR); - csvHeader.add("use case name") - .add("SWHID") - .add("number of edges accessed") - .add("traversal timing") - .add("swhid2node timing") - .add("node2swhid timing"); + csvHeader.add("use case name").add("SWHID").add("number of edges accessed").add("traversal timing") + .add("swhid2node timing").add("node2swhid timing"); csvLog.write(csvHeader.toString() + "\n"); } } @@ -86,13 +81,12 @@ * @param graph compressed graph used in the benchmark * @param nodeIds node ids to use as starting point for the endpoint traversal * @param operation endpoint function to benchmark - * @param dstFmt destination formatted string as described in the API + * @param dstFmt destination formatted string as described in the + * API * @param algorithm traversal algorithm used in endpoint call (either "dfs" or "bfs") */ public void timeEndpoint(String useCaseName, Graph graph, long[] nodeIds, - Function operation, String dstFmt, String algorithm) - throws IOException { + Function operation, String dstFmt, String algorithm) throws IOException { ArrayList timings = new ArrayList<>(); ArrayList timingsNormalized = new ArrayList<>(); ArrayList nbEdgesAccessed = new ArrayList<>(); @@ -107,9 +101,7 @@ : operation.apply(new Endpoint.Input(swhid, dstFmt, algorithm)); StringJoiner csvLine = new StringJoiner(CSV_SEPARATOR); - csvLine.add(useCaseName) - .add(swhid.toString()) - .add(Long.toString(output.meta.nbEdgesAccessed)) + csvLine.add(useCaseName).add(swhid.toString()).add(Long.toString(output.meta.nbEdgesAccessed)) .add(Double.toString(output.meta.timings.traversal)) .add(Double.toString(output.meta.timings.swhid2node)) .add(Double.toString(output.meta.timings.node2swhid)); @@ -142,7 +134,7 @@ * Same as {@link #timeEndpoint} but without destination or algorithm specified to endpoint call. */ public void timeEndpoint(String useCaseName, Graph graph, long[] nodeIds, - Function operation) throws IOException { + Function operation) throws IOException { timeEndpoint(useCaseName, graph, nodeIds, operation, null, null); } diff --git a/java/src/main/java/org/softwareheritage/graph/benchmark/Browsing.java b/java/src/main/java/org/softwareheritage/graph/benchmark/Browsing.java --- a/java/src/main/java/org/softwareheritage/graph/benchmark/Browsing.java +++ b/java/src/main/java/org/softwareheritage/graph/benchmark/Browsing.java @@ -8,8 +8,8 @@ import java.io.IOException; /** - * Benchmark Software Heritage browsing + * Benchmark Software Heritage + * browsing * use-cases scenarios. * * @author The Software Heritage developers @@ -27,10 +27,8 @@ Graph graph = new Graph(bench.args.graphPath); - long[] dirNodeIds = - bench.args.random.generateNodeIdsOfType(graph, bench.args.nbNodes, Node.Type.DIR); - long[] revNodeIds = - bench.args.random.generateNodeIdsOfType(graph, bench.args.nbNodes, Node.Type.REV); + long[] dirNodeIds = bench.args.random.generateNodeIdsOfType(graph, bench.args.nbNodes, Node.Type.DIR); + long[] revNodeIds = bench.args.random.generateNodeIdsOfType(graph, bench.args.nbNodes, Node.Type.REV); Endpoint dirEndpoint = new Endpoint(graph, "forward", "dir:cnt,dir:dir"); Endpoint revEndpoint = new Endpoint(graph, "forward", "rev:rev"); diff --git a/java/src/main/java/org/softwareheritage/graph/benchmark/Provenance.java b/java/src/main/java/org/softwareheritage/graph/benchmark/Provenance.java --- a/java/src/main/java/org/softwareheritage/graph/benchmark/Provenance.java +++ b/java/src/main/java/org/softwareheritage/graph/benchmark/Provenance.java @@ -7,8 +7,8 @@ import java.io.IOException; /** - * Benchmark Software Heritage provenance + * Benchmark Software Heritage + * provenance * use-cases scenarios. * * @author The Software Heritage developers @@ -34,18 +34,12 @@ System.out.println("Used " + bench.args.nbNodes + " random nodes (results are in seconds):"); bench.createCSVLogFile(); - bench.timeEndpoint( - "commit provenance (dfs)", graph, nodeIds, commitProvenanceEndpoint::walk, "rev", "dfs"); - bench.timeEndpoint( - "commit provenance (bfs)", graph, nodeIds, commitProvenanceEndpoint::walk, "rev", "bfs"); - bench.timeEndpoint( - "complete commit provenance", graph, nodeIds, commitProvenanceEndpoint::leaves); - - bench.timeEndpoint( - "origin provenance (dfs)", graph, nodeIds, originProvenanceEndpoint::walk, "ori", "dfs"); - bench.timeEndpoint( - "origin provenance (bfs)", graph, nodeIds, originProvenanceEndpoint::walk, "ori", "bfs"); - bench.timeEndpoint( - "complete origin provenance", graph, nodeIds, originProvenanceEndpoint::leaves); + bench.timeEndpoint("commit provenance (dfs)", graph, nodeIds, commitProvenanceEndpoint::walk, "rev", "dfs"); + bench.timeEndpoint("commit provenance (bfs)", graph, nodeIds, commitProvenanceEndpoint::walk, "rev", "bfs"); + bench.timeEndpoint("complete commit provenance", graph, nodeIds, commitProvenanceEndpoint::leaves); + + bench.timeEndpoint("origin provenance (dfs)", graph, nodeIds, originProvenanceEndpoint::walk, "ori", "dfs"); + bench.timeEndpoint("origin provenance (bfs)", graph, nodeIds, originProvenanceEndpoint::walk, "ori", "bfs"); + bench.timeEndpoint("complete origin provenance", graph, nodeIds, originProvenanceEndpoint::leaves); } } diff --git a/java/src/main/java/org/softwareheritage/graph/benchmark/Vault.java b/java/src/main/java/org/softwareheritage/graph/benchmark/Vault.java --- a/java/src/main/java/org/softwareheritage/graph/benchmark/Vault.java +++ b/java/src/main/java/org/softwareheritage/graph/benchmark/Vault.java @@ -7,9 +7,9 @@ import java.io.IOException; /** - * Benchmark Software Heritage vault - * use-case scenario. + * Benchmark Software Heritage + * vault use-case + * scenario. * * @author The Software Heritage developers */ diff --git a/java/src/main/java/org/softwareheritage/graph/experiments/forks/FindCommonAncestor.java b/java/src/main/java/org/softwareheritage/graph/experiments/forks/FindCommonAncestor.java --- a/java/src/main/java/org/softwareheritage/graph/experiments/forks/FindCommonAncestor.java +++ b/java/src/main/java/org/softwareheritage/graph/experiments/forks/FindCommonAncestor.java @@ -19,16 +19,12 @@ private static JSAPResult parse_args(String[] args) { JSAPResult config = null; try { - SimpleJSAP jsap = new SimpleJSAP( - FindCommonAncestor.class.getName(), - "", - new Parameter[] { - new FlaggedOption("edgesFmt", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.REQUIRED, - 'e', "edges", "Edges constraints"), - new FlaggedOption("graphPath", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.REQUIRED, - 'g', "graph", "Basename of the compressed graph"), - } - ); + SimpleJSAP jsap = new SimpleJSAP(FindCommonAncestor.class.getName(), "", + new Parameter[]{ + new FlaggedOption("edgesFmt", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.REQUIRED, 'e', + "edges", "Edges constraints"), + new FlaggedOption("graphPath", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.REQUIRED, 'g', + "graph", "Basename of the compressed graph"),}); config = jsap.parse(args); if (jsap.messagePrinted()) { diff --git a/java/src/main/java/org/softwareheritage/graph/experiments/forks/FindPath.java b/java/src/main/java/org/softwareheritage/graph/experiments/forks/FindPath.java --- a/java/src/main/java/org/softwareheritage/graph/experiments/forks/FindPath.java +++ b/java/src/main/java/org/softwareheritage/graph/experiments/forks/FindPath.java @@ -22,14 +22,9 @@ private static JSAPResult parse_args(String[] args) { JSAPResult config = null; try { - SimpleJSAP jsap = new SimpleJSAP( - FindPath.class.getName(), - "", - new Parameter[] { - new FlaggedOption("graphPath", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.REQUIRED, - 'g', "graph", "Basename of the compressed graph"), - } - ); + SimpleJSAP jsap = new SimpleJSAP(FindPath.class.getName(), "", + new Parameter[]{new FlaggedOption("graphPath", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.REQUIRED, + 'g', "graph", "Basename of the compressed graph"),}); config = jsap.parse(args); if (jsap.messagePrinted()) { @@ -42,8 +37,7 @@ } private boolean nodeIsEmptySnapshot(Long node) { - if (this.emptySnapshot == null - && this.graph.getNodeType(node) == Node.Type.SNP + if (this.emptySnapshot == null && this.graph.getNodeType(node) == Node.Type.SNP && this.graph.outdegree(node) == 0) { System.err.println("Found empty snapshot: " + node); this.emptySnapshot = node; @@ -51,10 +45,9 @@ return node.equals(this.emptySnapshot); } - private Boolean shouldVisit(Long node){ + private Boolean shouldVisit(Long node) { Node.Type nt = this.graph.getNodeType(node); - if (nt != Node.Type.REV && nt != Node.Type.REL - && nt != Node.Type.SNP && nt != Node.Type.ORI) { + if (nt != Node.Type.REV && nt != Node.Type.REL && nt != Node.Type.SNP && nt != Node.Type.ORI) { return false; } if (this.nodeIsEmptySnapshot(node)) @@ -76,7 +69,8 @@ final LazyLongIterator iterator = graph.successors(currentNode); long succ; while ((succ = iterator.nextLong()) != -1) { - if (!shouldVisit(succ) || visited.contains(succ)) continue; + if (!shouldVisit(succ) || visited.contains(succ)) + continue; visited.add(succ); queue.add(succ); parentNode.put(succ, currentNode); @@ -121,8 +115,7 @@ System.out.format("%d ", n); } System.out.println(); - } - else { + } else { System.out.println("null"); } } diff --git a/java/src/main/java/org/softwareheritage/graph/experiments/forks/ForkCC.java b/java/src/main/java/org/softwareheritage/graph/experiments/forks/ForkCC.java --- a/java/src/main/java/org/softwareheritage/graph/experiments/forks/ForkCC.java +++ b/java/src/main/java/org/softwareheritage/graph/experiments/forks/ForkCC.java @@ -9,7 +9,6 @@ import it.unimi.dsi.logging.ProgressLogger; import org.softwareheritage.graph.Graph; import org.softwareheritage.graph.Node; -import org.softwareheritage.graph.benchmark.BFS; import java.io.File; import java.io.FileNotFoundException; @@ -26,20 +25,16 @@ private static JSAPResult parse_args(String[] args) { JSAPResult config = null; try { - SimpleJSAP jsap = new SimpleJSAP( - ForkCC.class.getName(), - "", - new Parameter[] { - new FlaggedOption("graphPath", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.REQUIRED, - 'g', "graph", "Basename of the compressed graph"), - new FlaggedOption("whitelistPath", JSAP.STRING_PARSER, null, JSAP.NOT_REQUIRED, - 't', "whitelist", "Whitelist of origins"), - new FlaggedOption("includeRootDir", JSAP.BOOLEAN_PARSER, "false", JSAP.NOT_REQUIRED, - 'R', "includerootdir", "Include root directory (default: false)"), - new FlaggedOption("outdir", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.REQUIRED, - 'o', "outdir", "Directory where to put the results"), - } - ); + SimpleJSAP jsap = new SimpleJSAP(ForkCC.class.getName(), "", + new Parameter[]{ + new FlaggedOption("graphPath", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.REQUIRED, 'g', + "graph", "Basename of the compressed graph"), + new FlaggedOption("whitelistPath", JSAP.STRING_PARSER, null, JSAP.NOT_REQUIRED, 't', + "whitelist", "Whitelist of origins"), + new FlaggedOption("includeRootDir", JSAP.BOOLEAN_PARSER, "false", JSAP.NOT_REQUIRED, 'R', + "includerootdir", "Include root directory (default: false)"), + new FlaggedOption("outdir", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.REQUIRED, 'o', + "outdir", "Directory where to put the results"),}); config = jsap.parse(args); if (jsap.messagePrinted()) { @@ -86,8 +81,7 @@ } private boolean nodeIsEmptySnapshot(Long node) { - if (this.emptySnapshot == null - && this.graph.getNodeType(node) == Node.Type.SNP + if (this.emptySnapshot == null && this.graph.getNodeType(node) == Node.Type.SNP && this.graph.outdegree(node) == 0) { System.err.println("Found empty snapshot: " + node); this.emptySnapshot = node; @@ -128,7 +122,8 @@ ArrayList> components = new ArrayList<>(); for (long i = 0; i < n; i++) { - if (!shouldVisit(i) || this.graph.getNodeType(i) == Node.Type.DIR) continue; + if (!shouldVisit(i) || this.graph.getNodeType(i) == Node.Type.DIR) + continue; ArrayList component = new ArrayList<>(); @@ -139,8 +134,7 @@ queue.dequeue(byteBuf); final long currentNode = Longs.fromByteArray(byteBuf); Node.Type cur_nt = this.graph.getNodeType(currentNode); - if (cur_nt == Node.Type.ORI - && (this.whitelist == null || this.whitelist.getBoolean(currentNode))) { + if (cur_nt == Node.Type.ORI && (this.whitelist == null || this.whitelist.getBoolean(currentNode))) { // TODO: add a check that the origin has >=1 non-empty snapshot component.add(currentNode); } @@ -148,8 +142,10 @@ final LazyLongIterator iterator = graph.successors(currentNode); long succ; while ((succ = iterator.nextLong()) != -1) { - if (!shouldVisit(succ)) continue; - if (this.graph.getNodeType(succ) == Node.Type.DIR && cur_nt != Node.Type.REV) continue; + if (!shouldVisit(succ)) + continue; + if (this.graph.getNodeType(succ) == Node.Type.DIR && cur_nt != Node.Type.REV) + continue; visited.set(succ); queue.enqueue(Longs.toByteArray(succ)); } @@ -238,7 +234,7 @@ } ProgressLogger logger = new ProgressLogger(); - //noinspection ResultOfMethodCallIgnored + // noinspection ResultOfMethodCallIgnored new File(outdirPath).mkdirs(); try { ArrayList> components = forkCc.compute(logger); diff --git a/java/src/main/java/org/softwareheritage/graph/experiments/forks/ForkCliques.java b/java/src/main/java/org/softwareheritage/graph/experiments/forks/ForkCliques.java --- a/java/src/main/java/org/softwareheritage/graph/experiments/forks/ForkCliques.java +++ b/java/src/main/java/org/softwareheritage/graph/experiments/forks/ForkCliques.java @@ -32,18 +32,14 @@ private static JSAPResult parse_args(String[] args) { JSAPResult config = null; try { - SimpleJSAP jsap = new SimpleJSAP( - ForkCliques.class.getName(), - "", + SimpleJSAP jsap = new SimpleJSAP(ForkCliques.class.getName(), "", new Parameter[]{ - new FlaggedOption("graphPath", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.REQUIRED, - 'g', "graph", "Basename of the compressed graph"), - new FlaggedOption("whitelistPath", JSAP.STRING_PARSER, null, JSAP.NOT_REQUIRED, - 't', "whitelist", "Whitelist of origins"), - new FlaggedOption("outdir", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.REQUIRED, - 'o', "outdir", "Directory where to put the results"), - } - ); + new FlaggedOption("graphPath", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.REQUIRED, 'g', + "graph", "Basename of the compressed graph"), + new FlaggedOption("whitelistPath", JSAP.STRING_PARSER, null, JSAP.NOT_REQUIRED, 't', + "whitelist", "Whitelist of origins"), + new FlaggedOption("outdir", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.REQUIRED, 'o', + "outdir", "Directory where to put the results"),}); config = jsap.parse(args); if (jsap.messagePrinted()) { @@ -72,8 +68,7 @@ Node.Type nt = this.graph.getNodeType(succ); if (nt == Node.Type.DIR || nt == Node.Type.CNT) continue; - if (nt == Node.Type.ORI - && (this.whitelist == null || this.whitelist.getBoolean(succ))) { + if (nt == Node.Type.ORI && (this.whitelist == null || this.whitelist.getBoolean(succ))) { res.add(succ); } else { stack.push(succ); @@ -97,7 +92,7 @@ if (this.graph.getNodeType(succ) == Node.Type.REV) return false; } - return true; + return true; } static private String fingerprint(ArrayList cluster) { @@ -180,7 +175,7 @@ Scanner scanner; try { scanner = new Scanner(new File(path)); - while(scanner.hasNextLong()) { + while (scanner.hasNextLong()) { whitelist.set(scanner.nextLong()); } System.err.println("Whitelist loaded."); @@ -214,7 +209,7 @@ ProgressLogger logger = new ProgressLogger(rootLogger); ArrayList> components = forkCliques.compute(logger); - //noinspection ResultOfMethodCallIgnored + // noinspection ResultOfMethodCallIgnored new File(outdirPath).mkdirs(); try { printDistribution(components, new Formatter(outdirPath + "/distribution.txt")); diff --git a/java/src/main/java/org/softwareheritage/graph/experiments/forks/ListEmptyOrigins.java b/java/src/main/java/org/softwareheritage/graph/experiments/forks/ListEmptyOrigins.java --- a/java/src/main/java/org/softwareheritage/graph/experiments/forks/ListEmptyOrigins.java +++ b/java/src/main/java/org/softwareheritage/graph/experiments/forks/ListEmptyOrigins.java @@ -16,14 +16,9 @@ private static JSAPResult parse_args(String[] args) { JSAPResult config = null; try { - SimpleJSAP jsap = new SimpleJSAP( - ListEmptyOrigins.class.getName(), - "", - new Parameter[]{ - new FlaggedOption("graphPath", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.REQUIRED, - 'g', "graph", "Basename of the compressed graph"), - } - ); + SimpleJSAP jsap = new SimpleJSAP(ListEmptyOrigins.class.getName(), "", + new Parameter[]{new FlaggedOption("graphPath", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.REQUIRED, + 'g', "graph", "Basename of the compressed graph"),}); config = jsap.parse(args); if (jsap.messagePrinted()) { @@ -61,8 +56,7 @@ private boolean nodeIsEmptySnapshot(Long node) { System.err.println(this.graph.getNodeType(node) + " " + this.graph.outdegree(node) + " " + node); - if (this.emptySnapshot == null - && this.graph.getNodeType(node) == Node.Type.SNP + if (this.emptySnapshot == null && this.graph.getNodeType(node) == Node.Type.SNP && this.graph.outdegree(node) == 0) { System.err.println("Found empty snapshot: " + node); this.emptySnapshot = node; @@ -75,7 +69,8 @@ ArrayList bad = new ArrayList<>(); for (long i = 0; i < n; 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); long succ; diff --git a/java/src/main/java/org/softwareheritage/graph/experiments/multiplicationfactor/GenDistribution.java b/java/src/main/java/org/softwareheritage/graph/experiments/multiplicationfactor/GenDistribution.java --- a/java/src/main/java/org/softwareheritage/graph/experiments/multiplicationfactor/GenDistribution.java +++ b/java/src/main/java/org/softwareheritage/graph/experiments/multiplicationfactor/GenDistribution.java @@ -18,23 +18,19 @@ private static JSAPResult parse_args(String[] args) { JSAPResult config = null; try { - SimpleJSAP jsap = new SimpleJSAP( - GenDistribution.class.getName(), - "", + SimpleJSAP jsap = new SimpleJSAP(GenDistribution.class.getName(), "", new Parameter[]{ - new FlaggedOption("graphPath", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.REQUIRED, - 'g', "graph", "Basename of the compressed graph"), - new FlaggedOption("srcType", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.REQUIRED, - 's', "srctype", "Source node type"), - new FlaggedOption("dstType", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.REQUIRED, - 'd', "dsttype", "Destination node type"), - new FlaggedOption("edgesFmt", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.REQUIRED, - 'e', "edges", "Edges constraints"), - - new FlaggedOption("numThreads", JSAP.INTEGER_PARSER, "128", JSAP.NOT_REQUIRED, - 't', "numthreads", "Number of threads"), - } - ); + new FlaggedOption("graphPath", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.REQUIRED, 'g', + "graph", "Basename of the compressed graph"), + new FlaggedOption("srcType", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.REQUIRED, 's', + "srctype", "Source node type"), + new FlaggedOption("dstType", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.REQUIRED, 'd', + "dsttype", "Destination node type"), + new FlaggedOption("edgesFmt", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.REQUIRED, 'e', + "edges", "Edges constraints"), + + new FlaggedOption("numThreads", JSAP.INTEGER_PARSER, "128", JSAP.NOT_REQUIRED, 't', + "numthreads", "Number of threads"),}); config = jsap.parse(args); if (jsap.messagePrinted()) { @@ -117,10 +113,8 @@ } }); totalTime = Timing.stop(startTime); - System.out.format("%d %d %d %d %f\n", - node, count[0], t.getNbNodesAccessed(), - t.getNbEdgesAccessed(), totalTime - ); + System.out.format("%d %d %d %d %f\n", node, count[0], t.getNbNodesAccessed(), + t.getNbEdgesAccessed(), totalTime); } }); } diff --git a/java/src/main/java/org/softwareheritage/graph/experiments/topology/ClusteringCoefficient.java b/java/src/main/java/org/softwareheritage/graph/experiments/topology/ClusteringCoefficient.java --- a/java/src/main/java/org/softwareheritage/graph/experiments/topology/ClusteringCoefficient.java +++ b/java/src/main/java/org/softwareheritage/graph/experiments/topology/ClusteringCoefficient.java @@ -5,7 +5,6 @@ import com.martiansoftware.jsap.*; import it.unimi.dsi.big.webgraph.ImmutableGraph; import it.unimi.dsi.big.webgraph.LazyLongIterator; -import it.unimi.dsi.big.webgraph.Transform; import it.unimi.dsi.logging.ProgressLogger; import org.slf4j.LoggerFactory; import org.softwareheritage.graph.Graph; @@ -28,16 +27,12 @@ private static JSAPResult parse_args(String[] args) { JSAPResult config = null; try { - SimpleJSAP jsap = new SimpleJSAP( - ClusteringCoefficient.class.getName(), - "", + SimpleJSAP jsap = new SimpleJSAP(ClusteringCoefficient.class.getName(), "", new Parameter[]{ - new FlaggedOption("graphPath", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.REQUIRED, - 'g', "graph", "Basename of the compressed graph"), - new FlaggedOption("outdir", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.REQUIRED, - 'o', "outdir", "Directory where to put the results"), - } - ); + new FlaggedOption("graphPath", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.REQUIRED, 'g', + "graph", "Basename of the compressed graph"), + new FlaggedOption("outdir", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.REQUIRED, 'o', + "outdir", "Directory where to put the results"),}); config = jsap.parse(args); if (jsap.messagePrinted()) { @@ -155,7 +150,7 @@ trials++; if (trials % 100 == 0 || true) { - double gC = (double)triangles / (double)trials; + double gC = (double) triangles / (double) trials; out_global.format("C: %f (triangles: %d, trials: %d)\n", gC, triangles, trials); System.out.format("C: %f (triangles: %d, trials: %d)\n", gC, triangles, trials); } @@ -182,16 +177,10 @@ new File(outdirPath).mkdirs(); try { - ccoef.compute_approx( - new Formatter(outdirPath + "/local.txt") - ); + ccoef.compute_approx(new Formatter(outdirPath + "/local.txt")); /* - ccoef.compute( - symmetric, - new ProgressLogger(rootLogger), - new Formatter(outdirPath + "/local.txt"), - new Formatter(outdirPath + "/global.txt") - ); + * ccoef.compute( symmetric, new ProgressLogger(rootLogger), new Formatter(outdirPath + + * "/local.txt"), new Formatter(outdirPath + "/global.txt") ); */ } catch (FileNotFoundException e) { e.printStackTrace(); diff --git a/java/src/main/java/org/softwareheritage/graph/experiments/topology/ConnectedComponents.java b/java/src/main/java/org/softwareheritage/graph/experiments/topology/ConnectedComponents.java --- a/java/src/main/java/org/softwareheritage/graph/experiments/topology/ConnectedComponents.java +++ b/java/src/main/java/org/softwareheritage/graph/experiments/topology/ConnectedComponents.java @@ -2,9 +2,7 @@ import com.google.common.primitives.Longs; import com.martiansoftware.jsap.*; -import it.unimi.dsi.big.webgraph.ImmutableGraph; import it.unimi.dsi.big.webgraph.LazyLongIterator; -import it.unimi.dsi.big.webgraph.Transform; import it.unimi.dsi.bits.LongArrayBitVector; import it.unimi.dsi.fastutil.Arrays; import it.unimi.dsi.io.ByteDiskQueue; @@ -29,16 +27,12 @@ private static JSAPResult parse_args(String[] args) { JSAPResult config = null; try { - SimpleJSAP jsap = new SimpleJSAP( - ConnectedComponents.class.getName(), - "", - new Parameter[] { - new FlaggedOption("graphPath", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.REQUIRED, - 'g', "graph", "Basename of the compressed graph"), - new FlaggedOption("outdir", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.REQUIRED, - 'o', "outdir", "Directory where to put the results"), - } - ); + SimpleJSAP jsap = new SimpleJSAP(ConnectedComponents.class.getName(), "", + new Parameter[]{ + new FlaggedOption("graphPath", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.REQUIRED, 'g', + "graph", "Basename of the compressed graph"), + new FlaggedOption("outdir", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.REQUIRED, 'o', + "outdir", "Directory where to put the results"),}); config = jsap.parse(args); if (jsap.messagePrinted()) { @@ -50,11 +44,11 @@ return config; } - private HashMap /*ArrayList>*/ compute(ProgressLogger pl) throws IOException { + private HashMap /* ArrayList> */ compute(ProgressLogger pl) throws IOException { final long n = graph.numNodes(); // Allow enough memory to behave like in-memory queue - int bufferSize = (int)Math.min(Arrays.MAX_ARRAY_SIZE & ~0x7, 8L * n); + int bufferSize = (int) Math.min(Arrays.MAX_ARRAY_SIZE & ~0x7, 8L * n); // Use a disk based queue to store BFS frontier final File queueFile = File.createTempFile(ConnectedComponents.class.getSimpleName(), "queue"); @@ -97,10 +91,8 @@ } /* - if (component.size() > 0) { - components.add(component); - } - */ + * if (component.size() > 0) { components.add(component); } + */ if (componentNodes > 0) componentDistribution.merge(componentNodes, 1L, Long::sum); } @@ -161,7 +153,7 @@ } ProgressLogger logger = new ProgressLogger(); - //noinspection ResultOfMethodCallIgnored + // noinspection ResultOfMethodCallIgnored new File(outdirPath).mkdirs(); try { // ArrayList> components = connectedComponents.compute(logger); diff --git a/java/src/main/java/org/softwareheritage/graph/experiments/topology/InOutDegree.java b/java/src/main/java/org/softwareheritage/graph/experiments/topology/InOutDegree.java --- a/java/src/main/java/org/softwareheritage/graph/experiments/topology/InOutDegree.java +++ b/java/src/main/java/org/softwareheritage/graph/experiments/topology/InOutDegree.java @@ -18,150 +18,157 @@ import org.softwareheritage.graph.Node; public class InOutDegree { - private InOutDegree() {} - - private static final int NODE_ARRAY_SIZE = Node.Type.values().length + 1; - private static final int TYPE_ALL = Node.Type.values().length; - private static final int TYPE_CNT = Node.Type.toInt(Node.Type.CNT); - private static final int TYPE_DIR = Node.Type.toInt(Node.Type.DIR); - private static final int TYPE_REV = Node.Type.toInt(Node.Type.REV); - private static final int TYPE_REL = Node.Type.toInt(Node.Type.REL); - private static final int TYPE_SNP = Node.Type.toInt(Node.Type.SNP); - private static final int TYPE_ORI = Node.Type.toInt(Node.Type.ORI); - - public static long[] outdegreeTypes(final Graph graph, long node) { - long[] out = new long[NODE_ARRAY_SIZE]; - var successors = graph.successors(node); - long neighbor; - while ((neighbor = successors.nextLong()) != -1) { - out[Node.Type.toInt(graph.getNodeType(neighbor))]++; - out[TYPE_ALL]++; - } - return out; - } - - public static long[] indegreeTypes(final Graph graph, long node) { - return outdegreeTypes(graph.transpose(), node); - } - - public static void writeDistribution(HashMap distribution, String filename) throws IOException { - PrintWriter f = new PrintWriter(new FileWriter(filename)); - TreeMap sortedDistribution = new TreeMap<>(distribution); - for (Map.Entry entry : sortedDistribution.entrySet()) { - f.println(entry.getKey() + " " + entry.getValue()); - } - f.close(); - } - - public static void run(final Graph graph, String resultsDir) throws IOException { - var cnt_in_dir = new HashMap(); - var dir_in_dir = new HashMap(); - var dir_in_rev = new HashMap(); - var dir_in_all = new HashMap(); - var dir_out_all = new HashMap(); - var dir_out_dir = new HashMap(); - var dir_out_cnt = new HashMap(); - var dir_out_rev = new HashMap(); - var rev_in_dir = new HashMap(); - var rev_in_rel = new HashMap(); - var rev_in_rev = new HashMap(); - var rev_in_snp = new HashMap(); - var rev_in_all = new HashMap(); - var rev_out_rev = new HashMap(); - var rel_in_snp = new HashMap(); - var snp_in_ori = new HashMap(); - var snp_out_all = new HashMap(); - var snp_out_rel = new HashMap(); - var snp_out_rev = new HashMap(); - var ori_out_snp = new HashMap(); - - final ProgressLogger pl = new ProgressLogger(); - pl.itemsName = "nodes"; - pl.expectedUpdates = graph.numNodes(); - pl.start("Scanning..."); - - long[] in; - long[] out; - - for(long i = graph.numNodes(); i-- != 0;) { - switch (graph.getNodeType(i)) { - case CNT: - cnt_in_dir.merge(graph.indegree(i), 1L, Long::sum); - case DIR: - in = indegreeTypes(graph, i); - out = outdegreeTypes(graph, i); - dir_in_all.merge(in[TYPE_ALL], 1L, Long::sum); - dir_out_all.merge(out[TYPE_ALL], 1L, Long::sum); - dir_in_dir.merge(in[TYPE_DIR], 1L, Long::sum); - dir_in_rev.merge(in[TYPE_REV], 1L, Long::sum); - dir_out_cnt.merge(out[TYPE_CNT], 1L, Long::sum); - dir_out_dir.merge(out[TYPE_DIR], 1L, Long::sum); - dir_out_rev.merge(out[TYPE_REV], 1L, Long::sum); - case REV: - in = indegreeTypes(graph, i); - out = outdegreeTypes(graph, i); - rev_in_all.merge(in[TYPE_ALL], 1L, Long::sum); - rev_in_dir.merge(in[TYPE_DIR], 1L, Long::sum); - rev_in_rev.merge(in[TYPE_REV], 1L, Long::sum); - rev_in_rel.merge(in[TYPE_REL], 1L, Long::sum); - rev_in_snp.merge(in[TYPE_SNP], 1L, Long::sum); - rev_out_rev.merge(out[TYPE_REV], 1L, Long::sum); - case REL: - rel_in_snp.merge(graph.indegree(i), 1L, Long::sum); - case SNP: - out = outdegreeTypes(graph, i); - snp_in_ori.merge(graph.indegree(i), 1L, Long::sum); - snp_out_all.merge(out[TYPE_ALL], 1L, Long::sum); - snp_out_rel.merge(out[TYPE_REL], 1L, Long::sum); - snp_out_rev.merge(out[TYPE_REV], 1L, Long::sum); - case ORI: - ori_out_snp.merge(graph.outdegree(i), 1L, Long::sum); - } - - pl.update(); - } - - pl.done(); - - writeDistribution(cnt_in_dir, resultsDir + "/cnt_in_dir.txt"); - writeDistribution(dir_in_dir, resultsDir + "/dir_in_dir.txt"); - writeDistribution(dir_in_rev, resultsDir + "/dir_in_rev.txt"); - writeDistribution(dir_in_all, resultsDir + "/dir_in_all.txt"); - writeDistribution(dir_out_all, resultsDir + "/dir_out_all.txt"); - writeDistribution(dir_out_dir, resultsDir + "/dir_out_dir.txt"); - writeDistribution(dir_out_cnt, resultsDir + "/dir_out_cnt.txt"); - writeDistribution(dir_out_rev, resultsDir + "/dir_out_rev.txt"); - writeDistribution(rev_in_dir, resultsDir + "/rev_in_dir.txt"); - writeDistribution(rev_in_rel, resultsDir + "/rev_in_rel.txt"); - writeDistribution(rev_in_rev, resultsDir + "/rev_in_rev.txt"); - writeDistribution(rev_in_snp, resultsDir + "/rev_in_snp.txt"); - writeDistribution(rev_in_all, resultsDir + "/rev_in_all.txt"); - writeDistribution(rev_out_rev, resultsDir + "/rev_out_rev.txt"); - writeDistribution(rel_in_snp, resultsDir + "/rel_in_snp.txt"); - writeDistribution(snp_in_ori, resultsDir + "/snp_in_ori.txt"); - writeDistribution(snp_out_all, resultsDir + "/snp_out_all.txt"); - writeDistribution(snp_out_rel, resultsDir + "/snp_out_rel.txt"); - writeDistribution(snp_out_rev, resultsDir + "/snp_out_rev.txt"); - writeDistribution(ori_out_snp, resultsDir + "/ori_out_snp.txt"); - } - - static public void main(final String[] arg) throws IllegalArgumentException, SecurityException, IllegalAccessException, InvocationTargetException, NoSuchMethodException, JSAPException, IOException, ClassNotFoundException { - final SimpleJSAP jsap = new SimpleJSAP(InOutDegree.class.getName(), "Computes in and out degrees of the given SWHGraph", - new Parameter[] { - new UnflaggedOption("basename", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.REQUIRED, JSAP.NOT_GREEDY, "The basename of the graph."), - new UnflaggedOption("resultsDir", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.NOT_REQUIRED, JSAP.NOT_GREEDY, "The directory of the resulting files."), - } - ); - - final JSAPResult jsapResult = jsap.parse(arg); - if (jsap.messagePrinted()) System.exit(1); - - final String basename = jsapResult.getString("basename"); - final String resultsDir = jsapResult.userSpecified("resultsDir") ? jsapResult.getString("resultsDir") : basename; - - final ProgressLogger pl = new ProgressLogger(); - - Graph graph = new Graph(basename); - run(graph, resultsDir); - } + private InOutDegree() { + } + + private static final int NODE_ARRAY_SIZE = Node.Type.values().length + 1; + private static final int TYPE_ALL = Node.Type.values().length; + private static final int TYPE_CNT = Node.Type.toInt(Node.Type.CNT); + private static final int TYPE_DIR = Node.Type.toInt(Node.Type.DIR); + private static final int TYPE_REV = Node.Type.toInt(Node.Type.REV); + private static final int TYPE_REL = Node.Type.toInt(Node.Type.REL); + private static final int TYPE_SNP = Node.Type.toInt(Node.Type.SNP); + private static final int TYPE_ORI = Node.Type.toInt(Node.Type.ORI); + + public static long[] outdegreeTypes(final Graph graph, long node) { + long[] out = new long[NODE_ARRAY_SIZE]; + var successors = graph.successors(node); + long neighbor; + while ((neighbor = successors.nextLong()) != -1) { + out[Node.Type.toInt(graph.getNodeType(neighbor))]++; + out[TYPE_ALL]++; + } + return out; + } + + public static long[] indegreeTypes(final Graph graph, long node) { + return outdegreeTypes(graph.transpose(), node); + } + + public static void writeDistribution(HashMap distribution, String filename) throws IOException { + PrintWriter f = new PrintWriter(new FileWriter(filename)); + TreeMap sortedDistribution = new TreeMap<>(distribution); + for (Map.Entry entry : sortedDistribution.entrySet()) { + f.println(entry.getKey() + " " + entry.getValue()); + } + f.close(); + } + + public static void run(final Graph graph, String resultsDir) throws IOException { + var cnt_in_dir = new HashMap(); + var dir_in_dir = new HashMap(); + var dir_in_rev = new HashMap(); + var dir_in_all = new HashMap(); + var dir_out_all = new HashMap(); + var dir_out_dir = new HashMap(); + var dir_out_cnt = new HashMap(); + var dir_out_rev = new HashMap(); + var rev_in_dir = new HashMap(); + var rev_in_rel = new HashMap(); + var rev_in_rev = new HashMap(); + var rev_in_snp = new HashMap(); + var rev_in_all = new HashMap(); + var rev_out_rev = new HashMap(); + var rel_in_snp = new HashMap(); + var snp_in_ori = new HashMap(); + var snp_out_all = new HashMap(); + var snp_out_rel = new HashMap(); + var snp_out_rev = new HashMap(); + var ori_out_snp = new HashMap(); + + final ProgressLogger pl = new ProgressLogger(); + pl.itemsName = "nodes"; + pl.expectedUpdates = graph.numNodes(); + pl.start("Scanning..."); + + long[] in; + long[] out; + + for (long i = graph.numNodes(); i-- != 0;) { + switch (graph.getNodeType(i)) { + case CNT: + cnt_in_dir.merge(graph.indegree(i), 1L, Long::sum); + case DIR: + in = indegreeTypes(graph, i); + out = outdegreeTypes(graph, i); + dir_in_all.merge(in[TYPE_ALL], 1L, Long::sum); + dir_out_all.merge(out[TYPE_ALL], 1L, Long::sum); + dir_in_dir.merge(in[TYPE_DIR], 1L, Long::sum); + dir_in_rev.merge(in[TYPE_REV], 1L, Long::sum); + dir_out_cnt.merge(out[TYPE_CNT], 1L, Long::sum); + dir_out_dir.merge(out[TYPE_DIR], 1L, Long::sum); + dir_out_rev.merge(out[TYPE_REV], 1L, Long::sum); + case REV: + in = indegreeTypes(graph, i); + out = outdegreeTypes(graph, i); + rev_in_all.merge(in[TYPE_ALL], 1L, Long::sum); + rev_in_dir.merge(in[TYPE_DIR], 1L, Long::sum); + rev_in_rev.merge(in[TYPE_REV], 1L, Long::sum); + rev_in_rel.merge(in[TYPE_REL], 1L, Long::sum); + rev_in_snp.merge(in[TYPE_SNP], 1L, Long::sum); + rev_out_rev.merge(out[TYPE_REV], 1L, Long::sum); + case REL: + rel_in_snp.merge(graph.indegree(i), 1L, Long::sum); + case SNP: + out = outdegreeTypes(graph, i); + snp_in_ori.merge(graph.indegree(i), 1L, Long::sum); + snp_out_all.merge(out[TYPE_ALL], 1L, Long::sum); + snp_out_rel.merge(out[TYPE_REL], 1L, Long::sum); + snp_out_rev.merge(out[TYPE_REV], 1L, Long::sum); + case ORI: + ori_out_snp.merge(graph.outdegree(i), 1L, Long::sum); + } + + pl.update(); + } + + pl.done(); + + writeDistribution(cnt_in_dir, resultsDir + "/cnt_in_dir.txt"); + writeDistribution(dir_in_dir, resultsDir + "/dir_in_dir.txt"); + writeDistribution(dir_in_rev, resultsDir + "/dir_in_rev.txt"); + writeDistribution(dir_in_all, resultsDir + "/dir_in_all.txt"); + writeDistribution(dir_out_all, resultsDir + "/dir_out_all.txt"); + writeDistribution(dir_out_dir, resultsDir + "/dir_out_dir.txt"); + writeDistribution(dir_out_cnt, resultsDir + "/dir_out_cnt.txt"); + writeDistribution(dir_out_rev, resultsDir + "/dir_out_rev.txt"); + writeDistribution(rev_in_dir, resultsDir + "/rev_in_dir.txt"); + writeDistribution(rev_in_rel, resultsDir + "/rev_in_rel.txt"); + writeDistribution(rev_in_rev, resultsDir + "/rev_in_rev.txt"); + writeDistribution(rev_in_snp, resultsDir + "/rev_in_snp.txt"); + writeDistribution(rev_in_all, resultsDir + "/rev_in_all.txt"); + writeDistribution(rev_out_rev, resultsDir + "/rev_out_rev.txt"); + writeDistribution(rel_in_snp, resultsDir + "/rel_in_snp.txt"); + writeDistribution(snp_in_ori, resultsDir + "/snp_in_ori.txt"); + writeDistribution(snp_out_all, resultsDir + "/snp_out_all.txt"); + writeDistribution(snp_out_rel, resultsDir + "/snp_out_rel.txt"); + writeDistribution(snp_out_rev, resultsDir + "/snp_out_rev.txt"); + writeDistribution(ori_out_snp, resultsDir + "/ori_out_snp.txt"); + } + + static public void main(final String[] arg) + throws IllegalArgumentException, SecurityException, IllegalAccessException, InvocationTargetException, + NoSuchMethodException, JSAPException, IOException, ClassNotFoundException { + final SimpleJSAP jsap = new SimpleJSAP(InOutDegree.class.getName(), + "Computes in and out degrees of the given SWHGraph", + new Parameter[]{ + new UnflaggedOption("basename", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.REQUIRED, + JSAP.NOT_GREEDY, "The basename of the graph."), + new UnflaggedOption("resultsDir", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.NOT_REQUIRED, + JSAP.NOT_GREEDY, "The directory of the resulting files."),}); + + final JSAPResult jsapResult = jsap.parse(arg); + if (jsap.messagePrinted()) + System.exit(1); + + final String basename = jsapResult.getString("basename"); + final String resultsDir = jsapResult.userSpecified("resultsDir") + ? jsapResult.getString("resultsDir") + : basename; + + final ProgressLogger pl = new ProgressLogger(); + + Graph graph = new Graph(basename); + run(graph, resultsDir); + } } diff --git a/java/src/main/java/org/softwareheritage/graph/experiments/topology/SubdatasetSizeFunction.java b/java/src/main/java/org/softwareheritage/graph/experiments/topology/SubdatasetSizeFunction.java --- a/java/src/main/java/org/softwareheritage/graph/experiments/topology/SubdatasetSizeFunction.java +++ b/java/src/main/java/org/softwareheritage/graph/experiments/topology/SubdatasetSizeFunction.java @@ -19,70 +19,72 @@ public class SubdatasetSizeFunction { - private SubdatasetSizeFunction() {} - - public static void run(final Graph graph) throws IOException { - final ProgressLogger pl = new ProgressLogger(); - pl.itemsName = "nodes"; - pl.expectedUpdates = graph.numNodes(); - - long n = graph.numNodes(); - LongArrayBitVector visited = LongArrayBitVector.ofLength(n); - - int bufferSize = (int) Math.min(Arrays.MAX_ARRAY_SIZE & ~0x7, 8L * n); - final File queueFile = File.createTempFile(ForkCC.class.getSimpleName(), "queue"); - final ByteDiskQueue queue = ByteDiskQueue.createNew(queueFile, bufferSize, true); - final byte[] byteBuf = new byte[Long.BYTES]; - - long[][] randomPerm = Util.identity(graph.numNodes()); - LongBigArrays.shuffle(randomPerm, new XoRoShiRo128PlusRandom()); - - long visitedSize = 0; - pl.start("Running traversal starting from origins..."); - for (long j = 0; j < n; ++j) { - long i = BigArrays.get(randomPerm, j); - if (visited.getBoolean(i) || graph.getNodeType(i) != Node.Type.ORI) { - continue; - } - queue.enqueue(Longs.toByteArray(i)); - visited.set(i); - - while (!queue.isEmpty()) { - queue.dequeue(byteBuf); - final long currentNode = Longs.fromByteArray(byteBuf); - - visitedSize++; - - final LazyLongIterator iterator = graph.successors(currentNode); - long succ; - while ((succ = iterator.nextLong()) != -1) { - if (visited.getBoolean(succ)) - continue; - visited.set(succ); - queue.enqueue(Longs.toByteArray(succ)); - } - - pl.update(); - } - - System.out.println(visitedSize); - } - pl.done(); - } - - static public void main(final String[] arg) throws IllegalArgumentException, SecurityException, JSAPException, IOException { - final SimpleJSAP jsap = new SimpleJSAP(SubdatasetSizeFunction.class.getName(), "Computes in and out degrees of the given SWHGraph", - new Parameter[] { - new UnflaggedOption("basename", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.REQUIRED, JSAP.NOT_GREEDY, "The basename of the graph."), - } - ); - - final JSAPResult jsapResult = jsap.parse(arg); - if (jsap.messagePrinted()) System.exit(1); - - final String basename = jsapResult.getString("basename"); - - Graph graph = new Graph(basename); - run(graph); - } + private SubdatasetSizeFunction() { + } + + public static void run(final Graph graph) throws IOException { + final ProgressLogger pl = new ProgressLogger(); + pl.itemsName = "nodes"; + pl.expectedUpdates = graph.numNodes(); + + long n = graph.numNodes(); + LongArrayBitVector visited = LongArrayBitVector.ofLength(n); + + int bufferSize = (int) Math.min(Arrays.MAX_ARRAY_SIZE & ~0x7, 8L * n); + final File queueFile = File.createTempFile(ForkCC.class.getSimpleName(), "queue"); + final ByteDiskQueue queue = ByteDiskQueue.createNew(queueFile, bufferSize, true); + final byte[] byteBuf = new byte[Long.BYTES]; + + long[][] randomPerm = Util.identity(graph.numNodes()); + LongBigArrays.shuffle(randomPerm, new XoRoShiRo128PlusRandom()); + + long visitedSize = 0; + pl.start("Running traversal starting from origins..."); + for (long j = 0; j < n; ++j) { + long i = BigArrays.get(randomPerm, j); + if (visited.getBoolean(i) || graph.getNodeType(i) != Node.Type.ORI) { + continue; + } + queue.enqueue(Longs.toByteArray(i)); + visited.set(i); + + while (!queue.isEmpty()) { + queue.dequeue(byteBuf); + final long currentNode = Longs.fromByteArray(byteBuf); + + visitedSize++; + + final LazyLongIterator iterator = graph.successors(currentNode); + long succ; + while ((succ = iterator.nextLong()) != -1) { + if (visited.getBoolean(succ)) + continue; + visited.set(succ); + queue.enqueue(Longs.toByteArray(succ)); + } + + pl.update(); + } + + System.out.println(visitedSize); + } + pl.done(); + } + + static public void main(final String[] arg) + throws IllegalArgumentException, SecurityException, JSAPException, IOException { + final SimpleJSAP jsap = new SimpleJSAP(SubdatasetSizeFunction.class.getName(), + "Computes in and out degrees of the given SWHGraph", + new Parameter[]{new UnflaggedOption("basename", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.REQUIRED, + JSAP.NOT_GREEDY, "The basename of the graph."),}); + + final JSAPResult jsapResult = jsap.parse(arg); + if (jsap.messagePrinted()) + System.exit(1); + + final String basename = jsapResult.getString("basename"); + + Graph graph = new Graph(basename); + run(graph); + } } diff --git a/java/src/main/java/org/softwareheritage/graph/maps/LabelMapBuilder.java b/java/src/main/java/org/softwareheritage/graph/maps/LabelMapBuilder.java --- a/java/src/main/java/org/softwareheritage/graph/maps/LabelMapBuilder.java +++ b/java/src/main/java/org/softwareheritage/graph/maps/LabelMapBuilder.java @@ -4,7 +4,6 @@ import it.unimi.dsi.big.webgraph.LazyLongIterator; import it.unimi.dsi.big.webgraph.labelling.ArcLabelledImmutableGraph; import it.unimi.dsi.big.webgraph.labelling.BitStreamArcLabelledImmutableGraph; -import it.unimi.dsi.big.webgraph.labelling.FixedWidthIntLabel; import it.unimi.dsi.big.webgraph.labelling.FixedWidthIntListLabel; import it.unimi.dsi.fastutil.BigArrays; import it.unimi.dsi.fastutil.Size64; @@ -35,20 +34,15 @@ private static JSAPResult parse_args(String[] args) { JSAPResult config = null; try { - SimpleJSAP jsap = new SimpleJSAP( - LabelMapBuilder.class.getName(), - "", - new Parameter[] { - new FlaggedOption("graphPath", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.REQUIRED, - 'g', "graph", "Basename of the compressed graph"), - new FlaggedOption("debugPath", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.NOT_REQUIRED, - 'd', "debug-path", - "Store the intermediate representation here for debug"), - - new FlaggedOption("tmpDir", JSAP.STRING_PARSER, "tmp", JSAP.NOT_REQUIRED, - 't', "tmp", "Temporary directory path"), - } - ); + SimpleJSAP jsap = new SimpleJSAP(LabelMapBuilder.class.getName(), "", + new Parameter[]{ + new FlaggedOption("graphPath", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.REQUIRED, 'g', + "graph", "Basename of the compressed graph"), + new FlaggedOption("debugPath", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.NOT_REQUIRED, 'd', + "debug-path", "Store the intermediate representation here for debug"), + + new FlaggedOption("tmpDir", JSAP.STRING_PARSER, "tmp", JSAP.NOT_REQUIRED, 't', "tmp", + "Temporary directory path"),}); config = jsap.parse(args); if (jsap.messagePrinted()) { @@ -85,21 +79,17 @@ return mphMap; } - static long getMPHSize(Object2LongFunction mph) - { + static long getMPHSize(Object2LongFunction mph) { return (mph instanceof Size64) ? ((Size64) mph).size64() : mph.size(); } - static long SwhIDToNode(String strSWHID, Object2LongFunction mphMap, long[][] orderMap) - { + static long SwhIDToNode(String strSWHID, Object2LongFunction mphMap, long[][] orderMap) { long mphId = mphMap.getLong(strSWHID); return BigArrays.get(orderMap, mphId); } - static void computeLabelMap(String graphPath, String debugPath, String tmpDir) - throws IOException - { - // Compute intermediate representation in the format "

- * Java has a limit for mmap()-ed files because of unsupported 64-bit indexing. The dsiutils ByteBufferInputStream is used to overcome this - * Java limit. + * Java has a limit for mmap()-ed files because of unsupported 64-bit indexing. The + * dsiutils ByteBufferInputStream is used to overcome + * this Java limit. * * @author The Software Heritage developers */ diff --git a/java/src/main/java/org/softwareheritage/graph/maps/NodeIdMap.java b/java/src/main/java/org/softwareheritage/graph/maps/NodeIdMap.java --- a/java/src/main/java/org/softwareheritage/graph/maps/NodeIdMap.java +++ b/java/src/main/java/org/softwareheritage/graph/maps/NodeIdMap.java @@ -8,8 +8,8 @@ /** * Mapping between internal long node id and external SWHID. *

- * Mappings in both directions are pre-computed and dumped on disk in the - * {@link NodeMapBuilder} class, then they are loaded here using mmap(). + * Mappings in both directions are pre-computed and dumped on disk in the {@link NodeMapBuilder} + * class, then they are loaded here using mmap(). * * @author The Software Heritage developers * @see NodeMapBuilder @@ -57,8 +57,9 @@ * @see SWHID */ public long getNodeId(SWHID swhid) { - // The file is sorted by swhid, hence we can binary search on swhid to get corresponding - // nodeId + /* + * The file is sorted by swhid, hence we can binary search on swhid to get corresponding nodeId + */ long start = 0; long end = nbIds - 1; @@ -94,9 +95,10 @@ * @see SWHID */ public SWHID getSWHID(long nodeId) { - // Each line in NODE_TO_SWHID is formatted as: swhid - // The file is ordered by nodeId, meaning node0's swhid is at line 0, hence we can read the - // nodeId-th line to get corresponding swhid + /* + * Each line in NODE_TO_SWHID is formatted as: swhid The file is ordered by nodeId, meaning node0's + * swhid is at line 0, hence we can read the nodeId-th line to get corresponding swhid + */ if (nodeId < 0 || nodeId >= nbIds) { throw new IllegalArgumentException("Node id " + nodeId + " should be between 0 and " + nbIds); } diff --git a/java/src/main/java/org/softwareheritage/graph/maps/NodeMapBuilder.java b/java/src/main/java/org/softwareheritage/graph/maps/NodeMapBuilder.java --- a/java/src/main/java/org/softwareheritage/graph/maps/NodeMapBuilder.java +++ b/java/src/main/java/org/softwareheritage/graph/maps/NodeMapBuilder.java @@ -24,9 +24,11 @@ /** * Create maps needed at runtime by the graph service, in particular: *

- * - SWHID → WebGraph long node id - * - WebGraph long node id → SWHID (converse of the former) - * - WebGraph long node id → SWH node type (enum) + *

* * @author The Software Heritage developers */ @@ -61,15 +63,16 @@ */ // Suppress warning for Object2LongFunction cast @SuppressWarnings("unchecked") - static void precomputeNodeIdMap(String graphPath, String tmpDir) - throws IOException { + static void precomputeNodeIdMap(String graphPath, String tmpDir) throws IOException { ProgressLogger plSWHID2Node = new ProgressLogger(logger, 10, TimeUnit.SECONDS); ProgressLogger plNode2SWHID = new ProgressLogger(logger, 10, TimeUnit.SECONDS); plSWHID2Node.itemsName = "swhid→node"; plNode2SWHID.itemsName = "node→swhid"; - // avg speed for swhid→node is sometime skewed due to write to the sort - // pipe hanging when sort is sorting; hence also desplay local speed + /* + * avg speed for swhid→node is sometime skewed due to write to the sort pipe hanging when sort is + * sorting; hence also desplay local speed + */ plSWHID2Node.displayLocalSpeed = true; // first half of SWHID->node mapping: SWHID -> WebGraph MPH (long) @@ -96,19 +99,20 @@ System.exit(2); } - // Create mapping SWHID -> WebGraph node id, by sequentially reading - // nodes, hashing them with MPH, and permuting according to BFS order - FastBufferedReader buffer = new FastBufferedReader(new InputStreamReader(System.in, - StandardCharsets.US_ASCII)); + /* + * Create mapping SWHID -> WebGraph node id, by sequentially reading nodes, hashing them with MPH, + * and permuting according to BFS order + */ + FastBufferedReader buffer = new FastBufferedReader(new InputStreamReader(System.in, StandardCharsets.US_ASCII)); LineIterator swhidIterator = new LineIterator(buffer); - // The WebGraph node id -> SWHID mapping can be obtained from the - // SWHID->node one by numerically sorting on node id and sequentially - // writing obtained SWHIDs to a binary map. Delegates the sorting job to - // /usr/bin/sort via pipes + /* + * The WebGraph node id -> SWHID mapping can be obtained from the SWHID->node one by numerically + * sorting on node id and sequentially writing obtained SWHIDs to a binary map. Delegates the + * sorting job to /usr/bin/sort via pipes + */ ProcessBuilder processBuilder = new ProcessBuilder(); - processBuilder.command("sort", "--numeric-sort", "--key", "2", - "--buffer-size", SORT_BUFFER_SIZE, + processBuilder.command("sort", "--numeric-sort", "--key", "2", "--buffer-size", SORT_BUFFER_SIZE, "--temporary-directory", tmpDir); Process sort = processBuilder.start(); BufferedOutputStream sort_stdin = new BufferedOutputStream(sort.getOutputStream()); @@ -116,23 +120,25 @@ // for the binary format of swhidToNodeMap, see Python module swh.graph.swhid:SwhidToIntMap // for the binary format of nodeToSwhidMap, see Python module swh.graph.swhid:IntToSwhidMap - try (DataOutputStream swhidToNodeMap = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(graphPath + Graph.SWHID_TO_NODE))); - BufferedOutputStream nodeToSwhidMap = new BufferedOutputStream(new FileOutputStream(graphPath + Graph.NODE_TO_SWHID))) { - - // background handler for sort output, it will be fed SWHID/node - // pairs while swhidToNodeMap is being filled, and will itself fill - // nodeToSwhidMap as soon as data from sort is ready + try (DataOutputStream swhidToNodeMap = new DataOutputStream( + new BufferedOutputStream(new FileOutputStream(graphPath + Graph.SWHID_TO_NODE))); + BufferedOutputStream nodeToSwhidMap = new BufferedOutputStream( + new FileOutputStream(graphPath + Graph.NODE_TO_SWHID))) { + + /* + * background handler for sort output, it will be fed SWHID/node pairs while swhidToNodeMap is being + * filled, and will itself fill nodeToSwhidMap as soon as data from sort is ready + */ SortOutputHandler outputHandler = new SortOutputHandler(sort_stdout, nodeToSwhidMap, plNode2SWHID); outputHandler.start(); - // Type map from WebGraph node ID to SWH type. Used at runtime by - // pure Java graph traversals to efficiently check edge - // restrictions. - final int log2NbTypes = (int) Math.ceil(Math.log(Node.Type.values().length) - / Math.log(2)); + /* + * Type map from WebGraph node ID to SWH type. Used at runtime by pure Java graph traversals to + * efficiently check edge restrictions. + */ + final int log2NbTypes = (int) Math.ceil(Math.log(Node.Type.values().length) / Math.log(2)); final int nbBitsPerNodeType = log2NbTypes; - LongArrayBitVector nodeTypesBitVector = - LongArrayBitVector.ofLength(nbBitsPerNodeType * nbIds); + LongArrayBitVector nodeTypesBitVector = LongArrayBitVector.ofLength(nbBitsPerNodeType * nbIds); LongBigList nodeTypesMap = nodeTypesBitVector.asLongBigList(nbBitsPerNodeType); plSWHID2Node.start("filling swhid2node map"); @@ -146,8 +152,7 @@ swhidToNodeMap.write(swhidBin, 0, swhidBin.length); swhidToNodeMap.writeLong(nodeId); - sort_stdin.write((swhidStr + "\t" + nodeId + "\n") - .getBytes(StandardCharsets.US_ASCII)); + sort_stdin.write((swhidStr + "\t" + nodeId + "\n").getBytes(StandardCharsets.US_ASCII)); nodeTypesMap.set(nodeId, swhid.getType().ordinal()); plSWHID2Node.lightUpdate(); @@ -196,8 +201,8 @@ sortDone = true; this.pl.start("filling node2swhid map"); } - String line = input.nextLine(); // format: SWHID NODE_ID - SWHID swhid = new SWHID(line.split("\\t")[0]); // get SWHID + String line = input.nextLine(); // format: SWHID NODE_ID + SWHID swhid = new SWHID(line.split("\\t")[0]); // get SWHID try { output.write((byte[]) swhid.toBytes()); } catch (IOException e) { diff --git a/java/src/main/java/org/softwareheritage/graph/maps/NodeTypesMap.java b/java/src/main/java/org/softwareheritage/graph/maps/NodeTypesMap.java --- a/java/src/main/java/org/softwareheritage/graph/maps/NodeTypesMap.java +++ b/java/src/main/java/org/softwareheritage/graph/maps/NodeTypesMap.java @@ -8,15 +8,13 @@ import java.io.IOException; /** - * Mapping between long node id and SWH node type as described in the data - * model. + * Mapping between long node id and SWH node type as described in the + * data model. *

- * The type mapping is pre-computed and dumped on disk in the {@link NodeMapBuilder} - * class, then it is loaded in-memory here using - * fastutil LongBigList. To be - * space-efficient, the mapping is stored as a bitmap using minimum number of - * bits per {@link Node.Type}. + * The type mapping is pre-computed and dumped on disk in the {@link NodeMapBuilder} class, then it + * is loaded in-memory here using fastutil LongBigList. + * To be space-efficient, the mapping is stored as a bitmap using minimum number of bits per + * {@link Node.Type}. * * @author The Software Heritage developers */ diff --git a/java/src/main/java/org/softwareheritage/graph/server/App.java b/java/src/main/java/org/softwareheritage/graph/server/App.java --- a/java/src/main/java/org/softwareheritage/graph/server/App.java +++ b/java/src/main/java/org/softwareheritage/graph/server/App.java @@ -34,8 +34,7 @@ "Binding port of the server."), new UnflaggedOption("graphPath", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.REQUIRED, JSAP.NOT_GREEDY, "The basename of the compressed graph."), - new Switch("timings", 't', "timings", "Show timings in API result metadata."), - }); + new Switch("timings", 't', "timings", "Show timings in API result metadata."),}); JSAPResult config = jsap.parse(args); if (jsap.messagePrinted()) { @@ -56,8 +55,7 @@ * @param port binding port of the server * @param showTimings true if timings should be in results metadata, false otherwise */ - private static void startServer(String graphPath, int port, boolean showTimings) - throws IOException { + private static void startServer(String graphPath, int port, boolean showTimings) throws IOException { Graph graph = new Graph(graphPath); Stats stats = new Stats(graphPath); diff --git a/java/src/main/java/org/softwareheritage/graph/server/Endpoint.java b/java/src/main/java/org/softwareheritage/graph/server/Endpoint.java --- a/java/src/main/java/org/softwareheritage/graph/server/Endpoint.java +++ b/java/src/main/java/org/softwareheritage/graph/server/Endpoint.java @@ -27,8 +27,9 @@ * * @param graph the graph used for traversal endpoint * @param direction a string (either "forward" or "backward") specifying edge orientation - * @param edgesFmt a formatted string describing allowed edges + * @param edgesFmt a formatted string describing allowed + * edges */ public Endpoint(Graph graph, String direction, String edgesFmt) { this.graph = graph; @@ -246,8 +247,8 @@ /** Source node of endpoint call specified as a {@link SWHID} */ public SWHID src; /** - * Destination formatted string as described in the API + * Destination formatted string as described in the + * API */ public String dstFmt; /** Traversal algorithm used in endpoint call (either "dfs" or "bfs") */ diff --git a/java/src/main/java/org/softwareheritage/graph/utils/MPHTranslate.java b/java/src/main/java/org/softwareheritage/graph/utils/MPHTranslate.java --- a/java/src/main/java/org/softwareheritage/graph/utils/MPHTranslate.java +++ b/java/src/main/java/org/softwareheritage/graph/utils/MPHTranslate.java @@ -14,14 +14,9 @@ private static JSAPResult parse_args(String[] args) { JSAPResult config = null; try { - SimpleJSAP jsap = new SimpleJSAP( - MPHTranslate.class.getName(), - "", - new Parameter[]{ - new UnflaggedOption("function", JSAP.STRING_PARSER, JSAP.REQUIRED, - "Filename of the serialized MPH"), - } - ); + SimpleJSAP jsap = new SimpleJSAP(MPHTranslate.class.getName(), "", + new Parameter[]{new UnflaggedOption("function", JSAP.STRING_PARSER, JSAP.REQUIRED, + "Filename of the serialized MPH"),}); config = jsap.parse(args); if (jsap.messagePrinted()) { @@ -34,20 +29,17 @@ } @SuppressWarnings("unchecked") // Suppress warning for Object2LongFunction cast - static Object2LongFunction loadMPH(String mphPath) - throws IOException, ClassNotFoundException { + static Object2LongFunction loadMPH(String mphPath) throws IOException, ClassNotFoundException { return (Object2LongFunction) BinIO.loadObject(mphPath); } - public static void main(String[] args) - throws IOException, ClassNotFoundException { + public static void main(String[] args) throws IOException, ClassNotFoundException { JSAPResult config = parse_args(args); String mphPath = config.getString("function"); Object2LongFunction mphMap = loadMPH(mphPath); - FastBufferedReader buffer = new FastBufferedReader( - new InputStreamReader(System.in, StandardCharsets.US_ASCII)); + FastBufferedReader buffer = new FastBufferedReader(new InputStreamReader(System.in, StandardCharsets.US_ASCII)); LineIterator lineIterator = new LineIterator(buffer); while (lineIterator.hasNext()) { diff --git a/java/src/main/java/org/softwareheritage/graph/utils/ReadGraph.java b/java/src/main/java/org/softwareheritage/graph/utils/ReadGraph.java --- a/java/src/main/java/org/softwareheritage/graph/utils/ReadGraph.java +++ b/java/src/main/java/org/softwareheritage/graph/utils/ReadGraph.java @@ -20,13 +20,8 @@ var s = it.successors(); long dstNode; 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)); } } } } - diff --git a/java/src/main/java/org/softwareheritage/graph/utils/ReadLabelledGraph.java b/java/src/main/java/org/softwareheritage/graph/utils/ReadLabelledGraph.java --- a/java/src/main/java/org/softwareheritage/graph/utils/ReadLabelledGraph.java +++ b/java/src/main/java/org/softwareheritage/graph/utils/ReadLabelledGraph.java @@ -15,7 +15,8 @@ ArcLabelledImmutableGraph graph = BitStreamArcLabelledImmutableGraph.loadOffline(graphPath + "-labelled"); NodeIdMap nodeMap = new NodeIdMap(graphPath, graph.numNodes()); - PermutedFrontCodedStringList labelMap = (PermutedFrontCodedStringList) BinIO.loadObject(graphPath + "-labels.fcl"); + PermutedFrontCodedStringList labelMap = (PermutedFrontCodedStringList) BinIO + .loadObject(graphPath + "-labels.fcl"); ArcLabelledNodeIterator it = graph.nodeIterator(); while (it.hasNext()) { @@ -27,22 +28,13 @@ int[] labels = (int[]) s.label().get(); if (labels.length > 0) { for (int label : labels) { - System.out.format( - "%s %s %s\n", - nodeMap.getSWHID(srcNode), - nodeMap.getSWHID(dstNode), - labelMap.get(label) - ); + System.out.format("%s %s %s\n", nodeMap.getSWHID(srcNode), nodeMap.getSWHID(dstNode), + labelMap.get(label)); } } else { - System.out.format( - "%s %s\n", - nodeMap.getSWHID(srcNode), - nodeMap.getSWHID(dstNode) - ); + System.out.format("%s %s\n", nodeMap.getSWHID(srcNode), nodeMap.getSWHID(dstNode)); } } } } } - diff --git a/java/src/test/java/org/softwareheritage/graph/AllowedEdgesTest.java b/java/src/test/java/org/softwareheritage/graph/AllowedEdgesTest.java --- a/java/src/test/java/org/softwareheritage/graph/AllowedEdgesTest.java +++ b/java/src/test/java/org/softwareheritage/graph/AllowedEdgesTest.java @@ -5,7 +5,6 @@ import java.util.ArrayList; - public class AllowedEdgesTest extends GraphTest { static class EdgeType { Node.Type src; @@ -18,8 +17,10 @@ @Override public boolean equals(Object otherObj) { - if (otherObj == this) return true; - if (!(otherObj instanceof EdgeType)) return false; + if (otherObj == this) + return true; + if (!(otherObj instanceof EdgeType)) + return false; EdgeType other = (EdgeType) otherObj; return src == other.src && dst == other.dst; diff --git a/java/src/test/java/org/softwareheritage/graph/VisitTest.java b/java/src/test/java/org/softwareheritage/graph/VisitTest.java --- a/java/src/test/java/org/softwareheritage/graph/VisitTest.java +++ b/java/src/test/java/org/softwareheritage/graph/VisitTest.java @@ -28,97 +28,67 @@ ArrayList nodes = (ArrayList) endpoint2.visitNodes(new Endpoint.Input(swhid)).result; ArrayList expectedPaths = new ArrayList(); - expectedPaths.add( - new SwhPath( - "swh:1:ori:0000000000000000000000000000000000000021", + expectedPaths.add(new SwhPath("swh:1:ori:0000000000000000000000000000000000000021", "swh:1:snp:0000000000000000000000000000000000000020", "swh:1:rev:0000000000000000000000000000000000000009", "swh:1:dir:0000000000000000000000000000000000000008", - "swh:1:cnt:0000000000000000000000000000000000000007" - )); - expectedPaths.add( - new SwhPath( - "swh:1:ori:0000000000000000000000000000000000000021", + "swh:1:cnt:0000000000000000000000000000000000000007")); + expectedPaths.add(new SwhPath("swh:1:ori:0000000000000000000000000000000000000021", "swh:1:snp:0000000000000000000000000000000000000020", "swh:1:rev:0000000000000000000000000000000000000009", "swh:1:dir:0000000000000000000000000000000000000008", - "swh:1:cnt:0000000000000000000000000000000000000001" - )); - expectedPaths.add( - new SwhPath( - "swh:1:ori:0000000000000000000000000000000000000021", + "swh:1:cnt:0000000000000000000000000000000000000001")); + expectedPaths.add(new SwhPath("swh:1:ori:0000000000000000000000000000000000000021", "swh:1:snp:0000000000000000000000000000000000000020", "swh:1:rev:0000000000000000000000000000000000000009", "swh:1:dir:0000000000000000000000000000000000000008", "swh:1:dir:0000000000000000000000000000000000000006", - "swh:1:cnt:0000000000000000000000000000000000000004" - )); - expectedPaths.add( - new SwhPath( - "swh:1:ori:0000000000000000000000000000000000000021", + "swh:1:cnt:0000000000000000000000000000000000000004")); + expectedPaths.add(new SwhPath("swh:1:ori:0000000000000000000000000000000000000021", "swh:1:snp:0000000000000000000000000000000000000020", "swh:1:rev:0000000000000000000000000000000000000009", "swh:1:dir:0000000000000000000000000000000000000008", "swh:1:dir:0000000000000000000000000000000000000006", - "swh:1:cnt:0000000000000000000000000000000000000005" - )); - expectedPaths.add( - new SwhPath( - "swh:1:ori:0000000000000000000000000000000000000021", + "swh:1:cnt:0000000000000000000000000000000000000005")); + expectedPaths.add(new SwhPath("swh:1:ori:0000000000000000000000000000000000000021", "swh:1:snp:0000000000000000000000000000000000000020", "swh:1:rev:0000000000000000000000000000000000000009", "swh:1:rev:0000000000000000000000000000000000000003", "swh:1:dir:0000000000000000000000000000000000000002", - "swh:1:cnt:0000000000000000000000000000000000000001" - )); - expectedPaths.add( - new SwhPath( - "swh:1:ori:0000000000000000000000000000000000000021", + "swh:1:cnt:0000000000000000000000000000000000000001")); + expectedPaths.add(new SwhPath("swh:1:ori:0000000000000000000000000000000000000021", "swh:1:snp:0000000000000000000000000000000000000020", "swh:1:rel:0000000000000000000000000000000000000010", "swh:1:rev:0000000000000000000000000000000000000009", "swh:1:dir:0000000000000000000000000000000000000008", - "swh:1:cnt:0000000000000000000000000000000000000007" - )); - expectedPaths.add( - new SwhPath( - "swh:1:ori:0000000000000000000000000000000000000021", + "swh:1:cnt:0000000000000000000000000000000000000007")); + expectedPaths.add(new SwhPath("swh:1:ori:0000000000000000000000000000000000000021", "swh:1:snp:0000000000000000000000000000000000000020", "swh:1:rel:0000000000000000000000000000000000000010", "swh:1:rev:0000000000000000000000000000000000000009", "swh:1:dir:0000000000000000000000000000000000000008", - "swh:1:cnt:0000000000000000000000000000000000000001" - )); - expectedPaths.add( - new SwhPath( - "swh:1:ori:0000000000000000000000000000000000000021", + "swh:1:cnt:0000000000000000000000000000000000000001")); + expectedPaths.add(new SwhPath("swh:1:ori:0000000000000000000000000000000000000021", "swh:1:snp:0000000000000000000000000000000000000020", "swh:1:rel:0000000000000000000000000000000000000010", "swh:1:rev:0000000000000000000000000000000000000009", "swh:1:dir:0000000000000000000000000000000000000008", "swh:1:dir:0000000000000000000000000000000000000006", - "swh:1:cnt:0000000000000000000000000000000000000004" - )); - expectedPaths.add( - new SwhPath( - "swh:1:ori:0000000000000000000000000000000000000021", + "swh:1:cnt:0000000000000000000000000000000000000004")); + expectedPaths.add(new SwhPath("swh:1:ori:0000000000000000000000000000000000000021", "swh:1:snp:0000000000000000000000000000000000000020", "swh:1:rel:0000000000000000000000000000000000000010", "swh:1:rev:0000000000000000000000000000000000000009", "swh:1:dir:0000000000000000000000000000000000000008", "swh:1:dir:0000000000000000000000000000000000000006", - "swh:1:cnt:0000000000000000000000000000000000000005" - )); - expectedPaths.add( - new SwhPath( - "swh:1:ori:0000000000000000000000000000000000000021", + "swh:1:cnt:0000000000000000000000000000000000000005")); + expectedPaths.add(new SwhPath("swh:1:ori:0000000000000000000000000000000000000021", "swh:1:snp:0000000000000000000000000000000000000020", "swh:1:rel:0000000000000000000000000000000000000010", "swh:1:rev:0000000000000000000000000000000000000009", "swh:1:rev:0000000000000000000000000000000000000003", "swh:1:dir:0000000000000000000000000000000000000002", - "swh:1:cnt:0000000000000000000000000000000000000001" - )); + "swh:1:cnt:0000000000000000000000000000000000000001")); GraphTest.assertEqualsAnyOrder(expectedPaths, paths); assertSameNodesFromPaths(expectedPaths, nodes); @@ -134,37 +104,22 @@ ArrayList nodes = (ArrayList) endpoint2.visitNodes(new Endpoint.Input(swhid)).result; ArrayList expectedPaths = new ArrayList(); - expectedPaths.add( - new SwhPath( - "swh:1:dir:0000000000000000000000000000000000000012", + expectedPaths.add(new SwhPath("swh:1:dir:0000000000000000000000000000000000000012", "swh:1:dir:0000000000000000000000000000000000000008", - "swh:1:cnt:0000000000000000000000000000000000000007" - )); - expectedPaths.add( - new SwhPath( - "swh:1:dir:0000000000000000000000000000000000000012", + "swh:1:cnt:0000000000000000000000000000000000000007")); + expectedPaths.add(new SwhPath("swh:1:dir:0000000000000000000000000000000000000012", "swh:1:dir:0000000000000000000000000000000000000008", - "swh:1:cnt:0000000000000000000000000000000000000001" - )); - expectedPaths.add( - new SwhPath( - "swh:1:dir:0000000000000000000000000000000000000012", + "swh:1:cnt:0000000000000000000000000000000000000001")); + expectedPaths.add(new SwhPath("swh:1:dir:0000000000000000000000000000000000000012", "swh:1:dir:0000000000000000000000000000000000000008", "swh:1:dir:0000000000000000000000000000000000000006", - "swh:1:cnt:0000000000000000000000000000000000000004" - )); - expectedPaths.add( - new SwhPath( - "swh:1:dir:0000000000000000000000000000000000000012", + "swh:1:cnt:0000000000000000000000000000000000000004")); + expectedPaths.add(new SwhPath("swh:1:dir:0000000000000000000000000000000000000012", "swh:1:dir:0000000000000000000000000000000000000008", "swh:1:dir:0000000000000000000000000000000000000006", - "swh:1:cnt:0000000000000000000000000000000000000005" - )); - expectedPaths.add( - new SwhPath( - "swh:1:dir:0000000000000000000000000000000000000012", - "swh:1:cnt:0000000000000000000000000000000000000011" - )); + "swh:1:cnt:0000000000000000000000000000000000000005")); + expectedPaths.add(new SwhPath("swh:1:dir:0000000000000000000000000000000000000012", + "swh:1:cnt:0000000000000000000000000000000000000011")); GraphTest.assertEqualsAnyOrder(expectedPaths, paths); assertSameNodesFromPaths(expectedPaths, nodes); @@ -180,10 +135,7 @@ ArrayList nodes = (ArrayList) endpoint2.visitNodes(new Endpoint.Input(swhid)).result; ArrayList expectedPaths = new ArrayList(); - expectedPaths.add( - new SwhPath( - "swh:1:cnt:0000000000000000000000000000000000000004" - )); + expectedPaths.add(new SwhPath("swh:1:cnt:0000000000000000000000000000000000000004")); GraphTest.assertEqualsAnyOrder(expectedPaths, paths); assertSameNodesFromPaths(expectedPaths, nodes); @@ -199,10 +151,7 @@ ArrayList nodes = (ArrayList) endpoint2.visitNodes(new Endpoint.Input(swhid)).result; ArrayList expectedPaths = new ArrayList(); - expectedPaths.add( - new SwhPath( - "swh:1:ori:0000000000000000000000000000000000000021" - )); + expectedPaths.add(new SwhPath("swh:1:ori:0000000000000000000000000000000000000021")); GraphTest.assertEqualsAnyOrder(expectedPaths, paths); assertSameNodesFromPaths(expectedPaths, nodes); @@ -218,13 +167,10 @@ ArrayList nodes = (ArrayList) endpoint2.visitNodes(new Endpoint.Input(swhid)).result; ArrayList expectedPaths = new ArrayList(); - expectedPaths.add( - new SwhPath( - "swh:1:dir:0000000000000000000000000000000000000012", + expectedPaths.add(new SwhPath("swh:1:dir:0000000000000000000000000000000000000012", "swh:1:rev:0000000000000000000000000000000000000013", "swh:1:rev:0000000000000000000000000000000000000018", - "swh:1:rel:0000000000000000000000000000000000000019" - )); + "swh:1:rel:0000000000000000000000000000000000000019")); GraphTest.assertEqualsAnyOrder(expectedPaths, paths); assertSameNodesFromPaths(expectedPaths, nodes); @@ -240,45 +186,33 @@ ArrayList nodes = (ArrayList) endpoint2.visitNodes(new Endpoint.Input(swhid)).result; ArrayList expectedPaths = new ArrayList(); - expectedPaths.add( - new SwhPath( - "swh:1:cnt:0000000000000000000000000000000000000004", + expectedPaths.add(new SwhPath("swh:1:cnt:0000000000000000000000000000000000000004", "swh:1:dir:0000000000000000000000000000000000000006", "swh:1:dir:0000000000000000000000000000000000000008", "swh:1:dir:0000000000000000000000000000000000000012", "swh:1:rev:0000000000000000000000000000000000000013", "swh:1:rev:0000000000000000000000000000000000000018", - "swh:1:rel:0000000000000000000000000000000000000019" - )); - expectedPaths.add( - new SwhPath( - "swh:1:cnt:0000000000000000000000000000000000000004", + "swh:1:rel:0000000000000000000000000000000000000019")); + expectedPaths.add(new SwhPath("swh:1:cnt:0000000000000000000000000000000000000004", "swh:1:dir:0000000000000000000000000000000000000006", "swh:1:dir:0000000000000000000000000000000000000008", "swh:1:rev:0000000000000000000000000000000000000009", "swh:1:rev:0000000000000000000000000000000000000013", "swh:1:rev:0000000000000000000000000000000000000018", - "swh:1:rel:0000000000000000000000000000000000000019" - )); - expectedPaths.add( - new SwhPath( - "swh:1:cnt:0000000000000000000000000000000000000004", + "swh:1:rel:0000000000000000000000000000000000000019")); + expectedPaths.add(new SwhPath("swh:1:cnt:0000000000000000000000000000000000000004", "swh:1:dir:0000000000000000000000000000000000000006", "swh:1:dir:0000000000000000000000000000000000000008", "swh:1:rev:0000000000000000000000000000000000000009", "swh:1:snp:0000000000000000000000000000000000000020", - "swh:1:ori:0000000000000000000000000000000000000021" - )); - expectedPaths.add( - new SwhPath( - "swh:1:cnt:0000000000000000000000000000000000000004", + "swh:1:ori:0000000000000000000000000000000000000021")); + expectedPaths.add(new SwhPath("swh:1:cnt:0000000000000000000000000000000000000004", "swh:1:dir:0000000000000000000000000000000000000006", "swh:1:dir:0000000000000000000000000000000000000008", "swh:1:rev:0000000000000000000000000000000000000009", "swh:1:rel:0000000000000000000000000000000000000010", "swh:1:snp:0000000000000000000000000000000000000020", - "swh:1:ori:0000000000000000000000000000000000000021" - )); + "swh:1:ori:0000000000000000000000000000000000000021")); GraphTest.assertEqualsAnyOrder(expectedPaths, paths); assertSameNodesFromPaths(expectedPaths, nodes); @@ -294,11 +228,8 @@ ArrayList nodes = (ArrayList) endpoint2.visitNodes(new Endpoint.Input(swhid)).result; ArrayList expectedPaths = new ArrayList(); - expectedPaths.add( - new SwhPath( - "swh:1:snp:0000000000000000000000000000000000000020", - "swh:1:rev:0000000000000000000000000000000000000009" - )); + expectedPaths.add(new SwhPath("swh:1:snp:0000000000000000000000000000000000000020", + "swh:1:rev:0000000000000000000000000000000000000009")); GraphTest.assertEqualsAnyOrder(expectedPaths, paths); assertSameNodesFromPaths(expectedPaths, nodes); @@ -314,12 +245,9 @@ ArrayList nodes = (ArrayList) endpoint2.visitNodes(new Endpoint.Input(swhid)).result; ArrayList expectedPaths = new ArrayList(); - expectedPaths.add( - new SwhPath( - "swh:1:rel:0000000000000000000000000000000000000010", + expectedPaths.add(new SwhPath("swh:1:rel:0000000000000000000000000000000000000010", "swh:1:rev:0000000000000000000000000000000000000009", - "swh:1:rev:0000000000000000000000000000000000000003" - )); + "swh:1:rev:0000000000000000000000000000000000000003")); GraphTest.assertEqualsAnyOrder(expectedPaths, paths); assertSameNodesFromPaths(expectedPaths, nodes); @@ -335,80 +263,50 @@ ArrayList nodes = (ArrayList) endpoint2.visitNodes(new Endpoint.Input(swhid)).result; ArrayList expectedPaths = new ArrayList(); - expectedPaths.add( - new SwhPath( - "swh:1:rev:0000000000000000000000000000000000000013", + expectedPaths.add(new SwhPath("swh:1:rev:0000000000000000000000000000000000000013", "swh:1:rev:0000000000000000000000000000000000000009", "swh:1:dir:0000000000000000000000000000000000000008", "swh:1:dir:0000000000000000000000000000000000000006", - "swh:1:cnt:0000000000000000000000000000000000000005" - )); - expectedPaths.add( - new SwhPath( - "swh:1:rev:0000000000000000000000000000000000000013", + "swh:1:cnt:0000000000000000000000000000000000000005")); + expectedPaths.add(new SwhPath("swh:1:rev:0000000000000000000000000000000000000013", "swh:1:dir:0000000000000000000000000000000000000012", "swh:1:dir:0000000000000000000000000000000000000008", "swh:1:dir:0000000000000000000000000000000000000006", - "swh:1:cnt:0000000000000000000000000000000000000005" - )); - expectedPaths.add( - new SwhPath( - "swh:1:rev:0000000000000000000000000000000000000013", + "swh:1:cnt:0000000000000000000000000000000000000005")); + expectedPaths.add(new SwhPath("swh:1:rev:0000000000000000000000000000000000000013", "swh:1:rev:0000000000000000000000000000000000000009", "swh:1:dir:0000000000000000000000000000000000000008", "swh:1:dir:0000000000000000000000000000000000000006", - "swh:1:cnt:0000000000000000000000000000000000000004" - )); - expectedPaths.add( - new SwhPath( - "swh:1:rev:0000000000000000000000000000000000000013", + "swh:1:cnt:0000000000000000000000000000000000000004")); + expectedPaths.add(new SwhPath("swh:1:rev:0000000000000000000000000000000000000013", "swh:1:dir:0000000000000000000000000000000000000012", "swh:1:dir:0000000000000000000000000000000000000008", "swh:1:dir:0000000000000000000000000000000000000006", - "swh:1:cnt:0000000000000000000000000000000000000004" - )); - expectedPaths.add( - new SwhPath( - "swh:1:rev:0000000000000000000000000000000000000013", + "swh:1:cnt:0000000000000000000000000000000000000004")); + expectedPaths.add(new SwhPath("swh:1:rev:0000000000000000000000000000000000000013", "swh:1:rev:0000000000000000000000000000000000000009", "swh:1:dir:0000000000000000000000000000000000000008", - "swh:1:cnt:0000000000000000000000000000000000000007" - )); - expectedPaths.add( - new SwhPath( - "swh:1:rev:0000000000000000000000000000000000000013", + "swh:1:cnt:0000000000000000000000000000000000000007")); + expectedPaths.add(new SwhPath("swh:1:rev:0000000000000000000000000000000000000013", "swh:1:dir:0000000000000000000000000000000000000012", "swh:1:dir:0000000000000000000000000000000000000008", - "swh:1:cnt:0000000000000000000000000000000000000007" - )); - expectedPaths.add( - new SwhPath( - "swh:1:rev:0000000000000000000000000000000000000013", + "swh:1:cnt:0000000000000000000000000000000000000007")); + expectedPaths.add(new SwhPath("swh:1:rev:0000000000000000000000000000000000000013", "swh:1:dir:0000000000000000000000000000000000000012", - "swh:1:cnt:0000000000000000000000000000000000000011" - )); - expectedPaths.add( - new SwhPath( - "swh:1:rev:0000000000000000000000000000000000000013", + "swh:1:cnt:0000000000000000000000000000000000000011")); + expectedPaths.add(new SwhPath("swh:1:rev:0000000000000000000000000000000000000013", "swh:1:rev:0000000000000000000000000000000000000009", "swh:1:rev:0000000000000000000000000000000000000003", "swh:1:dir:0000000000000000000000000000000000000002", - "swh:1:cnt:0000000000000000000000000000000000000001" - )); - expectedPaths.add( - new SwhPath( - "swh:1:rev:0000000000000000000000000000000000000013", + "swh:1:cnt:0000000000000000000000000000000000000001")); + expectedPaths.add(new SwhPath("swh:1:rev:0000000000000000000000000000000000000013", "swh:1:rev:0000000000000000000000000000000000000009", "swh:1:dir:0000000000000000000000000000000000000008", - "swh:1:cnt:0000000000000000000000000000000000000001" - )); - expectedPaths.add( - new SwhPath( - "swh:1:rev:0000000000000000000000000000000000000013", + "swh:1:cnt:0000000000000000000000000000000000000001")); + expectedPaths.add(new SwhPath("swh:1:rev:0000000000000000000000000000000000000013", "swh:1:dir:0000000000000000000000000000000000000012", "swh:1:dir:0000000000000000000000000000000000000008", - "swh:1:cnt:0000000000000000000000000000000000000001" - )); + "swh:1:cnt:0000000000000000000000000000000000000001")); GraphTest.assertEqualsAnyOrder(expectedPaths, paths); assertSameNodesFromPaths(expectedPaths, nodes); @@ -424,24 +322,15 @@ ArrayList nodes = (ArrayList) endpoint2.visitNodes(new Endpoint.Input(swhid)).result; ArrayList expectedPaths = new ArrayList(); - expectedPaths.add( - new SwhPath( - "swh:1:snp:0000000000000000000000000000000000000020", + expectedPaths.add(new SwhPath("swh:1:snp:0000000000000000000000000000000000000020", "swh:1:rev:0000000000000000000000000000000000000009", "swh:1:rev:0000000000000000000000000000000000000003", - "swh:1:dir:0000000000000000000000000000000000000002" - )); - expectedPaths.add( - new SwhPath( - "swh:1:snp:0000000000000000000000000000000000000020", + "swh:1:dir:0000000000000000000000000000000000000002")); + expectedPaths.add(new SwhPath("swh:1:snp:0000000000000000000000000000000000000020", "swh:1:rev:0000000000000000000000000000000000000009", - "swh:1:dir:0000000000000000000000000000000000000008" - )); - expectedPaths.add( - new SwhPath( - "swh:1:snp:0000000000000000000000000000000000000020", - "swh:1:rel:0000000000000000000000000000000000000010" - )); + "swh:1:dir:0000000000000000000000000000000000000008")); + expectedPaths.add(new SwhPath("swh:1:snp:0000000000000000000000000000000000000020", + "swh:1:rel:0000000000000000000000000000000000000010")); GraphTest.assertEqualsAnyOrder(expectedPaths, paths); assertSameNodesFromPaths(expectedPaths, nodes); @@ -457,10 +346,7 @@ ArrayList nodes = (ArrayList) endpoint2.visitNodes(new Endpoint.Input(swhid)).result; ArrayList expectedPaths = new ArrayList(); - expectedPaths.add( - new SwhPath( - "swh:1:snp:0000000000000000000000000000000000000020" - )); + expectedPaths.add(new SwhPath("swh:1:snp:0000000000000000000000000000000000000020")); GraphTest.assertEqualsAnyOrder(expectedPaths, paths); assertSameNodesFromPaths(expectedPaths, nodes); @@ -476,20 +362,14 @@ ArrayList nodes = (ArrayList) endpoint2.visitNodes(new Endpoint.Input(swhid)).result; ArrayList expectedPaths = new ArrayList(); - expectedPaths.add( - new SwhPath( - "swh:1:rev:0000000000000000000000000000000000000003", + expectedPaths.add(new SwhPath("swh:1:rev:0000000000000000000000000000000000000003", "swh:1:rev:0000000000000000000000000000000000000009", "swh:1:rev:0000000000000000000000000000000000000013", "swh:1:rev:0000000000000000000000000000000000000018", - "swh:1:rel:0000000000000000000000000000000000000019" - )); - expectedPaths.add( - new SwhPath( - "swh:1:rev:0000000000000000000000000000000000000003", + "swh:1:rel:0000000000000000000000000000000000000019")); + expectedPaths.add(new SwhPath("swh:1:rev:0000000000000000000000000000000000000003", "swh:1:rev:0000000000000000000000000000000000000009", - "swh:1:rel:0000000000000000000000000000000000000010" - )); + "swh:1:rel:0000000000000000000000000000000000000010")); GraphTest.assertEqualsAnyOrder(expectedPaths, paths); assertSameNodesFromPaths(expectedPaths, nodes); diff --git a/java/src/test/java/org/softwareheritage/graph/WalkTest.java b/java/src/test/java/org/softwareheritage/graph/WalkTest.java --- a/java/src/test/java/org/softwareheritage/graph/WalkTest.java +++ b/java/src/test/java/org/softwareheritage/graph/WalkTest.java @@ -14,23 +14,17 @@ SWHID src = new SWHID("swh:1:snp:0000000000000000000000000000000000000020"); String dstFmt = "swh:1:cnt:0000000000000000000000000000000000000005"; - SwhPath solution1 = - new SwhPath( - "swh:1:snp:0000000000000000000000000000000000000020", - "swh:1:rev:0000000000000000000000000000000000000009", - "swh:1:dir:0000000000000000000000000000000000000008", - "swh:1:dir:0000000000000000000000000000000000000006", - "swh:1:cnt:0000000000000000000000000000000000000005" - ); - SwhPath solution2 = - new SwhPath( - "swh:1:snp:0000000000000000000000000000000000000020", - "swh:1:rel:0000000000000000000000000000000000000010", - "swh:1:rev:0000000000000000000000000000000000000009", - "swh:1:dir:0000000000000000000000000000000000000008", - "swh:1:dir:0000000000000000000000000000000000000006", - "swh:1:cnt:0000000000000000000000000000000000000005" - ); + SwhPath solution1 = new SwhPath("swh:1:snp:0000000000000000000000000000000000000020", + "swh:1:rev:0000000000000000000000000000000000000009", + "swh:1:dir:0000000000000000000000000000000000000008", + "swh:1:dir:0000000000000000000000000000000000000006", + "swh:1:cnt:0000000000000000000000000000000000000005"); + SwhPath solution2 = new SwhPath("swh:1:snp:0000000000000000000000000000000000000020", + "swh:1:rel:0000000000000000000000000000000000000010", + "swh:1:rev:0000000000000000000000000000000000000009", + "swh:1:dir:0000000000000000000000000000000000000008", + "swh:1:dir:0000000000000000000000000000000000000006", + "swh:1:cnt:0000000000000000000000000000000000000005"); Endpoint endpoint1 = new Endpoint(graph, "forward", "*"); SwhPath dfsPath = (SwhPath) endpoint1.walk(new Endpoint.Input(src, dstFmt, "dfs")).result; @@ -48,10 +42,7 @@ SWHID src = new SWHID("swh:1:cnt:0000000000000000000000000000000000000007"); String dstFmt = "cnt"; - SwhPath expectedPath = - new SwhPath( - "swh:1:cnt:0000000000000000000000000000000000000007" - ); + SwhPath expectedPath = new SwhPath("swh:1:cnt:0000000000000000000000000000000000000007"); Endpoint endpoint1 = new Endpoint(graph, "forward", "*"); SwhPath dfsPath = (SwhPath) endpoint1.walk(new Endpoint.Input(src, dstFmt, "dfs")).result; @@ -68,13 +59,10 @@ SWHID src = new SWHID("swh:1:rev:0000000000000000000000000000000000000018"); String dstFmt = "swh:1:rev:0000000000000000000000000000000000000003"; - SwhPath expectedPath = - new SwhPath( - "swh:1:rev:0000000000000000000000000000000000000018", - "swh:1:rev:0000000000000000000000000000000000000013", - "swh:1:rev:0000000000000000000000000000000000000009", - "swh:1:rev:0000000000000000000000000000000000000003" - ); + SwhPath expectedPath = new SwhPath("swh:1:rev:0000000000000000000000000000000000000018", + "swh:1:rev:0000000000000000000000000000000000000013", + "swh:1:rev:0000000000000000000000000000000000000009", + "swh:1:rev:0000000000000000000000000000000000000003"); Endpoint endpoint1 = new Endpoint(graph, "forward", "rev:rev"); SwhPath dfsPath = (SwhPath) endpoint1.walk(new Endpoint.Input(src, dstFmt, "dfs")).result; @@ -91,13 +79,10 @@ SWHID src = new SWHID("swh:1:rev:0000000000000000000000000000000000000003"); String dstFmt = "swh:1:rev:0000000000000000000000000000000000000018"; - SwhPath expectedPath = - new SwhPath( - "swh:1:rev:0000000000000000000000000000000000000003", - "swh:1:rev:0000000000000000000000000000000000000009", - "swh:1:rev:0000000000000000000000000000000000000013", - "swh:1:rev:0000000000000000000000000000000000000018" - ); + SwhPath expectedPath = new SwhPath("swh:1:rev:0000000000000000000000000000000000000003", + "swh:1:rev:0000000000000000000000000000000000000009", + "swh:1:rev:0000000000000000000000000000000000000013", + "swh:1:rev:0000000000000000000000000000000000000018"); Endpoint endpoint1 = new Endpoint(graph, "backward", "rev:rev"); SwhPath dfsPath = (SwhPath) endpoint1.walk(new Endpoint.Input(src, dstFmt, "dfs")).result; @@ -114,38 +99,26 @@ SWHID src = new SWHID("swh:1:cnt:0000000000000000000000000000000000000001"); String dstFmt = "snp"; - SwhPath solution1 = - new SwhPath( - "swh:1:cnt:0000000000000000000000000000000000000001", - "swh:1:dir:0000000000000000000000000000000000000002", - "swh:1:rev:0000000000000000000000000000000000000003", - "swh:1:rev:0000000000000000000000000000000000000009", - "swh:1:snp:0000000000000000000000000000000000000020" - ); - SwhPath solution2 = - new SwhPath( - "swh:1:cnt:0000000000000000000000000000000000000001", - "swh:1:dir:0000000000000000000000000000000000000002", - "swh:1:rev:0000000000000000000000000000000000000003", - "swh:1:rev:0000000000000000000000000000000000000009", - "swh:1:rel:0000000000000000000000000000000000000010", - "swh:1:snp:0000000000000000000000000000000000000020" - ); - SwhPath solution3 = - new SwhPath( - "swh:1:cnt:0000000000000000000000000000000000000001", - "swh:1:dir:0000000000000000000000000000000000000008", - "swh:1:rev:0000000000000000000000000000000000000009", - "swh:1:snp:0000000000000000000000000000000000000020" - ); - SwhPath solution4 = - new SwhPath( - "swh:1:cnt:0000000000000000000000000000000000000001", - "swh:1:dir:0000000000000000000000000000000000000008", - "swh:1:rev:0000000000000000000000000000000000000009", - "swh:1:rel:0000000000000000000000000000000000000010", - "swh:1:snp:0000000000000000000000000000000000000020" - ); + SwhPath solution1 = new SwhPath("swh:1:cnt:0000000000000000000000000000000000000001", + "swh:1:dir:0000000000000000000000000000000000000002", + "swh:1:rev:0000000000000000000000000000000000000003", + "swh:1:rev:0000000000000000000000000000000000000009", + "swh:1:snp:0000000000000000000000000000000000000020"); + SwhPath solution2 = new SwhPath("swh:1:cnt:0000000000000000000000000000000000000001", + "swh:1:dir:0000000000000000000000000000000000000002", + "swh:1:rev:0000000000000000000000000000000000000003", + "swh:1:rev:0000000000000000000000000000000000000009", + "swh:1:rel:0000000000000000000000000000000000000010", + "swh:1:snp:0000000000000000000000000000000000000020"); + SwhPath solution3 = new SwhPath("swh:1:cnt:0000000000000000000000000000000000000001", + "swh:1:dir:0000000000000000000000000000000000000008", + "swh:1:rev:0000000000000000000000000000000000000009", + "swh:1:snp:0000000000000000000000000000000000000020"); + SwhPath solution4 = new SwhPath("swh:1:cnt:0000000000000000000000000000000000000001", + "swh:1:dir:0000000000000000000000000000000000000008", + "swh:1:rev:0000000000000000000000000000000000000009", + "swh:1:rel:0000000000000000000000000000000000000010", + "swh:1:snp:0000000000000000000000000000000000000020"); Endpoint endpoint1 = new Endpoint(graph, "backward", "*"); SwhPath dfsPath = (SwhPath) endpoint1.walk(new Endpoint.Input(src, dstFmt, "dfs")).result; @@ -163,47 +136,31 @@ SWHID src = new SWHID("swh:1:rev:0000000000000000000000000000000000000009"); String dstFmt = "cnt"; - SwhPath solution1 = - new SwhPath( - "swh:1:rev:0000000000000000000000000000000000000009", - "swh:1:dir:0000000000000000000000000000000000000008", - "swh:1:cnt:0000000000000000000000000000000000000007" - ); - SwhPath solution2 = - new SwhPath( - "swh:1:rev:0000000000000000000000000000000000000009", - "swh:1:dir:0000000000000000000000000000000000000008", - "swh:1:dir:0000000000000000000000000000000000000006", - "swh:1:cnt:0000000000000000000000000000000000000005" - ); - SwhPath solution3 = - new SwhPath( - "swh:1:rev:0000000000000000000000000000000000000009", - "swh:1:dir:0000000000000000000000000000000000000008", - "swh:1:dir:0000000000000000000000000000000000000006", - "swh:1:cnt:0000000000000000000000000000000000000004" - ); - SwhPath solution4 = - new SwhPath( - "swh:1:rev:0000000000000000000000000000000000000009", - "swh:1:dir:0000000000000000000000000000000000000008", - "swh:1:cnt:0000000000000000000000000000000000000001" - ); - SwhPath solution5 = - new SwhPath( - "swh:1:rev:0000000000000000000000000000000000000009", - "swh:1:rev:0000000000000000000000000000000000000003", - "swh:1:dir:0000000000000000000000000000000000000002", - "swh:1:cnt:0000000000000000000000000000000000000001" - ); + SwhPath solution1 = new SwhPath("swh:1:rev:0000000000000000000000000000000000000009", + "swh:1:dir:0000000000000000000000000000000000000008", + "swh:1:cnt:0000000000000000000000000000000000000007"); + SwhPath solution2 = new SwhPath("swh:1:rev:0000000000000000000000000000000000000009", + "swh:1:dir:0000000000000000000000000000000000000008", + "swh:1:dir:0000000000000000000000000000000000000006", + "swh:1:cnt:0000000000000000000000000000000000000005"); + SwhPath solution3 = new SwhPath("swh:1:rev:0000000000000000000000000000000000000009", + "swh:1:dir:0000000000000000000000000000000000000008", + "swh:1:dir:0000000000000000000000000000000000000006", + "swh:1:cnt:0000000000000000000000000000000000000004"); + SwhPath solution4 = new SwhPath("swh:1:rev:0000000000000000000000000000000000000009", + "swh:1:dir:0000000000000000000000000000000000000008", + "swh:1:cnt:0000000000000000000000000000000000000001"); + SwhPath solution5 = new SwhPath("swh:1:rev:0000000000000000000000000000000000000009", + "swh:1:rev:0000000000000000000000000000000000000003", + "swh:1:dir:0000000000000000000000000000000000000002", + "swh:1:cnt:0000000000000000000000000000000000000001"); Endpoint endpoint1 = new Endpoint(graph, "forward", "rev:*,dir:*"); SwhPath dfsPath = (SwhPath) endpoint1.walk(new Endpoint.Input(src, dstFmt, "dfs")).result; Endpoint endpoint2 = new Endpoint(graph, "forward", "rev:*,dir:*"); SwhPath bfsPath = (SwhPath) endpoint2.walk(new Endpoint.Input(src, dstFmt, "bfs")).result; - List possibleSolutions = - Arrays.asList(solution1, solution2, solution3, solution4, solution5); + List possibleSolutions = Arrays.asList(solution1, solution2, solution3, solution4, solution5); Assertions.assertTrue(possibleSolutions.contains(dfsPath)); Assertions.assertTrue(possibleSolutions.contains(bfsPath)); } @@ -214,13 +171,10 @@ SWHID src = new SWHID("swh:1:dir:0000000000000000000000000000000000000016"); String dstFmt = "rel"; - SwhPath expectedPath = - new SwhPath( - "swh:1:dir:0000000000000000000000000000000000000016", - "swh:1:dir:0000000000000000000000000000000000000017", - "swh:1:rev:0000000000000000000000000000000000000018", - "swh:1:rel:0000000000000000000000000000000000000019" - ); + SwhPath expectedPath = new SwhPath("swh:1:dir:0000000000000000000000000000000000000016", + "swh:1:dir:0000000000000000000000000000000000000017", + "swh:1:rev:0000000000000000000000000000000000000018", + "swh:1:rel:0000000000000000000000000000000000000019"); Endpoint endpoint1 = new Endpoint(graph, "backward", "dir:dir,dir:rev,rev:*"); SwhPath dfsPath = (SwhPath) endpoint1.walk(new Endpoint.Input(src, dstFmt, "dfs")).result;