97aea0e9ffe95696193b62a5b16b528dfe35d67b
java/com.sap.sse.common.test/src/com/sap/sse/common/test/KadaneExtremeSubsequenceFinderTest.java
| ... | ... | @@ -3,6 +3,9 @@ package com.sap.sse.common.test; |
| 3 | 3 | import static org.junit.jupiter.api.Assertions.assertEquals; |
| 4 | 4 | import static org.junit.jupiter.api.Assertions.assertTrue; |
| 5 | 5 | |
| 6 | +import java.util.Random; |
|
| 7 | +import java.util.TreeSet; |
|
| 8 | + |
|
| 6 | 9 | import org.junit.jupiter.api.Test; |
| 7 | 10 | |
| 8 | 11 | import com.sap.sse.common.scalablevalue.KadaneExtremeSubsequenceFinder; |
| ... | ... | @@ -132,4 +135,16 @@ public abstract class KadaneExtremeSubsequenceFinderTest { |
| 132 | 135 | assertEquals(0, finder.getStartIndexOfMaxSumSequence()); |
| 133 | 136 | assertEquals(1, finder.getEndIndexOfMaxSumSequence()); |
| 134 | 137 | } |
| 138 | + |
|
| 139 | + @Test |
|
| 140 | + public void performanceTest() { |
|
| 141 | + final Random random = new Random(); |
|
| 142 | + final int NODES = 10000; |
|
| 143 | + for (int i=0; i<NODES; i++) { |
|
| 144 | + finder.add(new ScalableDouble(random.nextDouble()-0.5)); |
|
| 145 | + } |
|
| 146 | + for (int i=0; i<NODES/2; i++) { |
|
| 147 | + finder.remove(random.nextInt(finder.size())); |
|
| 148 | + } |
|
| 149 | + } |
|
| 135 | 150 | } |
java/com.sap.sse.common/src/com/sap/sse/common/scalablevalue/KadaneExtremeSubsequenceFinderLinkedNodesImpl.java
| ... | ... | @@ -205,8 +205,9 @@ public class KadaneExtremeSubsequenceFinderLinkedNodesImpl<ValueType, AveragesTo |
| 205 | 205 | this.last = null; |
| 206 | 206 | final Comparator<Node<ValueType, AveragesTo, T>> minSumComparator = (n1, n2)->compare(n1.getMinSumEndingHere(), n2.getMinSumEndingHere()); |
| 207 | 207 | final Comparator<Node<ValueType, AveragesTo, T>> maxSumComparator = (n1, n2)->compare(n1.getMaxSumEndingHere(), n2.getMaxSumEndingHere()); |
| 208 | - this.nodesOrderedByMinSum = new TreeSet<>(minSumComparator.thenComparing((n1, n2)->Integer.compare(n1.getId(), n2.getId()))); |
|
| 209 | - this.nodesOrderedByMaxSum = new TreeSet<>(maxSumComparator.thenComparing((n1, n2)->Integer.compare(n1.getId(), n2.getId()))); |
|
| 208 | + final Comparator<? super Node<ValueType, AveragesTo, T>> idComparator = (n1, n2)->Integer.compare(n1.getId(), n2.getId()); |
|
| 209 | + this.nodesOrderedByMinSum = new TreeSet<>((n1,n2)->(n1==n2?0:minSumComparator.thenComparing(idComparator).compare(n1, n2))); |
|
| 210 | + this.nodesOrderedByMaxSum = new TreeSet<>((n1,n2)->(n1==n2?0:maxSumComparator.thenComparing(idComparator).compare(n1, n2))); |
|
| 210 | 211 | } |
| 211 | 212 | |
| 212 | 213 | @Override |