@Override
  public int indexOf(int e)
  {
    if (e < 0) {
      throw new IllegalArgumentException("positive integer expected: " + Integer.toString(e));
    }
    if (isEmpty()) {
      return -1;
    }

    // returned value
    int index = 0;

    int blockIndex = maxLiteralLengthDivision(e);
    int bitPosition = maxLiteralLengthModulus(e);
    for (int i = 0; i <= lastWordIndex && blockIndex >= 0; i++) {
      int w = words[i];
      if (isLiteral(w)) {
        // check if the current literal word is the "right" one
        if (blockIndex == 0) {
          if ((w & (1 << bitPosition)) == 0) {
            return -1;
          }
          return index + Integer.bitCount(w & ~(0xFFFFFFFF << bitPosition));
        }
        blockIndex--;
        index += getLiteralBitCount(w);
      } else {
        if (simulateWAH) {
          if (isOneSequence(w) && blockIndex <= getSequenceCount(w)) {
            return index + maxLiteralLengthMultiplication(blockIndex) + bitPosition;
          }
        } else {
          // if we are at the beginning of a sequence, and it is
          // a set bit, the bit already exists
          if (blockIndex == 0) {
            int l = getLiteral(w);
            if ((l & (1 << bitPosition)) == 0) {
              return -1;
            }
            return index + Integer.bitCount(l & ~(0xFFFFFFFF << bitPosition));
          }

          // if we are in the middle of a sequence of 1's, the bit already exist
          if (blockIndex > 0
              && blockIndex <= getSequenceCount(w)
              && isOneSequence(w)) {
            return index + maxLiteralLengthMultiplication(blockIndex) + bitPosition - (isSequenceWithNoBits(w) ? 0 : 1);
          }
        }

        // next word
        int blocks = getSequenceCount(w) + 1;
        blockIndex -= blocks;
        if (isZeroSequence(w)) {
          if (!simulateWAH && !isSequenceWithNoBits(w)) {
            index++;
          }
        } else {
          index += maxLiteralLengthMultiplication(blocks);
          if (!simulateWAH && !isSequenceWithNoBits(w)) {
            index--;
          }
        }
      }
    }

    // not found
    return -1;
  }
@ Override public int indexOf ( int e ) { if ( e < 0 ) { throw new IllegalArgumentException ( "positive integer expected: " + Integer . toString ( e ) ) ; } if ( isEmpty ( ) ) { return - 1 ; } int index = 0 ; int blockIndex = maxLiteralLengthDivision ( e ) ; int bitPosition = maxLiteralLengthModulus ( e ) ; for ( int i = 0 ; i <= lastWordIndex && blockIndex >= 0 ; i ++ ) { int w = words [ i ] ; if ( isLiteral ( w ) ) { if ( blockIndex == 0 ) { if ( ( w & ( 1 << bitPosition ) ) == 0 ) { return - 1 ; } return index + Integer . bitCount ( w & ~ ( 0xFFFFFFFF << bitPosition ) ) ; } blockIndex -- ; index += getLiteralBitCount ( w ) ; } else { if ( simulateWAH ) { if ( isOneSequence ( w ) && blockIndex <= getSequenceCount ( w ) ) { return index + maxLiteralLengthMultiplication ( blockIndex ) + bitPosition ; } } else { if ( blockIndex == 0 ) { int l = getLiteral ( w ) ; if ( ( l & ( 1 << bitPosition ) ) == 0 ) { return - 1 ; } return index + Integer . bitCount ( l & ~ ( 0xFFFFFFFF << bitPosition ) ) ; } if ( blockIndex > 0 && blockIndex <= getSequenceCount ( w ) && isOneSequence ( w ) ) { return index + maxLiteralLengthMultiplication ( blockIndex ) + bitPosition - ( isSequenceWithNoBits ( w ) ? 0 : 1 ) ; } } int blocks = getSequenceCount ( w ) + 1 ; blockIndex -= blocks ; if ( isZeroSequence ( w ) ) { if ( ! simulateWAH && ! isSequenceWithNoBits ( w ) ) { index ++ ; } } else { index += maxLiteralLengthMultiplication ( blocks ) ; if ( ! simulateWAH && ! isSequenceWithNoBits ( w ) ) { index -- ; } } } } return - 1 ; }
{@inheritDoc}