private void updateGaps(Bin<T> newBin) { Bin<T> prev = lower(newBin.getMean()); if (prev != null) { updateGaps(prev, newBin); } Bin<T> next = higher(newBin.getMean()); if (next != null) { updateGaps(newBin, next); } }
private void updateGaps(Bin<T> prev, Bin<T> next) { Gap<T> newGap = new Gap<T>(prev, next, gapWeight(prev, next)); Gap<T> prevGap = _binsToGaps.get(prev.getMean()); if (prevGap != null) { _gaps.remove(prevGap); } _binsToGaps.put(prev.getMean(), newGap); _gaps.add(newGap); }
@Override public void insert(Bin<T> bin) { addTotalCount(bin); if (isFrozen() && getBins().size() == getMaxBins()) { Double floorDiff = Double.MAX_VALUE; Bin<T> floorBin = floor(bin.getMean()); if (floorBin != null) { floorDiff = Math.abs(floorBin.getMean() - bin.getMean()); } Double ceilDiff = Double.MAX_VALUE; Bin<T> ceilBin = ceiling(bin.getMean()); if (ceilBin != null) { ceilDiff = Math.abs(ceilBin.getMean() - bin.getMean()); } if (floorDiff <= ceilDiff) { floorBin.sumUpdate(bin); } else { ceilBin.sumUpdate(bin); } } else { Bin<T> existingBin = get(bin.getMean()); if (existingBin != null) { existingBin.sumUpdate(bin); if (isWeightGaps()) { updateGaps(existingBin); } } else { updateGaps(bin); _bins.put(bin.getMean(), bin); } } }
@Override public void merge() { while (_bins.size() > getMaxBins()) { Gap<T> smallestGap = _gaps.pollFirst(); Bin<T> newBin = smallestGap.getStartBin().combine(smallestGap.getEndBin()); Gap<T> followingGap = _binsToGaps.get(smallestGap.getEndBin().getMean()); if (followingGap != null) { _gaps.remove(followingGap); } _bins.remove(smallestGap.getStartBin().getMean()); _bins.remove(smallestGap.getEndBin().getMean()); _binsToGaps.remove(smallestGap.getStartBin().getMean()); _binsToGaps.remove(smallestGap.getEndBin().getMean()); updateGaps(newBin); _bins.put(newBin.getMean(), newBin); } }