From e1006342b4445e528ceedd0b2c51f31f175282eb Mon Sep 17 00:00:00 2001 From: Lee Rhodes Date: Wed, 24 Jan 2024 12:08:31 -0800 Subject: [PATCH] initial commit --- .../apache/datasketches/kll/KllDoublesHelper.java | 1 - .../apache/datasketches/kll/KllFloatsHelper.java | 5 ++--- .../apache/datasketches/kll/KllItemsHelper.java | 14 ++++++++++++++ 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/apache/datasketches/kll/KllDoublesHelper.java b/src/main/java/org/apache/datasketches/kll/KllDoublesHelper.java index 741092337..15e6c52f7 100644 --- a/src/main/java/org/apache/datasketches/kll/KllDoublesHelper.java +++ b/src/main/java/org/apache/datasketches/kll/KllDoublesHelper.java @@ -37,7 +37,6 @@ * @author Kevin Lang * @author Alexander Saydakov */ -// final class KllDoublesHelper { /** diff --git a/src/main/java/org/apache/datasketches/kll/KllFloatsHelper.java b/src/main/java/org/apache/datasketches/kll/KllFloatsHelper.java index 8c35fc66a..efdb4e4b2 100644 --- a/src/main/java/org/apache/datasketches/kll/KllFloatsHelper.java +++ b/src/main/java/org/apache/datasketches/kll/KllFloatsHelper.java @@ -37,7 +37,6 @@ * @author Kevin Lang * @author Alexander Saydakov */ -// final class KllFloatsHelper { /** @@ -485,10 +484,10 @@ private static void populateFloatWorkArrays( if (selfPop == 0 && otherPop == 0) { continue; } if (selfPop > 0 && otherPop == 0) { System.arraycopy(myCurFloatItemsArr, myCurLevelsArr[lvl], workbuf, worklevels[lvl], selfPop); - } + } else if (selfPop == 0 && otherPop > 0) { System.arraycopy(otherFloatItemsArr, otherLevelsArr[lvl], workbuf, worklevels[lvl], otherPop); - } + } else if (selfPop > 0 && otherPop > 0) { mergeSortedFloatArrays( myCurFloatItemsArr, myCurLevelsArr[lvl], selfPop, diff --git a/src/main/java/org/apache/datasketches/kll/KllItemsHelper.java b/src/main/java/org/apache/datasketches/kll/KllItemsHelper.java index 502d43278..c3144a8eb 100644 --- a/src/main/java/org/apache/datasketches/kll/KllItemsHelper.java +++ b/src/main/java/org/apache/datasketches/kll/KllItemsHelper.java @@ -39,6 +39,20 @@ @SuppressWarnings("unchecked") final class KllItemsHelper { + /** + * Create Items Array from given item and weight. + * Used with weighted update only. + * @param item the given item + * @param weight the given weight + * @return the Items Array. + */ + static T[] createItemsArray(final T item, final int weight) { + final int itemsArrLen = Integer.bitCount(weight); + final Object[] itemsArr = new Object[itemsArrLen]; + Arrays.fill(itemsArr, item); + return (T[]) itemsArr; + } + /** * The following code is only valid in the special case of exactly reaching capacity while updating. * It cannot be used while merging, while reducing k, or anything else.