add bounds checking on *Hash*Range functions

This commit is contained in:
Jonathan Shook 2023-06-06 14:26:25 -05:00
parent 525e1d2b66
commit 41ebd93530
8 changed files with 26 additions and 14 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 nosqlbench
* Copyright (c) 2022-2023 nosqlbench
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -58,6 +58,9 @@ public class HashRange implements LongToDoubleFunction {
private final Hash hash = new Hash();
public HashRange(double min, double max) {
if (min>max) {
throw new RuntimeException("min must be less than or equal to max");
}
this.min = min;
this.max = max;
this.interval = max - min;

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 nosqlbench
* Copyright (c) 2022-2023 nosqlbench
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -34,6 +34,9 @@ public class HashRange implements LongFunction<Float> {
private final Hash hash = new Hash();
public HashRange(float min, float max) {
if (min>max) {
throw new RuntimeException("max must be greater than or equal to min");
}
this.min = min;
this.max = max;
this.interval = max - min;

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 nosqlbench
* Copyright (c) 2022-2023 nosqlbench
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -34,6 +34,9 @@ public class AddHashRange implements LongToIntFunction {
}
public AddHashRange(int minValue, int maxValue) {
if (minValue>maxValue) {
throw new RuntimeException("minValue must be less than or equal to maxValue");
}
this.hashRange = new HashRange(minValue, maxValue);
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 nosqlbench
* Copyright (c) 2022-2023 nosqlbench
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -35,8 +35,7 @@ public class HashRange implements LongToIntFunction {
@Example({"HashRange(32L)","map the input to a number in the range 0-31, inclusive, of type int"})
public HashRange(int width) {
this.width=width;
this.minValue=0L;
this(0,width);
}
@Example({"HashRange(35L,39L)","map the input to a number in the range 35-38, inclusive, of type int"})

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 nosqlbench
* Copyright (c) 2022-2023 nosqlbench
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -33,6 +33,9 @@ public class AddHashRange implements LongUnaryOperator {
}
public AddHashRange(long minValue, long maxValue) {
if (minValue>maxValue) {
throw new RuntimeException("minValue must be less than or equal to maxValue");
}
this.hashRange = new HashRange(minValue, maxValue);
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 nosqlbench
* Copyright (c) 2022-2023 nosqlbench
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -41,8 +41,7 @@ public class HashRange implements LongUnaryOperator {
private final Hash hash = new Hash();
public HashRange(long width) {
this.minValue=0L;
this.width=width;
this(0L,width);
}
public HashRange(long minValue, long maxValue) {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 nosqlbench
* Copyright (c) 2022-2023 nosqlbench
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -36,6 +36,9 @@ public class AddHashRange implements IntUnaryOperator {
}
public AddHashRange(int minValue, int maxValue) {
if (minValue>maxValue) {
throw new RuntimeException("minValue must be equal to or greater than maxValue");
}
this.hashRange = new io.nosqlbench.virtdata.library.basics.shared.unary_int.HashRange(minValue, maxValue);
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 nosqlbench
* Copyright (c) 2022-2023 nosqlbench
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -32,8 +32,7 @@ public class HashRange implements IntUnaryOperator {
private final Hash hash = new Hash();
public HashRange(int width) {
this.minValue=0;
this.width=width;
this(0,width);
}
public HashRange(int minValue, int maxValue) {