diff --git a/java/src/main/java/org/softwareheritage/graph/Subgraph.java b/java/src/main/java/org/softwareheritage/graph/Subgraph.java index 9cafc0bb7ad932885008ab3611fc6ee8c0b2c3c2..90ee60c95655335174b0ebae3563216b9cf6323b 100644 --- a/java/src/main/java/org/softwareheritage/graph/Subgraph.java +++ b/java/src/main/java/org/softwareheritage/graph/Subgraph.java @@ -196,6 +196,28 @@ public class Subgraph extends ImmutableGraph { return this.transpose().outdegree(nodeId); } + /** + * Converts SWHID node to long. + * + * @param swhid node specified as a <code>byte[]</code> + * @return internal long node id + * @see SWHID + */ + public long getNodeId(byte[] swhid) { + return underlyingGraph.getNodeId(swhid); + } + + /** + * Converts SWHID node to long. + * + * @param swhid node specified as a <code>String</code> + * @return internal long node id + * @see SWHID + */ + public long getNodeId(String swhid) { + return underlyingGraph.getNodeId(swhid); + } + /** * Converts {@link SWHID} node to long. * diff --git a/java/src/main/java/org/softwareheritage/graph/SwhGraph.java b/java/src/main/java/org/softwareheritage/graph/SwhGraph.java index d95bc732c809e5454f4957595abc9d3ee7fe214d..556d9edb64b6e0c54ab98be766739e6da823de89 100644 --- a/java/src/main/java/org/softwareheritage/graph/SwhGraph.java +++ b/java/src/main/java/org/softwareheritage/graph/SwhGraph.java @@ -34,6 +34,16 @@ public interface SwhGraph { return getProperties().getPath(); } + /** @see SwhGraphProperties#getNodeId(byte[]) */ + default long getNodeId(byte[] swhid) { + return getProperties().getNodeId(swhid); + } + + /** @see SwhGraphProperties#getNodeId(String) */ + default long getNodeId(String swhid) { + return getProperties().getNodeId(swhid); + } + /** @see SwhGraphProperties#getNodeId(SWHID) */ default long getNodeId(SWHID swhid) { return getProperties().getNodeId(swhid); diff --git a/java/src/main/java/org/softwareheritage/graph/SwhGraphProperties.java b/java/src/main/java/org/softwareheritage/graph/SwhGraphProperties.java index 064a7df3bada896db72885319df15e7a4668c9e2..af6adffafeaa4a78675488865bcbdd92bc002a8c 100644 --- a/java/src/main/java/org/softwareheritage/graph/SwhGraphProperties.java +++ b/java/src/main/java/org/softwareheritage/graph/SwhGraphProperties.java @@ -84,6 +84,28 @@ public class SwhGraphProperties { return path; } + /** + * Converts SWHID node to long. + * + * @param swhid node specified as a <code>byte[]</code> + * @return internal long node id + * @see SWHID + */ + public long getNodeId(byte[] swhid) { + return nodeIdMap.getNodeId(swhid); + } + + /** + * Converts SWHID node to long. + * + * @param swhid node specified as a <code>String</code> + * @return internal long node id + * @see SWHID + */ + public long getNodeId(String swhid) { + return nodeIdMap.getNodeId(swhid); + } + /** * Converts {@link SWHID} node to long. * diff --git a/java/src/main/java/org/softwareheritage/graph/maps/NodeIdMap.java b/java/src/main/java/org/softwareheritage/graph/maps/NodeIdMap.java index 406e26f2e7d79d724c4860291d7e90e74d0ec55a..786277fa51bb7e50038f76231d1182281aeea052 100644 --- a/java/src/main/java/org/softwareheritage/graph/maps/NodeIdMap.java +++ b/java/src/main/java/org/softwareheritage/graph/maps/NodeIdMap.java @@ -147,6 +147,17 @@ public class NodeIdMap implements Size64 { return this.orderMap.getLong(origNodeId); } + /** + * Converts String-form SWHID to corresponding long node id. Low-level function, does not check if + * the SWHID is valid. + * + * @param swhid node represented as String + * @return corresponding node as a long id + */ + public long getNodeId(String swhid) { + return getNodeId(swhid.getBytes(StandardCharsets.US_ASCII)); + } + /** * Converts SWHID to corresponding long node id. * diff --git a/java/src/main/java/org/softwareheritage/graph/utils/CountPaths.java b/java/src/main/java/org/softwareheritage/graph/utils/CountPaths.java index 0f0162b9389ff072eb6e0e2e3ee5734becc3661e..a59f8232a238bc975d6ab03596fbd9a5b9d31e06 100644 --- a/java/src/main/java/org/softwareheritage/graph/utils/CountPaths.java +++ b/java/src/main/java/org/softwareheritage/graph/utils/CountPaths.java @@ -98,8 +98,7 @@ public class CountPaths { while (stdin.hasNextLine()) { pl.lightUpdate(); String cells[] = stdin.nextLine().strip().split(",", -1); - SWHID nodeSWHID = new SWHID(cells[0]); - long nodeId = graph.getNodeId(nodeSWHID); + long nodeId = graph.getNodeId(cells[0]); long countFromRoots = countsFromRoots.getLong(nodeId); long countFromAll = countsFromAll.getLong(nodeId);