private static void populateItemWorkArrays()

in src/main/java/org/apache/datasketches/kll/KllItemsHelper.java [470:502]


  private static <T> void populateItemWorkArrays( //workBuf and workLevels are modified
      final Object[] workbuf, final int[] worklevels, final int provisionalNumLevels,
      final int myCurNumLevels, final int[] myCurLevelsArr, final Object[] myCurItemsArr,
      final int otherNumLevels, final int[] otherLevelsArr, final Object[] otherItemsArr,
      final Comparator<? super T> comp) {
    worklevels[0] = 0;

    // Note: the level zero data from "other" was already inserted into "self".
    // This copies into workbuf.
    final int selfPopZero = KllHelper.currentLevelSizeItems(0, myCurNumLevels, myCurLevelsArr);
    System.arraycopy( myCurItemsArr, myCurLevelsArr[0], workbuf, worklevels[0], selfPopZero);
    worklevels[1] = worklevels[0] + selfPopZero;

    for (int lvl = 1; lvl < provisionalNumLevels; lvl++) {
      final int selfPop = KllHelper.currentLevelSizeItems(lvl, myCurNumLevels, myCurLevelsArr);
      final int otherPop = KllHelper.currentLevelSizeItems(lvl, otherNumLevels, otherLevelsArr);
      worklevels[lvl + 1] = worklevels[lvl] + selfPop + otherPop;
      assert selfPop >= 0 && otherPop >= 0;
      if (selfPop == 0 && otherPop == 0) { continue; }
      else if (selfPop > 0 && otherPop == 0) {
        System.arraycopy(myCurItemsArr, myCurLevelsArr[lvl], workbuf, worklevels[lvl], selfPop);
      }
      else if (selfPop == 0 && otherPop > 0) {
        System.arraycopy(otherItemsArr, otherLevelsArr[lvl], workbuf, worklevels[lvl], otherPop);
      }
      else if (selfPop > 0 && otherPop > 0) {
        mergeSortedItemsArrays(
            myCurItemsArr, myCurLevelsArr[lvl], selfPop,
            otherItemsArr, otherLevelsArr[lvl], otherPop,
            workbuf, worklevels[lvl], comp);
      }
    }
  }