long prevSetBit ( long index ) { assert index >= 0 && index < numBits : "index=" + index + " numBits=" + numBits ; int i = ( int ) ( index >> 6 ) ; final int subIndex = ( int ) ( index & 0x3f ) ; // index within the word long word = ( bits [ i ] << ( 63 - subIndex ) ) ; // skip all the bits to the // left of index if ( word != 0 ) { return ( i << 6 ) + subIndex - Long . numberOfLeadingZeros ( word ) ; // See // LUCENE-3197 } while ( -- i >= 0 ) { word = bits [ i ] ; if ( word != 0 ) { return ( i << 6 ) + 63 - Long . numberOfLeadingZeros ( word ) ; } } return - 1 ; }
Returns the index of the last set bit before or on the index specified . - 1 is returned if there are no more set bits .