// determine next symbol
// calculate the % of the value within the range
long range = (high - low + 1) >>> model.log2MaxCount();
int currentSymbolCount = (int) ((value - low) / range);
SymbolInfo symbolInfo = model.countToSymbol(currentSymbolCount);
high = low + (range * symbolInfo.highCount()) - 1;
low = low + range * symbolInfo.lowCount();
// if high bytes are equal, remove high byte and add a new byte of input
while ((high & 0xFF0000000000L) == (low & 0xFF0000000000L)) {
bufferByte();
}
// handle possible underflow
// if top two bytes differ by only one digit
if ((high >> 32) - (low >> 32) == 1) {
// if second highest bytes are 0x00 on the high and 0xFF
// on the low, we need to deal with underflow
while ((high & 0x00FF00000000L) == 0 && (low & 0x00FF00000000L) == 0x00FF00000000L) {
// remove second chunk of low and high (shifting over lower bits)
low = removeUnderflowByte(low);
high = removeUnderflowByte(high);
value = removeUnderflowByte(value);
// add a new byte
bufferByte();
}
}
low &= 0xFFFFFFFFFFFFL;
high &= 0xFFFFFFFFFFFFL;
value &= 0xFFFFFFFFFFFFL;
return symbolInfo.symbol();
}