final int expectedByteCount = (int) Math.ceil(totalPrecision / 8.0);
if (expectedByteCount <= 0) {
// special case for no precision
return new RangeDecomposition(
new ByteArrayRange[] {
new ByteArrayRange(
new ByteArrayId(
new byte[] {}),
new ByteArrayId(
new byte[] {}))
});
}
for (int i = 0; i < hilbertRanges.size(); i++) {
final FilteredIndexRange<BigIntegerRange, BigIntegerRange> range = hilbertRanges.get(i);
// sanity check that values fit within the expected range
// it seems that uzaygezen can produce a value at 2^totalPrecision
// rather than 2^totalPrecision - 1
final BigInteger startValue = clamp(
minHilbertValue,
maxHilbertValue,
range.getIndexRange().getStart());
final BigInteger endValue = clamp(
minHilbertValue,
maxHilbertValue,
range.getIndexRange().getEnd().subtract(BigInteger.ONE));
// make sure its padded if necessary
final byte[] start = HilbertSFC.fitExpectedByteCount(
expectedByteCount,
startValue.toByteArray());
// make sure its padded if necessary
final byte[] end = HilbertSFC.fitExpectedByteCount(
expectedByteCount,
endValue.toByteArray());
sfcRanges[i] = new ByteArrayRange(
new ByteArrayId(
start),
new ByteArrayId(
end));
}