java/com.sap.sse.common/src/com/sap/sse/common/scalablevalue/KadaneExtremeSubarraysFinder.java
... ...
@@ -42,12 +42,12 @@ implements Serializable, Iterable<T> {
42 42
* includes prior elements; or the single element {@code sequence.get(i)} is greater than the sum of it and the maximum
43 43
* sum ending at the previous element {@code i-1}.
44 44
*/
45
- private final List<AveragesTo> maxSumEndingAt;
45
+ private final List<ScalableValueWithDistance<ValueType, AveragesTo>> maxSumEndingAt;
46 46
47 47
/**
48 48
* The maximum of the sums of any contiguous sub-sequence
49 49
*/
50
- private AveragesTo maxSum;
50
+ private ScalableValueWithDistance<ValueType, AveragesTo> maxSum;
51 51
52 52
/**
53 53
* Index of the first element in {@link #sequence} of the contiguous sub-sequence having the maximum sum
... ...
@@ -62,9 +62,9 @@ implements Serializable, Iterable<T> {
62 62
/**
63 63
* See {@code #maxSumEndingAt}, only for the minimum.
64 64
*/
65
- private final List<AveragesTo> minSumEndingAt;
65
+ private final List<ScalableValueWithDistance<ValueType, AveragesTo>> minSumEndingAt;
66 66
67
- private AveragesTo minSum;
67
+ private ScalableValueWithDistance<ValueType, AveragesTo> minSum;
68 68
69 69
/**
70 70
* Index of the first element in {@link #sequence} of the contiguous sub-sequence having the minium sum
... ...
@@ -91,12 +91,13 @@ implements Serializable, Iterable<T> {
91 91
public synchronized void add(int index, T t) {
92 92
sequence.add(index, t);
93 93
if (index == 0) {
94
- maxSumEndingAt.add(index, t.divide(1));
94
+ maxSumEndingAt.add(index, t);
95 95
// TODO update subsequent elements based on the change
96 96
} else {
97
- if (t.compareTo(maxSumEndingAt.get(index-1)) >= 0) {
98
- maxSumEndingAt.add(index, t.divide(1));
97
+ if (t.divide(1).compareTo(maxSumEndingAt.get(index-1).divide(1)) >= 0) {
98
+ maxSumEndingAt.add(index, t); // one-element sum consisting of element at "index" is the maximum
99 99
} else {
100
+ maxSumEndingAt.add(index, t.add(maxSumEndingAt.get(index-1)));
100 101
// TODO
101 102
}
102 103
}
... ...
@@ -116,11 +117,11 @@ implements Serializable, Iterable<T> {
116 117
remove(sequence.indexOf(t));
117 118
}
118 119
119
- public AveragesTo getMaxSum() {
120
+ public ScalableValueWithDistance<ValueType, AveragesTo> getMaxSum() {
120 121
return maxSum;
121 122
}
122 123
123
- public AveragesTo getMinSum() {
124
+ public ScalableValueWithDistance<ValueType, AveragesTo> getMinSum() {
124 125
return minSum;
125 126
}
126 127