public void flip ( long startIndex , long endIndex ) { if ( endIndex <= startIndex ) return ; int startWord = ( int ) ( startIndex >> 6 ) ; // since endIndex is one past the end, this is index of the last // word to be changed. int endWord = expandingWordNum ( endIndex - 1 ) ; long startmask = - 1L << startIndex ; long endmask = - 1L >>> - endIndex ; // 64-(endIndex&0x3f) is the same as -endIndex // due to wrap if ( startWord == endWord ) { bits [ startWord ] ^= ( startmask & endmask ) ; return ; } bits [ startWord ] ^= startmask ; for ( int i = startWord + 1 ; i < endWord ; i ++ ) { bits [ i ] = ~ bits [ i ] ; } bits [ endWord ] ^= endmask ; }
Flips a range of bits expanding the set size if necessary