public long decode ( final BitInputStream in , final long max ) throws IOException { if ( 0 == max ) { return 0 ; } int bits = ( int ) ( Math . round ( log2 ( 2 * this . stdDev ) ) - 1 ) ; if ( 0 > bits ) { bits = 0 ; } final long centralWindow = 1l << bits ; if ( centralWindow >= ( max + 1 ) / 2. ) { return in . readBoundedLong ( max + 1 ) ; } long stdDevWindowStart = ( long ) ( this . mean - centralWindow / 2 ) ; long stdDevWindowEnd = stdDevWindowStart + centralWindow ; if ( stdDevWindowStart < 0 ) { stdDevWindowEnd += - stdDevWindowStart ; stdDevWindowStart += - stdDevWindowStart ; } else { final long delta = stdDevWindowEnd - ( max + 1 ) ; if ( delta > 0 ) { stdDevWindowStart -= delta ; stdDevWindowEnd -= delta ; } } if ( in . readBool ( ) ) { return in . readBoundedLong ( centralWindow ) + stdDevWindowStart ; } else { boolean side ; if ( stdDevWindowStart <= 0 ) { side = true ; } else if ( stdDevWindowEnd > max ) { side = false ; } else { side = in . readBool ( ) ; } if ( side ) { return stdDevWindowEnd + in . readBoundedLong ( 1 + max - stdDevWindowEnd ) ; } else { return in . readBoundedLong ( stdDevWindowStart ) ; } } }
Decode long .