Skip to content

Commit

Permalink
Reduce unneeded bitset creation
Browse files Browse the repository at this point in the history
  • Loading branch information
Quasar985 committed Feb 26, 2025
1 parent ae9ad76 commit aae5461
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2024 Australian Signals Directorate
* Copyright 2010-2025 Australian Signals Directorate
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -410,7 +410,7 @@ private static Tuple<BitSet[], float[]> computeAllPathsDirected(final GraphReadM
protected static Tuple<BitSet[], float[]> computeShortestPathsUndirected(final GraphReadMethods graph, final ScoreType scoreType, final boolean selectedOnly) {
final int vertexCount = graph.getVertexCount();
final BitSet[] traversal = new BitSet[vertexCount];
final float[] scores = new float[vertexCount];
final float[] scores = new float[vertexCount]; // Array initialised with 0's

final BitSet update = new BitSet(vertexCount);
final BitSet[] sendFails = new BitSet[vertexCount];
Expand All @@ -421,12 +421,12 @@ protected static Tuple<BitSet[], float[]> computeShortestPathsUndirected(final G

// initialise variables
for (int vertexPosition = 0; vertexPosition < vertexCount; vertexPosition++) {
traversal[vertexPosition] = new BitSet(vertexCount);
scores[vertexPosition] = 0;

// only update nodes with neighbours
final int vxId = graph.getVertex(vertexPosition);
if (graph.getVertexNeighbourCount(vxId) > 0) {
traversal[vertexPosition] = new BitSet(vertexCount);

update.set(vertexPosition);

sendFails[vertexPosition] = new BitSet(vertexCount);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public void testComputeShortestPathsUndirected() {

// Set up expected expected bit set array
final BitSet expectedBitSetA = BitSet.valueOf(new long[]{0b11011});
final BitSet expectedBitSetB = BitSet.valueOf(new long[]{0b00000});
final BitSet expectedBitSetB = null;
final BitSet[] expectedBitSets = {expectedBitSetA, expectedBitSetA, expectedBitSetB, expectedBitSetA, expectedBitSetA};
// Set up expected float array
final float[] expectedFloats = {2.0F, 2.0F, 0.0F, 2.0F, 2.0F};
Expand Down

0 comments on commit aae5461

Please sign in to comment.