use of it.unimi.dsi.fastutil.ints.Int2DoubleSortedMap in project gridss by PapenfussLab.
the class IntervalAccumulator method add.
/**
* Add the given value at all positions in the given interval
* @param start start position (inclusive)
* @param end end position (inclusive)
* @param value value to add
*/
public void add(int start, int end, double value) {
if (binWidth == null) {
throw new IllegalStateException("Must be called after finaliseBins()");
}
if (end < start) {
throw new IllegalArgumentException("end cannot be before start");
}
// double perBaseValue = value / (end - start + 1);
start = Math.max(start, firstBinStart);
end = Math.min(end, lastBinEnd);
int startBinStartKey = bins.headMap(start + 1).lastIntKey();
int endBinStartKey = bins.headMap(end + 1).lastIntKey();
Int2DoubleSortedMap toUpdate = bins.subMap(startBinStartKey, endBinStartKey + 1);
ObjectBidirectionalIterator<Int2DoubleMap.Entry> it = toUpdate.int2DoubleEntrySet().iterator();
int widthLeft = end - start + 1;
while (widthLeft > 0) {
assert (it.hasNext());
Int2DoubleMap.Entry entry = it.next();
int entryStartPosition = entry.getIntKey();
int overlap = IntervalUtil.overlapsWidthClosed(start, end, entryStartPosition, entryStartPosition + getBinSize(entryStartPosition) - 1);
entry.setValue(entry.getDoubleValue() + overlap * value);
widthLeft -= overlap;
}
}
Aggregations