Skip to content

Commit 42e29d5

Browse files
jjaderbergIoannisPanagiotas
authored andcommitted
Make some fields final
1 parent af01a29 commit 42e29d5

File tree

4 files changed

+13
-13
lines changed

4 files changed

+13
-13
lines changed

algo/src/main/java/org/neo4j/gds/steiner/ShortestPathsSteinerAlgorithm.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@
3939

4040
public class ShortestPathsSteinerAlgorithm extends Algorithm<SteinerTreeResult> {
4141

42-
public static long ROOTNODE = -1;
43-
public static long PRUNED = -2;
42+
public static final long ROOT_NODE = -1;
43+
public static final long PRUNED = -2;
4444
private final Graph graph;
4545
private final long sourceId;
4646
private final List<Long> terminals;
@@ -49,7 +49,7 @@ public class ShortestPathsSteinerAlgorithm extends Algorithm<SteinerTreeResult>
4949
private final boolean applyRerouting;
5050
private final double delta;
5151
private final ExecutorService executorService;
52-
private int binSizeThreshold;
52+
private final int binSizeThreshold;
5353

5454
public ShortestPathsSteinerAlgorithm(
5555
Graph graph,
@@ -156,7 +156,7 @@ public void release() {
156156
}
157157

158158
private void initForSource(HugeLongArray parent, HugeDoubleArray parentCost) {
159-
parent.set(sourceId, ROOTNODE);
159+
parent.set(sourceId, ROOT_NODE);
160160
parentCost.set(sourceId, 0);
161161
}
162162

@@ -249,7 +249,7 @@ private LinkCutTree createLinkCutTree(HugeLongArray parent) {
249249
var tree = new LinkCutTree(graph.nodeCount());
250250
for (long nodeId = 0; nodeId < graph.nodeCount(); ++nodeId) {
251251
var parentId = parent.get(nodeId);
252-
if (parentId != PRUNED && parentId != ROOTNODE) {
252+
if (parentId != PRUNED && parentId != ROOT_NODE) {
253253
tree.link(parentId, nodeId);
254254
}
255255
}
@@ -279,7 +279,7 @@ private void cutNodesAfterRerouting(
279279
}
280280

281281
ParallelUtil.parallelForEachNode(graph.nodeCount(), concurrency, nodeId -> {
282-
if (parent.get(nodeId) != PRUNED && parent.get(nodeId) != ROOTNODE) {
282+
if (parent.get(nodeId) != PRUNED && parent.get(nodeId) != ROOT_NODE) {
283283
if (!endsAtTerminal.get(nodeId)) {
284284
parent.set(nodeId, PRUNED);
285285
totalCost.add(-parentCost.get(nodeId));
@@ -311,7 +311,7 @@ private void reroute(
311311
var parentId = parent.get(t);
312312
double targetParentCost = parentCost.get(t);
313313
//we want to see if replacing t's parent with nodeId makes sense (i.e., smaller cost)
314-
if (parentId != PRUNED && parentId != ROOTNODE && w < targetParentCost) {
314+
if (parentId != PRUNED && parentId != ROOT_NODE && w < targetParentCost) {
315315
boolean shouldReconnect = checkIfRerouteIsValid(tree, s, t, parentId);
316316
if (shouldReconnect) { //yes we can replace t's parent with s
317317
didReroutes.setTrue();

algo/src/test/java/org/neo4j/gds/steiner/ShortestPathSteinerAlgorithmExtendedTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ void shouldWorkCorrectly(double delta, int binSizeThreshold) {
170170
ProgressTracker.NULL_TRACKER
171171
).compute();
172172

173-
long[] parentArray = new long[]{ShortestPathsSteinerAlgorithm.ROOTNODE, a[0], a[1], a[2], a[3], a[4]};
173+
long[] parentArray = new long[]{ShortestPathsSteinerAlgorithm.ROOT_NODE, a[0], a[1], a[2], a[3], a[4]};
174174
double[] parentCostArray = new double[]{0, 1.0, 1.0, 1.0, 1.0, 4.1};
175175
SteinerTestUtils.assertTreeIsCorrect(idFunction, steinerTreeResult, parentArray, parentCostArray, 8.1);
176176
}
@@ -191,7 +191,7 @@ void shouldWorkCorrectlyWithLineGraph() {
191191
)
192192
.compute();
193193

194-
long[] parentArray = new long[]{ShortestPathsSteinerAlgorithm.ROOTNODE, a[0], a[1], a[2], a[3]};
194+
long[] parentArray = new long[]{ShortestPathsSteinerAlgorithm.ROOT_NODE, a[0], a[1], a[2], a[3]};
195195

196196
double[] parentCostArray = new double[]{0, 1, 1, 1, 1};
197197

@@ -243,7 +243,7 @@ void shouldWorkIfRevisitsVertices() {
243243
).compute();
244244

245245
long[] parentArray = new long[]{
246-
ShortestPathsSteinerAlgorithm.ROOTNODE,
246+
ShortestPathsSteinerAlgorithm.ROOT_NODE,
247247
a[0],
248248
a[1],
249249
a[6],
@@ -271,7 +271,7 @@ void shouldWorkOnTriangle() {
271271
ProgressTracker.NULL_TRACKER
272272
).compute();
273273

274-
long[] parentArray = new long[]{ShortestPathsSteinerAlgorithm.ROOTNODE, a[0], a[1], a[2]};
274+
long[] parentArray = new long[]{ShortestPathsSteinerAlgorithm.ROOT_NODE, a[0], a[1], a[2]};
275275
double[] parentCostArray = new double[]{0, 15, 3, 6};
276276

277277
SteinerTestUtils.assertTreeIsCorrect(triangleIdFunction, steinerTreeResult, parentArray, parentCostArray, 24);

algo/src/test/java/org/neo4j/gds/steiner/ShortestPathsSteinerAlgorithmReroutingTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ void rerouteShouldNotCreateLoops() {
134134
).compute();
135135
var parent = steinerResult.parentArray().toArray();
136136

137-
assertThat(parent[(int) idFunction.of("a0")]).isEqualTo(ShortestPathsSteinerAlgorithm.ROOTNODE);
137+
assertThat(parent[(int) idFunction.of("a0")]).isEqualTo(ShortestPathsSteinerAlgorithm.ROOT_NODE);
138138
assertThat(parent[(int) idFunction.of("a1")]).isEqualTo(idFunction.of("a0"));
139139
assertThat(parent[(int) idFunction.of("a2")]).isEqualTo(idFunction.of("a1"));
140140
assertThat(parent[(int) idFunction.of("a3")]).isEqualTo(idFunction.of("a2"));

algo/src/test/java/org/neo4j/gds/steiner/ShortestPathsSteinerAlgorithmTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ void shouldWorkCorrectly() {
8383
ProgressTracker.NULL_TRACKER
8484
).compute();
8585
var pruned = ShortestPathsSteinerAlgorithm.PRUNED;
86-
var rootnode = ShortestPathsSteinerAlgorithm.ROOTNODE;
86+
var rootnode = ShortestPathsSteinerAlgorithm.ROOT_NODE;
8787
long[] parentArray = new long[]{
8888
rootnode,
8989
pruned,

0 commit comments

Comments
 (0)