private void insertBatch(){
  if (index == 0) {
    return;
  }
  Arrays.sort(batch,0,index);
  int start=0;
  if (samples.isEmpty()) {
    samples.add(new SampleItem(batch[0],0,1));
    start++;
  }
  final ListIterator<SampleItem> it=samples.listIterator();
  SampleItem prev=it.next();
  for (int i=start; i < index; i++) {
    final double value=batch[i];
    while (it.nextIndex() < samples.size() && prev.value < value) {
      prev=it.next();
    }
    if (prev.value > value) {
      it.previous();
    }
    final int delta=calculateDelta(it.previousIndex(),it.nextIndex());
    final SampleItem next=new SampleItem(value,delta,1);
    it.add(next);
    prev=next;
  }
  index=0;
}

private void insertBatch ( ) { if ( index == 0 ) { return ; } Arrays . sort ( batch , 0 , index ) ; int start = 0 ; if ( samples . isEmpty ( ) ) { samples . add ( new SampleItem ( batch [ 0 ] , 0 , 1 ) ) ; start ++ ; } final ListIterator < SampleItem > it = samples . listIterator ( ) ; SampleItem prev = it . next ( ) ; for ( int i = start ; i < index ; i ++ ) { final double value = batch [ i ] ; while ( it . nextIndex ( ) < samples . size ( ) && prev . value < value ) { prev = it . next ( ) ; } if ( prev . value > value ) { it . previous ( ) ; } final int delta = calculateDelta ( it . previousIndex ( ) , it . nextIndex ( ) ) ; final SampleItem next = new SampleItem ( value , delta , 1 ) ; it . add ( next ) ; prev = next ; } index = 0 ; }
merges items from buffer into the samples array in one pass . this is more efficient than doing an insert on every item .
