-
-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Optimized ShrinkingDistance.forCollection(..)
Working towards #435 effects
- Loading branch information
Showing
3 changed files
with
26 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,16 +13,24 @@ public static long at(long[] array, int i) { | |
return array.length > i ? array[i] : 0; | ||
} | ||
|
||
public static long[] sumUp(long[] left, long[] right) { | ||
long[] sum = new long[Math.max(left.length, right.length)]; | ||
for (int i = 0; i < sum.length; i++) { | ||
long summedValue = at(left, i) + at(right, i); | ||
if (summedValue < 0) { | ||
summedValue = Long.MAX_VALUE; | ||
public static long[] sumUp(List<long[]> listOfArrays) { | ||
int maxDistanceSize = listOfArrays.stream().mapToInt(s -> s.length).max().orElse(0); | ||
long[] summedUpArray = new long[maxDistanceSize]; | ||
Arrays.fill(summedUpArray, 0); | ||
for (long[] array : listOfArrays) { | ||
for (int i = 0; i < summedUpArray.length; i++) { | ||
summedUpArray[i] = plusWithoutOverflowAt(summedUpArray, array, i); | ||
} | ||
sum[i] = summedValue; | ||
} | ||
return sum; | ||
return summedUpArray; | ||
} | ||
|
||
private static long plusWithoutOverflowAt(long[] left, long[] right, int index) { | ||
long summedValue = at(right, index) + at(left, index); | ||
if (summedValue < 0) { | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
jlink
Author
Collaborator
|
||
return Long.MAX_VALUE; | ||
} | ||
return summedValue; | ||
} | ||
|
||
public static long[] concatenate(List<long[]> listOfArrays) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This is a wrong way to detect overflow