Skip to content

Commit

Permalink
This commit is the result of the first round of reviews.
Browse files Browse the repository at this point in the history
  • Loading branch information
leerho committed Nov 29, 2023
1 parent 56e3bd9 commit 6ecbf50
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 96 deletions.
36 changes: 18 additions & 18 deletions src/main/java/org/apache/datasketches/common/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -531,39 +531,39 @@ public static double powerSeriesNextDouble(final int ppb, final double curPoint,
}

/**
* Returns the ceiling of a given <i>n</i> given a <i>radix</i>, where the ceiling is an integral power of the radix.
* This is the smallest positive power of <i>radix</i> that is equal to or greater than the given <i>n</i>
* Returns the ceiling of a given <i>n</i> given a <i>base</i>, where the ceiling is an integral power of the base.
* This is the smallest positive power of <i>base</i> that is equal to or greater than the given <i>n</i>
* and equal to a mathematical integer.
* The result of this function is consistent with {@link #ceilingIntPowerOf2(int)} for values
* less than one. I.e., if <i>n &lt; 1,</i> the result is 1.
*
* <p>The formula is: <i>radix<sup>ceiling(log<sub>radix</sub>(x))</sup></i></p>
* <p>The formula is: <i>base<sup>ceiling(log<sub>base</sub>(x))</sup></i></p>
*
* @param radix The base of the number system.
* @param base The number in the expression &#8968;base<sup>n</sup>&#8969;.
* @param n The input argument.
* @return the ceiling power of <i>radix</i> as a double and equal to a mathematical integer.
* @return the ceiling power of <i>base</i> as a double and equal to a mathematical integer.
*/
public static double ceilingPowerBaseOfDouble(final double radix, final double n) {
public static double ceilingPowerBaseOfDouble(final double base, final double n) {
final double x = n < 1.0 ? 1.0 : n;
return Math.round(pow(radix, ceil(logBaseOfX(radix, x))));
return Math.round(pow(base, ceil(logBaseOfX(base, x))));
}

/**
* Computes the floor of a given <i>n</i> given <i>radix</i>, where the floor is an integral power of the radix.
* This is the largest positive power of <i>radix</i> that is equal to or less than the given <i>n</i>
* Computes the floor of a given <i>n</i> given <i>base</i>, where the floor is an integral power of the base.
* This is the largest positive power of <i>base</i> that is equal to or less than the given <i>n</i>
* and equal to a mathematical integer.
* The result of this function is consistent with {@link #floorPowerOf2(int)} for values
* less than one. I.e., if <i>n &lt; 1,</i> the result is 1.
*
* <p>The formula is: <i>radix<sup>floor(log<sub>radix</sub>(x))</sup></i></p>
* <p>The formula is: <i>base<sup>floor(log<sub>base</sub>(x))</sup></i></p>
*
* @param radix The base of the number system.
* @param base The number in the expression &#8970;base<sup>n</sup>&#8971;.
* @param n The input argument.
* @return the floor power of 2 and equal to a mathematical integer.
*/
public static double floorPowerBaseOfDouble(final double radix, final double n) {
public static double floorPowerBaseOfDouble(final double base, final double n) {
final double x = n < 1.0 ? 1.0 : n;
return Math.round(pow(radix, floor(logBaseOfX(radix, x))));
return Math.round(pow(base, floor(logBaseOfX(base, x))));
}

// Logarithm related
Expand All @@ -578,13 +578,13 @@ public static double log2(final double value) {
}

/**
* Returns the log<sub>radix</sub>(x). Example: logB(2.0, x) = log(x) / log(2.0).
* @param radix the base of the number system
* Returns the log<sub>base</sub>(x). Example, if base = 2.0: logB(2.0, x) = log(x) / log(2.0).
* @param base The number in the expression log(x) / log(base).
* @param x the given value
* @return the log<sub>radix</sub>(x): Example: logB(2.0, x) = log(x) / log(2.0).
* @return the log<sub>base</sub>(x)
*/
public static double logBaseOfX(final double radix, final double x) {
return log(x) / log(radix);
public static double logBaseOfX(final double base, final double x) {
return log(x) / log(base);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,9 @@ public GenericPartitionBoundaries<T> getPartitionBoundaries(final int numEqually
}
final GenericPartitionBoundaries<T> gpb = new GenericPartitionBoundaries<>(
this.totalN,
evSpQuantiles.clone(),
evSpNatRanks.clone(),
evSpNormRanks.clone(),
evSpQuantiles,
evSpNatRanks,
evSpNormRanks,
getMaxItem(),
getMinItem(),
searchCrit);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import static org.apache.datasketches.quantilescommon.QuantileSearchCriteria.INCLUSIVE;
import static org.apache.datasketches.quantilescommon.QuantilesAPI.EMPTY_MSG;

import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.List;

Expand All @@ -36,22 +37,20 @@
import org.apache.datasketches.quantilescommon.PartitioningFeature;
import org.apache.datasketches.quantilescommon.QuantileSearchCriteria;
import org.apache.datasketches.quantilescommon.QuantilesGenericAPI;
import org.apache.datasketches.quantilescommon.Stack;

/**
* A partitioning process that can partition very large data sets into thousands
* of partitions of approximately the same size.
* @param <T> the data type
* @param <S> the quantiles sketch that implements both QuantilesGenericAPI and PartitioningFeature.
*/
//@SuppressWarnings("unused")
public class Partitioner<T, S extends QuantilesGenericAPI<T> & PartitioningFeature<T>> {
private static final QuantileSearchCriteria defaultCriteria = INCLUSIVE;
private final long tgtPartitionSize;
private final int maxPartsPerSk;
private final SketchFillRequest<T, S> fillReq;
private final QuantileSearchCriteria criteria;
private final Stack<StackElement<T>> stack = new Stack<>();
private final ArrayDeque<StackElement<T>> stack = new ArrayDeque<>();

//computed once at the beginning
private int numLevels;
Expand Down Expand Up @@ -114,7 +113,7 @@ public List<PartitionBoundsRow<T>> partition(final S sk) {
return finalPartitionList;
}

private void partitionSearch(final Stack<StackElement<T>> stack) {
private void partitionSearch(final ArrayDeque<StackElement<T>> stack) {
if (stack.isEmpty()) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,9 @@ public GenericPartitionBoundaries<T> getPartitionBoundaries(final int numEqually
}
final GenericPartitionBoundaries<T> gpb = new GenericPartitionBoundaries<>(
this.totalN,
evSpQuantiles.clone(),
evSpNatRanks.clone(),
evSpNormRanks.clone(),
evSpQuantiles,
evSpNatRanks,
evSpNormRanks,
getMaxItem(),
getMinItem(),
searchCrit);
Expand Down
68 changes: 0 additions & 68 deletions src/main/java/org/apache/datasketches/quantilescommon/Stack.java

This file was deleted.

0 comments on commit 6ecbf50

Please sign in to comment.