mirror of
https://github.com/nosqlbench/nosqlbench.git
synced 2025-02-25 18:55:28 -06:00
#162 Allow hash range functions to span single value ranges
This commit is contained in:
parent
21be4c1987
commit
2a7406e0fa
@ -21,12 +21,11 @@ public class HashRange implements LongToIntFunction {
|
||||
|
||||
@Example({"HashRange(35L,39L)","map the input to a number in the range 35-38, inclusive, of type int"})
|
||||
public HashRange(int minValue, int maxValue) {
|
||||
this.minValue = minValue;
|
||||
|
||||
if (maxValue<=minValue) {
|
||||
if (maxValue<minValue) {
|
||||
throw new RuntimeException("HashRange must have min and max value in that order.");
|
||||
}
|
||||
this.width = maxValue - minValue;
|
||||
this.minValue = minValue;
|
||||
this.width = (maxValue - minValue) +1;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -8,6 +8,9 @@ import java.util.function.LongUnaryOperator;
|
||||
* Return a value within a range, pseudo-randomly. This is equivalent to
|
||||
* returning a value with in range between 0 and some maximum value, but
|
||||
* with a minimum value added.
|
||||
*
|
||||
* You can specify hash ranges as small as a single-element range, like
|
||||
* (5,5), or as wide as the relevant data type allows.
|
||||
*/
|
||||
@ThreadSafeMapper
|
||||
public class HashRange implements LongUnaryOperator {
|
||||
@ -22,12 +25,11 @@ public class HashRange implements LongUnaryOperator {
|
||||
}
|
||||
|
||||
public HashRange(long minValue, long maxValue) {
|
||||
this.minValue = minValue;
|
||||
|
||||
if (maxValue<=minValue) {
|
||||
if (maxValue<minValue) {
|
||||
throw new RuntimeException("HashRange must have min and max value in that order.");
|
||||
}
|
||||
this.width = maxValue - minValue;
|
||||
this.minValue = minValue;
|
||||
this.width = (maxValue - minValue)+1;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -17,12 +17,11 @@ public class HashRange implements IntUnaryOperator {
|
||||
}
|
||||
|
||||
public HashRange(int minValue, int maxValue) {
|
||||
this.minValue = minValue;
|
||||
|
||||
if (maxValue<=minValue) {
|
||||
if (maxValue<minValue) {
|
||||
throw new RuntimeException("HashRange must have min and max value in that order.");
|
||||
}
|
||||
this.width = maxValue - minValue;
|
||||
this.minValue = minValue;
|
||||
this.width = (maxValue - minValue) +1;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -13,4 +13,11 @@ public class HashRangeTest {
|
||||
assertThat(hashRange.applyAsLong(32L)).isEqualTo(11L);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSingleElementRange() {
|
||||
HashRange hashRange = new HashRange(33L,33L);
|
||||
long l = hashRange.applyAsLong(93874L);
|
||||
assertThat(l).isEqualTo(33L);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user