示例#1
0
 // sets all bits at a certain index to the given value
 private static void setWord(JsArrayInteger array, int index, int value) {
   // keep 0s out of the array
   if (value == 0) {
     deleteWord(array, index);
   } else {
     array.set(index, value);
   }
 }
示例#2
0
  public void clear(int fromIndex, int toIndex) {
    checkRange(fromIndex, toIndex);

    int length = length();
    if (fromIndex >= length) {
      // nothing to do
      return;
    }

    // check to see if toIndex is greater than our array length
    if (toIndex >= length) {
      // truncate the array by setting it's length
      int newLength = wordIndex(fromIndex + 31);
      setLengthWords(array, newLength);

      // remove the extra bits off the end
      if ((bitIndex(newLength)) - fromIndex != 0) {
        maskOutWord(array, newLength - 1, bitOffset(fromIndex), 32);
      }

    } else {
      int first = wordIndex(fromIndex);
      int last = wordIndex(toIndex);
      int startBit = bitOffset(fromIndex);
      int endBit = bitOffset(toIndex);

      if (first == last) {
        // clear the bits in between first and last
        maskOutWord(array, first, startBit, endBit);

      } else {
        // clear the bits from fromIndex to the next 32 bit boundary
        if (startBit != 0) {
          maskOutWord(array, first++, startBit, 32);
        }

        // clear the bits from the last 32 bit boundary to the toIndex
        if (endBit != 0) {
          maskOutWord(array, last, 0, endBit);
        }

        //
        // delete everything in between
        //
        for (int i = first; i < last; i++) {
          deleteWord(array, i);
        }
      }
    }
  }