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

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

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

  1. private void initSuggestColor(BitSet suggestColor, Reg as) {
  2. suggestColor.clear();
  3. for (Reg ex : as.prefers) {
  4. if (ex.reg >= 0) {
  5. suggestColor.set(ex.reg);
  6. }
  7. }
  8. }

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

  1. public synchronized boolean remove(Integer elementBit) {
  2. if (elementBit == null || !elementBits.get(elementBit)) {
  3. return false;
  4. }
  5. cache.remove(elementBit);
  6. elementBits.clear(elementBit);
  7. elementCount--;
  8. return true;
  9. }

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

  1. /**
  2. * Clear the info about which rows (in which original iterators and which row nums within them) were combined on
  3. * the previous step.
  4. */
  5. private void clearCombinedRowsInfo()
  6. {
  7. for (int originalIteratorIndex = indexesOfCurrentlyCombinedOriginalIterators.nextSetBit(0);
  8. originalIteratorIndex >= 0;
  9. originalIteratorIndex = indexesOfCurrentlyCombinedOriginalIterators.nextSetBit(originalIteratorIndex + 1)) {
  10. minCurrentlyCombinedRowNumByOriginalIteratorIndex[originalIteratorIndex] =
  11. MIN_CURRENTLY_COMBINED_ROW_NUM_UNSET_VALUE;
  12. }
  13. indexesOfCurrentlyCombinedOriginalIterators.clear();
  14. }

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

  1. public static BitSet computePrimes(int limit)
  2. {
  3. final BitSet primes = new BitSet();
  4. primes.set(0, false);
  5. primes.set(1, false);
  6. primes.set(2, limit, true);
  7. for (int i = 0; i * i < limit; i++)
  8. {
  9. if (primes.get(i))
  10. {
  11. for (int j = i * i; j < limit; j += i)
  12. {
  13. primes.clear(j);
  14. }
  15. }
  16. }
  17. return primes;
  18. }

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

  1. public boolean removeAtIndex(int index)
  2. {
  3. boolean previous = this.get(index);
  4. if (this.size - index > 1)
  5. {
  6. for (int i = index; i < this.size; i++)
  7. {
  8. this.items.set(i, this.items.get(i + 1));
  9. }
  10. }
  11. --this.size;
  12. this.items.clear(this.size);
  13. return previous;
  14. }

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

  1. private void setSlotBits(List<Integer> slots) {
  2. if (slots.isEmpty() && this.slots == null) {
  3. return;
  4. }
  5. if (this.slots == null) {
  6. this.slots = new BitSet(SlotHash.SLOT_COUNT);
  7. }
  8. this.slots.clear();
  9. for (Integer slot : slots) {
  10. this.slots.set(slot);
  11. }
  12. }

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

  1. @Override
  2. protected void merge(ArrayState in1, ArrayState in2, ArrayState out) {
  3. out.active.clear();
  4. out.active.or(in1.active);
  5. out.active.or(in2.active);
  6. BitSet in2_excl = (BitSet) in2.active.clone();
  7. in2_excl.andNot(in1.active);
  8. for (int i = in1.active.nextSetBit(0); i >= 0; i = in1.active.nextSetBit(i + 1)) {
  9. if (in1.state[i] == null) {
  10. out.state[i] = null;
  11. } else if (in2.active.get(i)) {
  12. if (in2.state[i] == null) {
  13. out.state[i] = null;
  14. } else {
  15. out.state[i] = mergeTypeStates(in1.state[i], in2.state[i]);
  16. }
  17. } else {
  18. out.state[i] = in1.state[i];
  19. }
  20. }
  21. for (int i = in2_excl.nextSetBit(0); i >= 0; i = in2_excl.nextSetBit(i + 1)) {
  22. out.state[i] = in2.state[i];
  23. }
  24. }

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

  1. /**
  2. * Performs a deep copy on <i>other</i>.
  3. */
  4. public AccessControlEntry(AccessControlEntry other) {
  5. __isset_bit_vector.clear();
  6. __isset_bit_vector.or(other.__isset_bit_vector);
  7. this.denyWrite = other.denyWrite;
  8. this.denyTruncate = other.denyTruncate;
  9. this.denyDelete = other.denyDelete;
  10. this.denyAcquire = other.denyAcquire;
  11. this.denyRelease = other.denyRelease;
  12. }

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

  1. /**
  2. * Initializes the collating state if it hasn't been already.
  3. */
  4. private void start() {
  5. if (values == null) {
  6. values = new ArrayList(iterators.size());
  7. valueSet = new BitSet(iterators.size());
  8. for (int i = 0; i < iterators.size(); i++) {
  9. values.add(null);
  10. valueSet.clear(i);
  11. }
  12. }
  13. }

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

  1. final BitSet parent2Key = second.getRepresentation();
  2. final BitSet child1Key = new BitSet(length);
  3. final BitSet child2Key = new BitSet(length);
  4. a.clear(crossoverIndex, length);
  5. BitSet b = (BitSet) parent2Key.clone();
  6. b.clear(0, crossoverIndex);
  7. c.clear(crossoverIndex, length);
  8. BitSet d = (BitSet) parent2Key.clone();
  9. d.clear(0, crossoverIndex);
  10. child1Key.or(a);
  11. child1Key.or(d);
  12. child2Key.or(c);
  13. child2Key.or(b);
  14. return new ChromosomePair(first.newBitsChromosome(child1Key), second.newBitsChromosome(child2Key));

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

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

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

  1. protected void flowThrough(BitSet in, Unit unit, BitSet out) {
  2. out.clear();
  3. out.or(in);
  4. if (!out.get(indexOf(unit))) {
  5. out.set(indexOf(unit));
  6. // System.out.println("add to out: "+unit);
  7. } else {
  8. multiRunStatements.add(unit);
  9. }
  10. // System.out.println("in: "+in);
  11. // System.out.println("out: "+out);
  12. }

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

  1. @Override
  2. public boolean removeAtIndex(int index)
  3. {
  4. boolean previous = this.get(index);
  5. if (this.size - index > 1)
  6. {
  7. for (int i = index; i < this.size; i++)
  8. {
  9. this.items.set(i, this.items.get(i + 1));
  10. }
  11. }
  12. --this.size;
  13. this.items.clear(this.size);
  14. return previous;
  15. }

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

  1. /**
  2. * Reservoir sampling algorithm borrowed from Stack Overflow.
  3. * https://stackoverflow.com/questions/12817946/generate-a-random-bitset-with-n-1s
  4. */
  5. private static BitSet randomBitSet(int size, int cardinality, Random rnd) {
  6. final BitSet result = new BitSet(size);
  7. final int[] chosen = new int[cardinality];
  8. int i;
  9. for (i = 0; i < cardinality; ++i) {
  10. chosen[i] = i;
  11. result.set(i);
  12. }
  13. for (; i < size; ++i) {
  14. final int j = rnd.nextInt(i + 1);
  15. if (j < cardinality) {
  16. result.clear(chosen[j]);
  17. result.set(i);
  18. chosen[j] = i;
  19. }
  20. }
  21. return result;
  22. }

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

  1. /**
  2. * Reset the list.
  3. */
  4. public void clear() {
  5. set.clear();
  6. set.set(0, firstFreeBlock);
  7. }

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

  1. /** Unsupported operation. */
  2. @Override public boolean remove(Object o) {
  3. if (o == null)
  4. throw new UnsupportedOperationException("Null values are not supported!");
  5. int val = (int)o;
  6. if (val < 0)
  7. throw new UnsupportedOperationException("Negative values are not supported!");
  8. boolean alreadySet = bitSet.get(val);
  9. if (alreadySet) {
  10. bitSet.clear(val);
  11. size--;
  12. }
  13. return alreadySet;
  14. }

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

  1. /**
  2. * Performs a deep copy on <i>other</i>.
  3. */
  4. public HeartbeatOptions(HeartbeatOptions other) {
  5. __isset_bit_vector.clear();
  6. __isset_bit_vector.or(other.__isset_bit_vector);
  7. this.sendHeartBeatToReader = other.sendHeartBeatToReader;
  8. }

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

  1. /**
  2. * Initializes the collating state if it hasn't been already.
  3. */
  4. private void start() {
  5. if (values == null) {
  6. values = new ArrayList(iterators.size());
  7. valueSet = new BitSet(iterators.size());
  8. for (int i = 0; i < iterators.size(); i++) {
  9. values.add(null);
  10. valueSet.clear(i);
  11. }
  12. }
  13. }

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

  1. /**
  2. * Remove exception handlers from block nodes bitset
  3. */
  4. public static void cleanBitSet(MethodNode mth, BitSet bs) {
  5. for (int i = bs.nextSetBit(0); i >= 0; i = bs.nextSetBit(i + 1)) {
  6. BlockNode block = mth.getBasicBlocks().get(i);
  7. if (isBlockMustBeCleared(block)) {
  8. bs.clear(i);
  9. }
  10. }
  11. }

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

  1. private void makeSureAllElementAreAssigned(Map<Local, ArrayObject> arraySizes) {
  2. BitSet pos = new BitSet();
  3. for (Iterator<Map.Entry<Local, ArrayObject>> it = arraySizes.entrySet().iterator(); it.hasNext();) {
  4. Map.Entry<Local, ArrayObject> e = it.next();
  5. if (p.st == Stmt.ST.FILL_ARRAY_DATA) {
  6. int endPos = Array.getLength(((Constant) p.getOp2()).value);
  7. int next = pos.nextSetBit(0);
  8. if (next < 0 || next >= endPos) {// not set in range
  9. pos.set(0, endPos);
  10. } else {// setted in range
  11. needRemove = true;
  12. ArrayExpr ae = (ArrayExpr) p.getOp1();
  13. int idx = ((Number) ((Constant) ae.getOp2()).value).intValue();
  14. if (!pos.get(idx)) {
  15. pos.set(idx);
  16. } else {
  17. needRemove = true;
  18. if (needRemove || pos.nextClearBit(0) < arrayObject.size || pos.nextSetBit(arrayObject.size) >= 0) {
  19. it.remove();
  20. pos.clear();

相关文章