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

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

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

BitSet.previousSetBit介绍

[英]Returns the index of the first bit that is set on or before index, or -1 if no lower bits are set or index == -1.
[中]返回在索引上或之前设置的第一位的索引,如果未设置较低的位,则返回-1,或者返回索引==-1。

代码示例

代码示例来源:origin: apache/geode

  1. ReceivedVersionsReverseIteratorB() {
  2. this.index = -1;
  3. if (received == null) {
  4. nextIndex = -1;
  5. } else {
  6. this.nextIndex = received.previousSetBit((int) (nextVersion - receivedBaseVersion - 1));
  7. if (nextIndex + receivedBaseVersion <= previousVersion) {
  8. nextIndex = -1;
  9. }
  10. }
  11. }

代码示例来源:origin: apache/geode

  1. @Override
  2. long next() {
  3. this.index = this.nextIndex;
  4. if (this.index < 0) {
  5. throw new NoSuchElementException("no more elements available");
  6. }
  7. this.nextIndex = received.previousSetBit(this.index - 1);
  8. if (nextIndex + receivedBaseVersion <= previousVersion) {
  9. nextIndex = -1;
  10. }
  11. return this.index + receivedBaseVersion;
  12. }

代码示例来源:origin: com.h2database/h2

  1. /**
  2. * Get the position of the last (infinite) free space.
  3. *
  4. * @return the position.
  5. */
  6. public long getLastFree() {
  7. return getPos(set.previousSetBit(set.size()-1) + 1);
  8. }

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

  1. @Override
  2. public List<Variable> next() {
  3. BitSet resultBitSet = (BitSet) nextBitSet.clone();
  4. int b = nextBitSet.previousClearBit(n - 1);
  5. int b1 = nextBitSet.previousSetBit(b);
  6. if (b1 == -1) {
  7. advanceToNextK();
  8. } else {
  9. nextBitSet.clear(b1);
  10. nextBitSet.set(b1 + 1, b1 + (n - b) + 1);
  11. nextBitSet.clear(b1 + (n - b) + 1, n);
  12. }
  13. resultList.clear();
  14. for (int i = 0; i < n; ++i) {
  15. if (resultBitSet.get(i)) {
  16. resultList.add(permuteThis.get(i));
  17. }
  18. }
  19. return unmodifyableViewOfResult;
  20. }
  21. }

代码示例来源:origin: apache/hive

  1. int lastValidIndex = selectedBitSet.previousSetBit(size - 1);
  2. RecordIdentifier lastRecordIdInBatch =
  3. new RecordIdentifier(

代码示例来源:origin: apache/drill

  1. int lastValidIndex = selectedBitSet.previousSetBit(batch.size - 1);
  2. RecordIdentifier lastRecordIdInBatch =
  3. new RecordIdentifier(

代码示例来源:origin: vsch/flexmark-java

  1. public int previousSetBit(int i) {return myBits.previousSetBit(i);}
  2. public int previousClearBit(int i) {return myBits.previousClearBit(i);}

代码示例来源:origin: vsch/flexmark-java

  1. @Override
  2. public Integer next() {
  3. if (myNext == -1) {
  4. throw new NoSuchElementException();
  5. }
  6. myLast = myNext;
  7. myNext = myIsReversed ? (myNext == 0 ? -1 : myBitSet.previousSetBit(myNext - 1)) : myBitSet.nextSetBit(myNext + 1);
  8. return myLast;
  9. }

代码示例来源:origin: vsch/flexmark-java

  1. public BitSetIterator(BitSet bitSet, boolean reversed) {
  2. myBitSet = bitSet;
  3. myIsReversed = reversed;
  4. myNext = reversed ? bitSet.previousSetBit(bitSet.length()) : bitSet.nextSetBit(0);
  5. myLast = -1;
  6. }

代码示例来源:origin: vsch/flexmark-java

  1. public int cardinality(int start, int end) {
  2. int count = 0;
  3. if (start >= 0 && end > 0 && start < end) {
  4. int firstBit = myBits.nextSetBit(0);
  5. int lastBit = myBits.previousSetBit(myBits.length()) + 1;
  6. if (start < firstBit) start = firstBit;
  7. if (end > lastBit) end = lastBit;
  8. if (start <= end && myBits.length() > 0) {
  9. int startIndex = start >> 6;
  10. int endIndex = end >> 6;
  11. long startMask = -1L << (start & 63); // 0-FF, 1-FE, 2-FC, 3-FE, 4-F0....
  12. long endMask = ~(-1L << (end & 63)); // 0-0, 1-01, 2-03, 3-07
  13. if (endMask == 0) {
  14. endIndex--;
  15. endMask = -1L;
  16. }
  17. long[] words = myBits.toLongArray();
  18. for (int i = startIndex; i <= endIndex; i++) {
  19. long word = words[i];
  20. if (i == startIndex) word &= startMask;
  21. if (i == endIndex) word &= endMask;
  22. count += Long.bitCount(word);
  23. }
  24. }
  25. }
  26. return count;
  27. }

代码示例来源:origin: vsch/flexmark-java

  1. boolean changed = false;
  2. while (index-- > 0) {
  3. index = removeSet.previousSetBit(index);
  4. if (index == -1) break;
  5. remove(myValueList.get(index));

代码示例来源:origin: mzheravin/exchange-core

  1. private boolean updateMaxBidPriceHot(int idx) {
  2. int nextIdx = hotBidBitSet.previousSetBit(idx);
  3. if (nextIdx == -1) {
  4. // not found, have to also check far area
  5. return true;
  6. }
  7. // found new maxBidPrice in hot bitset
  8. maxBidPrice = nextIdx + basePrice;
  9. return false;
  10. }

代码示例来源:origin: mebigfatguy/fb-contrib

  1. /**
  2. * returns whether the last downward branching jump seen crosses over the current location
  3. *
  4. * @param pc
  5. * the current location
  6. * @return if the last if statement branched over here
  7. */
  8. private boolean gotoAcrossPC(int pc) {
  9. int target = gotoBranchPCs.previousSetBit(Integer.MAX_VALUE);
  10. return (target > pc);
  11. }

代码示例来源:origin: com.vladsch.flexmark/flexmark-util

  1. public BitSetIterator(BitSet bitSet, boolean reversed) {
  2. myBitSet = bitSet;
  3. myIsReversed = reversed;
  4. myNext = reversed ? bitSet.previousSetBit(bitSet.length()) : bitSet.nextSetBit(0);
  5. myLast = -1;
  6. }

代码示例来源:origin: com.vladsch.flexmark/flexmark-util

  1. @Override
  2. public Integer next() {
  3. if (myNext == -1) {
  4. throw new NoSuchElementException();
  5. }
  6. myLast = myNext;
  7. myNext = myIsReversed ? (myNext == 0 ? -1 : myBitSet.previousSetBit(myNext - 1)) : myBitSet.nextSetBit(myNext + 1);
  8. return myLast;
  9. }

代码示例来源:origin: chocoteam/choco-solver

  1. @Override
  2. public int max() {
  3. if(isEmpty()) throw new IllegalStateException("cannot find maximum of an empty set");
  4. return offset+values.previousSetBit(values.length());
  5. }

代码示例来源:origin: stackoverflow.com

  1. int maxNumberOfConsecutiveBits(BitSet bs) {
  2. int maxLength = 0;
  3. int onesI = bs.length(); // Points to the prior 0.
  4. for (int i = onesI; (i = bs.previousClearBit(i - 1)) >= 0; ) {
  5. int length = onesI - 1 - i;
  6. maxLength = Math.max(maxLength, length);
  7. i = bs.previousSetBit(i - 1) + 1; // Heuristic, optional.
  8. onesI = i;
  9. }
  10. return maxLength;
  11. }

代码示例来源:origin: com.h2database/h2-mvstore

  1. /**
  2. * Get the position of the last (infinite) free space.
  3. *
  4. * @return the position.
  5. */
  6. public long getLastFree() {
  7. return getPos(set.previousSetBit(set.size()-1) + 1);
  8. }

代码示例来源:origin: org.codelibs.elasticsearch.module/lang-painless

  1. /**
  2. * Finds the start of the first statement boundary that is on or before {@code offset}. If one is not found, {@code -1} is returned.
  3. */
  4. default int getPreviousStatement(int offset) {
  5. return getStatements().previousSetBit(offset);
  6. }

代码示例来源:origin: org.jetbrains.xodus/xodus-utils

  1. @SuppressWarnings("unchecked")
  2. @Override
  3. public PersistentLongMap.Entry<V> next() {
  4. if (!hasNext()) {
  5. throw new NoSuchElementException();
  6. }
  7. final int index = this.next;
  8. final long key = index + currentEntryBase;
  9. final Object result = currentEntry.data[index];
  10. this.next = currentEntry.bits.previousSetBit(index - 1);
  11. return new LongMapEntry<>(key, (V) result);
  12. }

相关文章