private void twoWayMergeInternal(final ReservoirItemsSketch<T> sketchIn,final boolean isModifiable){
  if (sketchIn.getN() <= sketchIn.getK()) {
    twoWayMergeInternalStandard(sketchIn);
  }
 else   if (gadget_.getN() < gadget_.getK()) {
    final ReservoirItemsSketch<T> tmpSketch=gadget_;
    gadget_=(isModifiable ? sketchIn : sketchIn.copy());
    twoWayMergeInternalStandard(tmpSketch);
  }
 else   if (sketchIn.getImplicitSampleWeight() < gadget_.getN() / ((double)(gadget_.getK() - 1))) {
    twoWayMergeInternalWeighted(sketchIn);
  }
 else {
    final ReservoirItemsSketch<T> tmpSketch=gadget_;
    gadget_=(isModifiable ? sketchIn : sketchIn.copy());
    twoWayMergeInternalWeighted(tmpSketch);
  }
}

private void twoWayMergeInternal ( final ReservoirItemsSketch < T > sketchIn , final boolean isModifiable ) { if ( sketchIn . getN ( ) <= sketchIn . getK ( ) ) { twoWayMergeInternalStandard ( sketchIn ) ; } else if ( gadget_ . getN ( ) < gadget_ . getK ( ) ) { final ReservoirItemsSketch < T > tmpSketch = gadget_ ; gadget_ = ( isModifiable ? sketchIn : sketchIn . copy ( ) ) ; twoWayMergeInternalStandard ( tmpSketch ) ; } else if ( sketchIn . getImplicitSampleWeight ( ) < gadget_ . getN ( ) / ( ( double ) ( gadget_ . getK ( ) - 1 ) ) ) { twoWayMergeInternalWeighted ( sketchIn ) ; } else { final ReservoirItemsSketch < T > tmpSketch = gadget_ ; gadget_ = ( isModifiable ? sketchIn : sketchIn . copy ( ) ) ; twoWayMergeInternalWeighted ( tmpSketch ) ; } }
this either merges sketchin into gadget_ or gadget_ into sketchin . if merging into sketchin with ismodifiable set to false , copies elements from sketchin first , leaving original unchanged .
