java.util.BitSet.checkIndex()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(7.1k)|赞(0)|评价(0)|浏览(124)

本文整理了Java中java.util.BitSet.checkIndex()方法的一些代码示例,展示了BitSet.checkIndex()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。BitSet.checkIndex()方法的具体详情如下:
包路径:java.util.BitSet
类名称:BitSet
方法名:checkIndex

BitSet.checkIndex介绍

暂无

代码示例

代码示例来源:origin: robovm/robovm

/**
 * Returns the bit at index {@code index}. Indexes greater than the current length return false.
 *
 * @throws IndexOutOfBoundsException if {@code index < 0}.
 */
public boolean get(int index) {
  if (index < 0) { // TODO: until we have an inlining JIT.
    checkIndex(index);
  }
  int arrayIndex = index / 64;
  if (arrayIndex >= longCount) {
    return false;
  }
  return (bits[arrayIndex] & (1L << index)) != 0;
}

代码示例来源:origin: robovm/robovm

/**
 * Returns the index of the first bit that is set on or before {@code index}, or -1 if
 * no lower bits are set or {@code index == -1}.
 * @throws IndexOutOfBoundsException if {@code index < -1}.
 * @since 1.7
 */
public int previousSetBit(int index) {
  if (index == -1) {
    return -1;
  }
  checkIndex(index);
  // TODO: optimize this.
  for (int i = index; i >= 0; --i) {
    if (get(i)) {
      return i;
    }
  }
  return -1;
}

代码示例来源:origin: robovm/robovm

/**
 * Returns the index of the first bit that is clear on or before {@code index}, or -1 if
 * no lower bits are clear or {@code index == -1}.
 * @throws IndexOutOfBoundsException if {@code index < -1}.
 * @since 1.7
 */
public int previousClearBit(int index) {
  if (index == -1) {
    return -1;
  }
  checkIndex(index);
  // TODO: optimize this.
  for (int i = index; i >= 0; --i) {
    if (!get(i)) {
      return i;
    }
  }
  return -1;
}

代码示例来源:origin: robovm/robovm

/**
 * Returns the index of the first bit that is clear on or after {@code index}.
 * Since all bits past the end are implicitly clear, this never returns -1.
 * @throws IndexOutOfBoundsException if {@code index < 0}.
 */
public int nextClearBit(int index) {
  checkIndex(index);
  int arrayIndex = index / 64;
  if (arrayIndex >= longCount) {
    return index;
  }
  long mask = ALL_ONES << index;
  if ((~bits[arrayIndex] & mask) != 0) {
    return 64 * arrayIndex + Long.numberOfTrailingZeros(~bits[arrayIndex] & mask);
  }
  while (++arrayIndex < longCount && bits[arrayIndex] == ALL_ONES) {
  }
  if (arrayIndex == longCount) {
    return 64 * longCount;
  }
  return 64 * arrayIndex + Long.numberOfTrailingZeros(~bits[arrayIndex]);
}

代码示例来源:origin: robovm/robovm

/**
 * Returns the index of the first bit that is set on or after {@code index}, or -1
 * if no higher bits are set.
 * @throws IndexOutOfBoundsException if {@code index < 0}.
 */
public int nextSetBit(int index) {
  checkIndex(index);
  int arrayIndex = index / 64;
  if (arrayIndex >= longCount) {
    return -1;
  }
  long mask = ALL_ONES << index;
  if ((bits[arrayIndex] & mask) != 0) {
    return 64 * arrayIndex + Long.numberOfTrailingZeros(bits[arrayIndex] & mask);
  }
  while (++arrayIndex < longCount && bits[arrayIndex] == 0) {
  }
  if (arrayIndex == longCount) {
    return -1;
  }
  return 64 * arrayIndex + Long.numberOfTrailingZeros(bits[arrayIndex]);
}

代码示例来源:origin: robovm/robovm

/**
 * Sets the bit at index {@code index} to true.
 *
 * @throws IndexOutOfBoundsException if {@code index < 0}.
 */
public void set(int index) {
  if (index < 0) { // TODO: until we have an inlining JIT.
    checkIndex(index);
  }
  int arrayIndex = index / 64;
  if (arrayIndex >= bits.length) {
    ensureCapacity(arrayIndex + 1);
  }
  bits[arrayIndex] |= (1L << index);
  longCount = Math.max(longCount, arrayIndex + 1);
}

代码示例来源:origin: robovm/robovm

/**
 * Clears the bit at index {@code index}.
 *
 * @throws IndexOutOfBoundsException if {@code index < 0}.
 */
public void clear(int index) {
  if (index < 0) { // TODO: until we have an inlining JIT.
    checkIndex(index);
  }
  int arrayIndex = index / 64;
  if (arrayIndex >= longCount) {
    return;
  }
  bits[arrayIndex] &= ~(1L << index);
  shrinkSize();
}

代码示例来源:origin: robovm/robovm

/**
 * Flips the bit at index {@code index}.
 *
 * @throws IndexOutOfBoundsException if {@code index < 0}.
 */
public void flip(int index) {
  if (index < 0) { // TODO: until we have an inlining JIT.
    checkIndex(index);
  }
  int arrayIndex = index / 64;
  if (arrayIndex >= bits.length) {
    ensureCapacity(arrayIndex + 1);
  }
  bits[arrayIndex] ^= (1L << index);
  longCount = Math.max(longCount, arrayIndex + 1);
  shrinkSize();
}

代码示例来源:origin: ibinti/bugvm

/**
 * Returns the bit at index {@code index}. Indexes greater than the current length return false.
 *
 * @throws IndexOutOfBoundsException if {@code index < 0}.
 */
public boolean get(int index) {
  if (index < 0) { // TODO: until we have an inlining JIT.
    checkIndex(index);
  }
  int arrayIndex = index / 64;
  if (arrayIndex >= longCount) {
    return false;
  }
  return (bits[arrayIndex] & (1L << index)) != 0;
}

代码示例来源:origin: MobiVM/robovm

/**
 * Returns the bit at index {@code index}. Indexes greater than the current length return false.
 *
 * @throws IndexOutOfBoundsException if {@code index < 0}.
 */
public boolean get(int index) {
  if (index < 0) { // TODO: until we have an inlining JIT.
    checkIndex(index);
  }
  int arrayIndex = index / 64;
  if (arrayIndex >= longCount) {
    return false;
  }
  return (bits[arrayIndex] & (1L << index)) != 0;
}

代码示例来源:origin: FlexoVM/flexovm

/**
 * Returns the bit at index {@code index}. Indexes greater than the current length return false.
 *
 * @throws IndexOutOfBoundsException if {@code index < 0}.
 */
public boolean get(int index) {
  if (index < 0) { // TODO: until we have an inlining JIT.
    checkIndex(index);
  }
  int arrayIndex = index / 64;
  if (arrayIndex >= longCount) {
    return false;
  }
  return (bits[arrayIndex] & (1L << index)) != 0;
}

代码示例来源:origin: junkdog/artemis-odb

public void set(int bitIndex) {
  checkIndex(bitIndex);
  set(array, bitIndex);
}

代码示例来源:origin: junkdog/artemis-odb

public void clear(int bitIndex) {
  checkIndex(bitIndex);
  clear(array, bitIndex);
}

代码示例来源:origin: junkdog/artemis-odb

public boolean get(int bitIndex) {
  checkIndex(bitIndex);
  return get(array, bitIndex);
}

代码示例来源:origin: junkdog/artemis-odb

public void flip(int bitIndex) {
  checkIndex(bitIndex);
  flip(array, bitIndex);
}

代码示例来源:origin: MobiVM/robovm

/**
 * Sets the bit at index {@code index} to true.
 *
 * @throws IndexOutOfBoundsException if {@code index < 0}.
 */
public void set(int index) {
  if (index < 0) { // TODO: until we have an inlining JIT.
    checkIndex(index);
  }
  int arrayIndex = index / 64;
  if (arrayIndex >= bits.length) {
    ensureCapacity(arrayIndex + 1);
  }
  bits[arrayIndex] |= (1L << index);
  longCount = Math.max(longCount, arrayIndex + 1);
}

代码示例来源:origin: ibinti/bugvm

/**
 * Sets the bit at index {@code index} to true.
 *
 * @throws IndexOutOfBoundsException if {@code index < 0}.
 */
public void set(int index) {
  if (index < 0) { // TODO: until we have an inlining JIT.
    checkIndex(index);
  }
  int arrayIndex = index / 64;
  if (arrayIndex >= bits.length) {
    ensureCapacity(arrayIndex + 1);
  }
  bits[arrayIndex] |= (1L << index);
  longCount = Math.max(longCount, arrayIndex + 1);
}

代码示例来源:origin: com.jtransc/jtransc-rt

/**
 * Sets the bit at index {@code index} to true.
 *
 * @throws IndexOutOfBoundsException if {@code index < 0}.
 */
public void set(int index) {
  if (index < 0) { // TODO: until we have an inlining JIT.
    checkIndex(index);
  }
  int arrayIndex = index / 64;
  if (arrayIndex >= bits.length) {
    ensureCapacity(arrayIndex + 1);
  }
  bits[arrayIndex] |= (1L << index);
  longCount = Math.max(longCount, arrayIndex + 1);
}

代码示例来源:origin: com.mobidevelop.robovm/robovm-rt

/**
 * Clears the bit at index {@code index}.
 *
 * @throws IndexOutOfBoundsException if {@code index < 0}.
 */
public void clear(int index) {
  if (index < 0) { // TODO: until we have an inlining JIT.
    checkIndex(index);
  }
  int arrayIndex = index / 64;
  if (arrayIndex >= longCount) {
    return;
  }
  bits[arrayIndex] &= ~(1L << index);
  shrinkSize();
}

代码示例来源:origin: com.mobidevelop.robovm/robovm-rt

/**
 * Flips the bit at index {@code index}.
 *
 * @throws IndexOutOfBoundsException if {@code index < 0}.
 */
public void flip(int index) {
  if (index < 0) { // TODO: until we have an inlining JIT.
    checkIndex(index);
  }
  int arrayIndex = index / 64;
  if (arrayIndex >= bits.length) {
    ensureCapacity(arrayIndex + 1);
  }
  bits[arrayIndex] ^= (1L << index);
  longCount = Math.max(longCount, arrayIndex + 1);
  shrinkSize();
}

相关文章