EstimatedHistogram: Support empty histogram

When creating an estimated histogram from buckets it is a valid option
to get a zero size array as the buckets array.

In that case the newOffsets method would get a negative value for its
size, which should result in a zero length array of offsets.

Signed-off-by: Amnon Heiman <amnon@scylladb.com>
This commit is contained in:
Amnon Heiman 2015-11-19 11:52:17 +02:00
parent 5362b2045d
commit e0dea0c27e

View File

@ -74,6 +74,9 @@ public class EstimatedHistogram {
} }
private static long[] newOffsets(int size) { private static long[] newOffsets(int size) {
if (size <= 0) {
return new long[0];
}
long[] result = new long[size]; long[] result = new long[size];
long last = 1; long last = 1;
result[0] = last; result[0] = last;