private static RoaringBitmap selectRangeWithoutCopy ( RoaringBitmap rb , final long rangeStart , final long rangeEnd ) { final int hbStart = Util . toIntUnsigned ( Util . highbits ( rangeStart ) ) ; final int lbStart = Util . toIntUnsigned ( Util . lowbits ( rangeStart ) ) ; final int hbLast = Util . toIntUnsigned ( Util . highbits ( rangeEnd - 1 ) ) ; final int lbLast = Util . toIntUnsigned ( Util . lowbits ( rangeEnd - 1 ) ) ; RoaringBitmap answer = new RoaringBitmap ( ) ; assert ( rangeStart >= 0 && rangeEnd >= 0 ) ; if ( rangeEnd <= rangeStart ) { return answer ; } if ( hbStart == hbLast ) { final int i = rb . highLowContainer . getIndex ( ( short ) hbStart ) ; if ( i >= 0 ) { final Container c = rb . highLowContainer . getContainerAtIndex ( i ) . remove ( 0 , lbStart ) . iremove ( lbLast + 1 , Util . maxLowBitAsInteger ( ) + 1 ) ; if ( ! c . isEmpty ( ) ) { answer . highLowContainer . append ( ( short ) hbStart , c ) ; } } return answer ; } int ifirst = rb . highLowContainer . getIndex ( ( short ) hbStart ) ; int ilast = rb . highLowContainer . getIndex ( ( short ) hbLast ) ; if ( ifirst >= 0 ) { final Container c = rb . highLowContainer . getContainerAtIndex ( ifirst ) . remove ( 0 , lbStart ) ; if ( ! c . isEmpty ( ) ) { answer . highLowContainer . append ( ( short ) hbStart , c ) ; } } // revised to loop on ints for ( int hb = hbStart + 1 ; hb <= hbLast - 1 ; ++ hb ) { final int i = rb . highLowContainer . getIndex ( ( short ) hb ) ; final int j = answer . highLowContainer . getIndex ( ( short ) hb ) ; assert j < 0 ; if ( i >= 0 ) { final Container c = rb . highLowContainer . getContainerAtIndex ( i ) ; answer . highLowContainer . insertNewKeyValueAt ( - j - 1 , ( short ) hb , c ) ; } } if ( ilast >= 0 ) { final Container c = rb . highLowContainer . getContainerAtIndex ( ilast ) . remove ( lbLast + 1 , Util . maxLowBitAsInteger ( ) + 1 ) ; if ( ! c . isEmpty ( ) ) { answer . highLowContainer . append ( ( short ) hbLast , c ) ; } } return answer ; }
had formerly failed if rangeEnd == 0