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

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

本文整理了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

ReceivedVersionsReverseIteratorB() {
 this.index = -1;
 if (received == null) {
  nextIndex = -1;
 } else {
  this.nextIndex = received.previousSetBit((int) (nextVersion - receivedBaseVersion - 1));
  if (nextIndex + receivedBaseVersion <= previousVersion) {
   nextIndex = -1;
  }
 }
}

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

@Override
long next() {
 this.index = this.nextIndex;
 if (this.index < 0) {
  throw new NoSuchElementException("no more elements available");
 }
 this.nextIndex = received.previousSetBit(this.index - 1);
 if (nextIndex + receivedBaseVersion <= previousVersion) {
  nextIndex = -1;
 }
 return this.index + receivedBaseVersion;
}

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

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

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

@Override
  public List<Variable> next() {
    BitSet resultBitSet = (BitSet) nextBitSet.clone();
    int b = nextBitSet.previousClearBit(n - 1);
    int b1 = nextBitSet.previousSetBit(b);
    if (b1 == -1) {
      advanceToNextK();
    } else {
      nextBitSet.clear(b1);
      nextBitSet.set(b1 + 1, b1 + (n - b) + 1);
      nextBitSet.clear(b1 + (n - b) + 1, n);
    }
    resultList.clear();
    for (int i = 0; i < n; ++i) {
      if (resultBitSet.get(i)) {
        resultList.add(permuteThis.get(i));
      }
    }
    return unmodifyableViewOfResult;
  }
}

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

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

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

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

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

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

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

@Override
public Integer next() {
  if (myNext == -1) {
    throw new NoSuchElementException();
  }
  myLast = myNext;
  myNext = myIsReversed ? (myNext == 0 ? -1 : myBitSet.previousSetBit(myNext - 1)) : myBitSet.nextSetBit(myNext + 1);
  return myLast;
}

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

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

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

public int cardinality(int start, int end) {
  int count = 0;
  if (start >= 0 && end > 0 && start < end) {
    int firstBit = myBits.nextSetBit(0);
    int lastBit = myBits.previousSetBit(myBits.length()) + 1;
    if (start < firstBit) start = firstBit;
    if (end > lastBit) end = lastBit;
    if (start <= end && myBits.length() > 0) {
      int startIndex = start >> 6;
      int endIndex = end >> 6;
      long startMask = -1L << (start & 63); // 0-FF, 1-FE, 2-FC, 3-FE, 4-F0....
      long endMask = ~(-1L << (end & 63)); // 0-0, 1-01, 2-03, 3-07
      if (endMask == 0) {
        endIndex--;
        endMask = -1L;
      }
      long[] words = myBits.toLongArray();
      for (int i = startIndex; i <= endIndex; i++) {
        long word = words[i];
        if (i == startIndex) word &= startMask;
        if (i == endIndex) word &= endMask;
        count += Long.bitCount(word);
      }
    }
  }
  return count;
}

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

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

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

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

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

/**
 * returns whether the last downward branching jump seen crosses over the current location
 *
 * @param pc
 *            the current location
 * @return if the last if statement branched over here
 */
private boolean gotoAcrossPC(int pc) {
  int target = gotoBranchPCs.previousSetBit(Integer.MAX_VALUE);
  return (target > pc);
}

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

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

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

@Override
public Integer next() {
  if (myNext == -1) {
    throw new NoSuchElementException();
  }
  myLast = myNext;
  myNext = myIsReversed ? (myNext == 0 ? -1 : myBitSet.previousSetBit(myNext - 1)) : myBitSet.nextSetBit(myNext + 1);
  return myLast;
}

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

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

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

int maxNumberOfConsecutiveBits(BitSet bs) {
  int maxLength = 0;
  int onesI = bs.length(); // Points to the prior 0.
  for (int i = onesI; (i = bs.previousClearBit(i - 1)) >= 0; ) {
    int length = onesI - 1 - i;
    maxLength = Math.max(maxLength, length);
    i = bs.previousSetBit(i - 1) + 1; // Heuristic, optional.
    onesI = i;
  }
  return maxLength;
}

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

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

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

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

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

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

相关文章