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

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

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

BitSet.checkIndex介绍

暂无

代码示例

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

  1. /**
  2. * Returns the bit at index {@code index}. Indexes greater than the current length return false.
  3. *
  4. * @throws IndexOutOfBoundsException if {@code index < 0}.
  5. */
  6. public boolean get(int index) {
  7. if (index < 0) { // TODO: until we have an inlining JIT.
  8. checkIndex(index);
  9. }
  10. int arrayIndex = index / 64;
  11. if (arrayIndex >= longCount) {
  12. return false;
  13. }
  14. return (bits[arrayIndex] & (1L << index)) != 0;
  15. }

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

  1. /**
  2. * Returns the index of the first bit that is set on or before {@code index}, or -1 if
  3. * no lower bits are set or {@code index == -1}.
  4. * @throws IndexOutOfBoundsException if {@code index < -1}.
  5. * @since 1.7
  6. */
  7. public int previousSetBit(int index) {
  8. if (index == -1) {
  9. return -1;
  10. }
  11. checkIndex(index);
  12. // TODO: optimize this.
  13. for (int i = index; i >= 0; --i) {
  14. if (get(i)) {
  15. return i;
  16. }
  17. }
  18. return -1;
  19. }

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

  1. /**
  2. * Returns the index of the first bit that is clear on or before {@code index}, or -1 if
  3. * no lower bits are clear or {@code index == -1}.
  4. * @throws IndexOutOfBoundsException if {@code index < -1}.
  5. * @since 1.7
  6. */
  7. public int previousClearBit(int index) {
  8. if (index == -1) {
  9. return -1;
  10. }
  11. checkIndex(index);
  12. // TODO: optimize this.
  13. for (int i = index; i >= 0; --i) {
  14. if (!get(i)) {
  15. return i;
  16. }
  17. }
  18. return -1;
  19. }

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

  1. /**
  2. * Returns the index of the first bit that is clear on or after {@code index}.
  3. * Since all bits past the end are implicitly clear, this never returns -1.
  4. * @throws IndexOutOfBoundsException if {@code index < 0}.
  5. */
  6. public int nextClearBit(int index) {
  7. checkIndex(index);
  8. int arrayIndex = index / 64;
  9. if (arrayIndex >= longCount) {
  10. return index;
  11. }
  12. long mask = ALL_ONES << index;
  13. if ((~bits[arrayIndex] & mask) != 0) {
  14. return 64 * arrayIndex + Long.numberOfTrailingZeros(~bits[arrayIndex] & mask);
  15. }
  16. while (++arrayIndex < longCount && bits[arrayIndex] == ALL_ONES) {
  17. }
  18. if (arrayIndex == longCount) {
  19. return 64 * longCount;
  20. }
  21. return 64 * arrayIndex + Long.numberOfTrailingZeros(~bits[arrayIndex]);
  22. }

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

  1. /**
  2. * Returns the index of the first bit that is set on or after {@code index}, or -1
  3. * if no higher bits are set.
  4. * @throws IndexOutOfBoundsException if {@code index < 0}.
  5. */
  6. public int nextSetBit(int index) {
  7. checkIndex(index);
  8. int arrayIndex = index / 64;
  9. if (arrayIndex >= longCount) {
  10. return -1;
  11. }
  12. long mask = ALL_ONES << index;
  13. if ((bits[arrayIndex] & mask) != 0) {
  14. return 64 * arrayIndex + Long.numberOfTrailingZeros(bits[arrayIndex] & mask);
  15. }
  16. while (++arrayIndex < longCount && bits[arrayIndex] == 0) {
  17. }
  18. if (arrayIndex == longCount) {
  19. return -1;
  20. }
  21. return 64 * arrayIndex + Long.numberOfTrailingZeros(bits[arrayIndex]);
  22. }

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

  1. /**
  2. * Sets the bit at index {@code index} to true.
  3. *
  4. * @throws IndexOutOfBoundsException if {@code index < 0}.
  5. */
  6. public void set(int index) {
  7. if (index < 0) { // TODO: until we have an inlining JIT.
  8. checkIndex(index);
  9. }
  10. int arrayIndex = index / 64;
  11. if (arrayIndex >= bits.length) {
  12. ensureCapacity(arrayIndex + 1);
  13. }
  14. bits[arrayIndex] |= (1L << index);
  15. longCount = Math.max(longCount, arrayIndex + 1);
  16. }

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

  1. /**
  2. * Clears the bit at index {@code index}.
  3. *
  4. * @throws IndexOutOfBoundsException if {@code index < 0}.
  5. */
  6. public void clear(int index) {
  7. if (index < 0) { // TODO: until we have an inlining JIT.
  8. checkIndex(index);
  9. }
  10. int arrayIndex = index / 64;
  11. if (arrayIndex >= longCount) {
  12. return;
  13. }
  14. bits[arrayIndex] &= ~(1L << index);
  15. shrinkSize();
  16. }

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

  1. /**
  2. * Flips the bit at index {@code index}.
  3. *
  4. * @throws IndexOutOfBoundsException if {@code index < 0}.
  5. */
  6. public void flip(int index) {
  7. if (index < 0) { // TODO: until we have an inlining JIT.
  8. checkIndex(index);
  9. }
  10. int arrayIndex = index / 64;
  11. if (arrayIndex >= bits.length) {
  12. ensureCapacity(arrayIndex + 1);
  13. }
  14. bits[arrayIndex] ^= (1L << index);
  15. longCount = Math.max(longCount, arrayIndex + 1);
  16. shrinkSize();
  17. }

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

  1. /**
  2. * Returns the bit at index {@code index}. Indexes greater than the current length return false.
  3. *
  4. * @throws IndexOutOfBoundsException if {@code index < 0}.
  5. */
  6. public boolean get(int index) {
  7. if (index < 0) { // TODO: until we have an inlining JIT.
  8. checkIndex(index);
  9. }
  10. int arrayIndex = index / 64;
  11. if (arrayIndex >= longCount) {
  12. return false;
  13. }
  14. return (bits[arrayIndex] & (1L << index)) != 0;
  15. }

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

  1. /**
  2. * Returns the bit at index {@code index}. Indexes greater than the current length return false.
  3. *
  4. * @throws IndexOutOfBoundsException if {@code index < 0}.
  5. */
  6. public boolean get(int index) {
  7. if (index < 0) { // TODO: until we have an inlining JIT.
  8. checkIndex(index);
  9. }
  10. int arrayIndex = index / 64;
  11. if (arrayIndex >= longCount) {
  12. return false;
  13. }
  14. return (bits[arrayIndex] & (1L << index)) != 0;
  15. }

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

  1. /**
  2. * Returns the bit at index {@code index}. Indexes greater than the current length return false.
  3. *
  4. * @throws IndexOutOfBoundsException if {@code index < 0}.
  5. */
  6. public boolean get(int index) {
  7. if (index < 0) { // TODO: until we have an inlining JIT.
  8. checkIndex(index);
  9. }
  10. int arrayIndex = index / 64;
  11. if (arrayIndex >= longCount) {
  12. return false;
  13. }
  14. return (bits[arrayIndex] & (1L << index)) != 0;
  15. }

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

  1. public void set(int bitIndex) {
  2. checkIndex(bitIndex);
  3. set(array, bitIndex);
  4. }

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

  1. public void clear(int bitIndex) {
  2. checkIndex(bitIndex);
  3. clear(array, bitIndex);
  4. }

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

  1. public boolean get(int bitIndex) {
  2. checkIndex(bitIndex);
  3. return get(array, bitIndex);
  4. }

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

  1. public void flip(int bitIndex) {
  2. checkIndex(bitIndex);
  3. flip(array, bitIndex);
  4. }

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

  1. /**
  2. * Sets the bit at index {@code index} to true.
  3. *
  4. * @throws IndexOutOfBoundsException if {@code index < 0}.
  5. */
  6. public void set(int index) {
  7. if (index < 0) { // TODO: until we have an inlining JIT.
  8. checkIndex(index);
  9. }
  10. int arrayIndex = index / 64;
  11. if (arrayIndex >= bits.length) {
  12. ensureCapacity(arrayIndex + 1);
  13. }
  14. bits[arrayIndex] |= (1L << index);
  15. longCount = Math.max(longCount, arrayIndex + 1);
  16. }

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

  1. /**
  2. * Sets the bit at index {@code index} to true.
  3. *
  4. * @throws IndexOutOfBoundsException if {@code index < 0}.
  5. */
  6. public void set(int index) {
  7. if (index < 0) { // TODO: until we have an inlining JIT.
  8. checkIndex(index);
  9. }
  10. int arrayIndex = index / 64;
  11. if (arrayIndex >= bits.length) {
  12. ensureCapacity(arrayIndex + 1);
  13. }
  14. bits[arrayIndex] |= (1L << index);
  15. longCount = Math.max(longCount, arrayIndex + 1);
  16. }

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

  1. /**
  2. * Sets the bit at index {@code index} to true.
  3. *
  4. * @throws IndexOutOfBoundsException if {@code index < 0}.
  5. */
  6. public void set(int index) {
  7. if (index < 0) { // TODO: until we have an inlining JIT.
  8. checkIndex(index);
  9. }
  10. int arrayIndex = index / 64;
  11. if (arrayIndex >= bits.length) {
  12. ensureCapacity(arrayIndex + 1);
  13. }
  14. bits[arrayIndex] |= (1L << index);
  15. longCount = Math.max(longCount, arrayIndex + 1);
  16. }

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

  1. /**
  2. * Clears the bit at index {@code index}.
  3. *
  4. * @throws IndexOutOfBoundsException if {@code index < 0}.
  5. */
  6. public void clear(int index) {
  7. if (index < 0) { // TODO: until we have an inlining JIT.
  8. checkIndex(index);
  9. }
  10. int arrayIndex = index / 64;
  11. if (arrayIndex >= longCount) {
  12. return;
  13. }
  14. bits[arrayIndex] &= ~(1L << index);
  15. shrinkSize();
  16. }

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

  1. /**
  2. * Flips the bit at index {@code index}.
  3. *
  4. * @throws IndexOutOfBoundsException if {@code index < 0}.
  5. */
  6. public void flip(int index) {
  7. if (index < 0) { // TODO: until we have an inlining JIT.
  8. checkIndex(index);
  9. }
  10. int arrayIndex = index / 64;
  11. if (arrayIndex >= bits.length) {
  12. ensureCapacity(arrayIndex + 1);
  13. }
  14. bits[arrayIndex] ^= (1L << index);
  15. longCount = Math.max(longCount, arrayIndex + 1);
  16. shrinkSize();
  17. }

相关文章