Skip to content

Commit 339c4e2

Browse files
committed
1 parent da77c0d commit 339c4e2

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/main/java/org/cicirello/permutations/distance/WeightedKendallTauDistance.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,17 +130,18 @@ private double merge(int[] array, double[] w, int first, int midPlus, int lastPl
130130
int j = 0;
131131
int k = first;
132132
double weightedCount = 0;
133+
double leftWeights = 0;
134+
for (int x = 0; x < left.length; x++) {
135+
leftWeights += w[left[x]];
136+
}
133137
while (i < left.length && j < right.length) {
134138
if (left[i] < right[j]) {
139+
leftWeights -= w[left[i]];
135140
array[k] = left[i];
136141
i++;
137142
k++;
138143
} else {
139144
// inversions
140-
double leftWeights = 0;
141-
for (int x = i; x < left.length; x++) {
142-
leftWeights += w[left[x]];
143-
}
144145
weightedCount += w[right[j]] * leftWeights;
145146
array[k] = right[j];
146147
j++;

0 commit comments

Comments
 (0)