private int popAndInsert() throws InterruptedException {
  Stats min=pq.take();
  if (LOG.isTraceEnabled()) {
    LOG.trace("picked forest# " + min.fIdx + " with "+ min.frmtCount+ " docs");
  }
  min.frmtCount+=batch;
  pq.offer(min);
  int idx=min.fIdx;
  frmtCount[idx]=min.frmtCount;
  return idx;
}

private int popAndInsert ( ) throws InterruptedException { Stats min = pq . take ( ) ; if ( LOG . isTraceEnabled ( ) ) { LOG . trace ( "picked forest# " + min . fIdx + " with " + min . frmtCount + " docs" ) ; } min . frmtCount += batch ; pq . offer ( min ) ; int idx = min . fIdx ; frmtCount [ idx ] = min . frmtCount ; return idx ; }
most of the time , frmtcount increase by batch ; instead of waiting the batch actually accumulated , we increment the batch in the priority . in this way , we merge two operations ( peek and remove ) into one operation ( take ) . what ' s more , the take operation only takes o ( 1 ) time while the remove operation takes o ( n ) time , where n is # forests . the down - side is , if insertcontentcollecterrors happens to collect errors , # of docs with errors is not excluded in the stats in the queue
