private void insertBatch() {
    LOG.debug("insertBatch called");

    if (bufferCount == 0) {
      return;
    }
    printList();

    Arrays.sort(buffer, 0, bufferCount);
    printBuffer();

    // Base case: no samples
    int start = 0;
    if (sample.size() == 0) {
      Item newItem = new Item(buffer[0], 1, 0);
      sample.add(newItem);
      start++;
      count++;
    }

    ListIterator<Item> it = sample.listIterator();
    Item item = it.next();
    for (int i = start; i < bufferCount; i++) {
      long v = buffer[i];
      while (it.nextIndex() < sample.size() && item.value < v) {
        item = it.next();
      }
      // If we found that bigger item, back up so we insert ourselves before it
      if (item.value > v) {
        it.previous();
      }
      // We use different indexes for the edge comparisons, because of the above
      // if statement that adjusts the iterator
      int delta;
      if (it.previousIndex() == 0 || it.nextIndex() == sample.size()) {
        delta = 0;
      } else {
        delta = ((int) Math.floor(allowableError(it.nextIndex()))) - 1;
      }
      Item newItem = new Item(v, 1, delta);
      it.add(newItem);
      count++;
      item = newItem;
      printList();
    }

    bufferCount = 0;
    printList();
    LOG.debug("insertBatch finished");
  }