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

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

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

BitSet.clear介绍

[英]Clears all the bits in this BitSet. This method does not change the capacity. Use clear if you want to reuse this BitSet with the same capacity, but create a new BitSet if you're trying to potentially reclaim memory.
[中]清除此位集中的所有位。此方法不会更改容量。如果要以相同的容量重用此位集,请使用“清除”,但如果要尝试潜在地回收内存,请创建新位集。

代码示例

代码示例来源:origin: pxb1988/dex2jar

private void initSuggestColor(BitSet suggestColor, Reg as) {
  suggestColor.clear();
  for (Reg ex : as.prefers) {
    if (ex.reg >= 0) {
      suggestColor.set(ex.reg);
    }
  }
}

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

public synchronized boolean remove(Integer elementBit) {
  if (elementBit == null || !elementBits.get(elementBit)) {
    return false;
  }
  cache.remove(elementBit);
  elementBits.clear(elementBit);
  elementCount--;
  return true;
}

代码示例来源:origin: apache/incubator-druid

/**
 * Clear the info about which rows (in which original iterators and which row nums within them) were combined on
 * the previous step.
 */
private void clearCombinedRowsInfo()
{
 for (int originalIteratorIndex = indexesOfCurrentlyCombinedOriginalIterators.nextSetBit(0);
    originalIteratorIndex >= 0;
    originalIteratorIndex = indexesOfCurrentlyCombinedOriginalIterators.nextSetBit(originalIteratorIndex + 1)) {
  minCurrentlyCombinedRowNumByOriginalIteratorIndex[originalIteratorIndex] =
    MIN_CURRENTLY_COMBINED_ROW_NUM_UNSET_VALUE;
 }
 indexesOfCurrentlyCombinedOriginalIterators.clear();
}

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

public static BitSet computePrimes(int limit)
{
  final BitSet primes = new BitSet();
  primes.set(0, false);
  primes.set(1, false);
  primes.set(2, limit, true);
  for (int i = 0; i * i < limit; i++)
  {
    if (primes.get(i))
    {
      for (int j = i * i; j < limit; j += i)
      {
        primes.clear(j);
      }
    }
  }
  return primes;
}

代码示例来源:origin: goldmansachs/gs-collections

public boolean removeAtIndex(int index)
{
  boolean previous = this.get(index);
  if (this.size - index > 1)
  {
    for (int i = index; i < this.size; i++)
    {
      this.items.set(i, this.items.get(i + 1));
    }
  }
  --this.size;
  this.items.clear(this.size);
  return previous;
}

代码示例来源:origin: lettuce-io/lettuce-core

private void setSlotBits(List<Integer> slots) {
  if (slots.isEmpty() && this.slots == null) {
    return;
  }
  if (this.slots == null) {
    this.slots = new BitSet(SlotHash.SLOT_COUNT);
  }
  this.slots.clear();
  for (Integer slot : slots) {
    this.slots.set(slot);
  }
}

代码示例来源:origin: Sable/soot

@Override
protected void merge(ArrayState in1, ArrayState in2, ArrayState out) {
 out.active.clear();
 out.active.or(in1.active);
 out.active.or(in2.active);
 BitSet in2_excl = (BitSet) in2.active.clone();
 in2_excl.andNot(in1.active);
 for (int i = in1.active.nextSetBit(0); i >= 0; i = in1.active.nextSetBit(i + 1)) {
  if (in1.state[i] == null) {
   out.state[i] = null;
  } else if (in2.active.get(i)) {
   if (in2.state[i] == null) {
    out.state[i] = null;
   } else {
    out.state[i] = mergeTypeStates(in1.state[i], in2.state[i]);
   }
  } else {
   out.state[i] = in1.state[i];
  }
 }
 for (int i = in2_excl.nextSetBit(0); i >= 0; i = in2_excl.nextSetBit(i + 1)) {
  out.state[i] = in2.state[i];
 }
}

代码示例来源:origin: twitter/distributedlog

/**
 * Performs a deep copy on <i>other</i>.
 */
public AccessControlEntry(AccessControlEntry other) {
 __isset_bit_vector.clear();
 __isset_bit_vector.or(other.__isset_bit_vector);
 this.denyWrite = other.denyWrite;
 this.denyTruncate = other.denyTruncate;
 this.denyDelete = other.denyDelete;
 this.denyAcquire = other.denyAcquire;
 this.denyRelease = other.denyRelease;
}

代码示例来源:origin: commons-collections/commons-collections

/** 
 * Initializes the collating state if it hasn't been already.
 */
private void start() {
  if (values == null) {
    values = new ArrayList(iterators.size());
    valueSet = new BitSet(iterators.size());
    for (int i = 0; i < iterators.size(); i++) {
      values.add(null);
      valueSet.clear(i);
    }
  }
}

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

final BitSet parent2Key = second.getRepresentation();
final BitSet child1Key = new BitSet(length);
final BitSet child2Key = new BitSet(length);
a.clear(crossoverIndex, length);
BitSet b = (BitSet) parent2Key.clone();
b.clear(0, crossoverIndex);
c.clear(crossoverIndex, length);
BitSet d = (BitSet) parent2Key.clone();
d.clear(0, crossoverIndex);
child1Key.or(a);
child1Key.or(d);
child2Key.or(c);
child2Key.or(b);
return new ChromosomePair(first.newBitsChromosome(child1Key), second.newBitsChromosome(child2Key));

代码示例来源:origin: sonyxperiadev/ApkAnalyser

private void setPostRegisterTypeAndPropagateChanges(AnalyzedInstruction analyzedInstruction, int registerNumber,
                      RegisterType registerType) {
  BitSet changedInstructions = new BitSet(instructions.size());
    for (int instructionIndex=changedInstructions.nextSetBit(0);
         instructionIndex>=0;
         instructionIndex=changedInstructions.nextSetBit(instructionIndex+1)) {
      changedInstructions.clear(instructionIndex);

代码示例来源:origin: Sable/soot

protected void flowThrough(BitSet in, Unit unit, BitSet out) {
 out.clear();
 out.or(in);
 if (!out.get(indexOf(unit))) {
  out.set(indexOf(unit));
  // System.out.println("add to out: "+unit);
 } else {
  multiRunStatements.add(unit);
 }
 // System.out.println("in: "+in);
 // System.out.println("out: "+out);
}

代码示例来源:origin: eclipse/eclipse-collections

@Override
public boolean removeAtIndex(int index)
{
  boolean previous = this.get(index);
  if (this.size - index > 1)
  {
    for (int i = index; i < this.size; i++)
    {
      this.items.set(i, this.items.get(i + 1));
    }
  }
  --this.size;
  this.items.clear(this.size);
  return previous;
}

代码示例来源:origin: line/armeria

/**
 * Reservoir sampling algorithm borrowed from Stack Overflow.
 * https://stackoverflow.com/questions/12817946/generate-a-random-bitset-with-n-1s
 */
private static BitSet randomBitSet(int size, int cardinality, Random rnd) {
  final BitSet result = new BitSet(size);
  final int[] chosen = new int[cardinality];
  int i;
  for (i = 0; i < cardinality; ++i) {
    chosen[i] = i;
    result.set(i);
  }
  for (; i < size; ++i) {
    final int j = rnd.nextInt(i + 1);
    if (j < cardinality) {
      result.clear(chosen[j]);
      result.set(i);
      chosen[j] = i;
    }
  }
  return result;
}

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

/**
 * Reset the list.
 */
public void clear() {
  set.clear();
  set.set(0, firstFreeBlock);
}

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

/** Unsupported operation. */
@Override public boolean remove(Object o) {
  if (o == null)
    throw new UnsupportedOperationException("Null values are not supported!");
  int val = (int)o;
  if (val < 0)
    throw new UnsupportedOperationException("Negative values are not supported!");
  boolean alreadySet = bitSet.get(val);
  if (alreadySet) {
    bitSet.clear(val);
    size--;
  }
  return alreadySet;
}

代码示例来源:origin: twitter/distributedlog

/**
 * Performs a deep copy on <i>other</i>.
 */
public HeartbeatOptions(HeartbeatOptions other) {
 __isset_bit_vector.clear();
 __isset_bit_vector.or(other.__isset_bit_vector);
 this.sendHeartBeatToReader = other.sendHeartBeatToReader;
}

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

/** 
 * Initializes the collating state if it hasn't been already.
 */
private void start() {
  if (values == null) {
    values = new ArrayList(iterators.size());
    valueSet = new BitSet(iterators.size());
    for (int i = 0; i < iterators.size(); i++) {
      values.add(null);
      valueSet.clear(i);
    }
  }
}

代码示例来源:origin: skylot/jadx

/**
 * Remove exception handlers from block nodes bitset
 */
public static void cleanBitSet(MethodNode mth, BitSet bs) {
  for (int i = bs.nextSetBit(0); i >= 0; i = bs.nextSetBit(i + 1)) {
    BlockNode block = mth.getBasicBlocks().get(i);
    if (isBlockMustBeCleared(block)) {
      bs.clear(i);
    }
  }
}

代码示例来源:origin: pxb1988/dex2jar

private void makeSureAllElementAreAssigned(Map<Local, ArrayObject> arraySizes) {
  BitSet pos = new BitSet();
  for (Iterator<Map.Entry<Local, ArrayObject>> it = arraySizes.entrySet().iterator(); it.hasNext();) {
    Map.Entry<Local, ArrayObject> e = it.next();
      if (p.st == Stmt.ST.FILL_ARRAY_DATA) {
        int endPos = Array.getLength(((Constant) p.getOp2()).value);
        int next = pos.nextSetBit(0);
        if (next < 0 || next >= endPos) {// not set in range
          pos.set(0, endPos);
        } else {// setted in range
          needRemove = true;
        ArrayExpr ae = (ArrayExpr) p.getOp1();
        int idx = ((Number) ((Constant) ae.getOp2()).value).intValue();
        if (!pos.get(idx)) {
          pos.set(idx);
        } else {
          needRemove = true;
    if (needRemove || pos.nextClearBit(0) < arrayObject.size || pos.nextSetBit(arrayObject.size) >= 0) {
      it.remove();
    pos.clear();

相关文章