Refactor connection weight calculation to use ArrayList for fixing bug

This commit is contained in:
2025-02-12 17:57:21 +01:00
parent cb8b2d2913
commit 65e8f378f5

View File

@@ -170,14 +170,13 @@ public final class Net implements Iterable<ServerNode> {
for (var conn : list) for (var conn : list)
sum += conn.weight; sum += conn.weight;
var newOne = new Connection[list.size()]; var newOne = new ArrayList<Connection>();
for (var i = 0; i < list.size(); i++) { for (var conn : list) {
var conn = list.get(i);
var newWeight = conn.weight / sum; var newWeight = conn.weight / sum;
newOne[i] = new Connection(conn.index, newWeight); newOne.add(new Connection(conn.index, newWeight));
} }
this.connections.set(node, List.of(newOne)); this.connections.set(node, newOne);
} }
} }