Skip to content

Commit

Permalink
Address PR comments
Browse files Browse the repository at this point in the history
Signed-off-by: Ketan Verma <[email protected]>
  • Loading branch information
ketanv3 committed Oct 31, 2023
1 parent bf37f5f commit 3d4f7ad
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class BidirectionalLinearSearcher implements Roundable {
private final long[] ascending;
private final long[] descending;

public BidirectionalLinearSearcher(long[] values, int size) {
BidirectionalLinearSearcher(long[] values, int size) {
assert size > 0 : "at least one value must be present";

int len = (size + 1) >>> 1; // rounded-up to handle odd number of values
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class BinarySearcher implements Roundable {
private final long[] values;
private final int size;

public BinarySearcher(long[] values, int size) {
BinarySearcher(long[] values, int size) {
assert size > 0 : "at least one value must be present";

this.values = values;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,15 @@

package org.opensearch.common.round;

import org.opensearch.common.annotation.InternalApi;

/**
* Factory class to create and return the fastest implementation of {@link Roundable}.
*
* @opensearch.internal
*/
public class RoundableFactory {
@InternalApi
public final class RoundableFactory {
/**
* The maximum limit up to which linear search is used, otherwise binary search is used.
* This is because linear search is much faster on small arrays.
Expand Down
6 changes: 3 additions & 3 deletions server/src/main/java/org/opensearch/common/Rounding.java
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ protected Prepared maybeUseArray(long minUtcMillis, long maxUtcMillis, int max)
values = ArrayUtil.grow(values, i + 1);
values[i++] = rounded;
}
return new ArrayRounding(values, i, this);
return new ArrayRounding(RoundableFactory.create(values, i), this);
}
}

Expand All @@ -456,8 +456,8 @@ private static class ArrayRounding implements Prepared {
private final Roundable roundable;
private final Prepared delegate;

public ArrayRounding(long[] values, int size, Prepared delegate) {
this.roundable = RoundableFactory.create(values, size);
public ArrayRounding(Roundable roundable, Prepared delegate) {
this.roundable = roundable;
this.delegate = delegate;
}

Expand Down

0 comments on commit 3d4f7ad

Please sign in to comment.