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

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

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

BitSet.nextSetBit介绍

[英]Returns the index of the first bit that is set on or after index, or -1 if no higher bits are set.
[中]返回在索引上或之后设置的第一位的索引,如果未设置更高的位,则返回-1。

代码示例

代码示例来源: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: checkstyle/checkstyle

  1. /**
  2. * Creates new instance for nested structure.
  3. * @param base parent's level
  4. * @param offsets offsets from parent's level.
  5. */
  6. public IndentLevel(IndentLevel base, int... offsets) {
  7. final BitSet src = base.levels;
  8. for (int i = src.nextSetBit(0); i >= 0; i = src.nextSetBit(i + 1)) {
  9. for (int offset : offsets) {
  10. levels.set(i + offset);
  11. }
  12. }
  13. }

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

  1. public static List<BlockNode> bitSetToBlocks(MethodNode mth, BitSet bs) {
  2. int size = bs.cardinality();
  3. if (size == 0) {
  4. return Collections.emptyList();
  5. }
  6. List<BlockNode> blocks = new ArrayList<>(size);
  7. for (int i = bs.nextSetBit(0); i >= 0; i = bs.nextSetBit(i + 1)) {
  8. BlockNode block = mth.getBasicBlocks().get(i);
  9. blocks.add(block);
  10. }
  11. return blocks;
  12. }

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

  1. private static void placePhi(MethodNode mth, int regNum, LiveVarAnalysis la) {
  2. List<BlockNode> blocks = mth.getBasicBlocks();
  3. int blocksCount = blocks.size();
  4. BitSet hasPhi = new BitSet(blocksCount);
  5. BitSet processed = new BitSet(blocksCount);
  6. Deque<BlockNode> workList = new LinkedList<>();
  7. BitSet assignBlocks = la.getAssignBlocks(regNum);
  8. for (int id = assignBlocks.nextSetBit(0); id >= 0; id = assignBlocks.nextSetBit(id + 1)) {
  9. processed.set(id);
  10. workList.add(blocks.get(id));
  11. }
  12. while (!workList.isEmpty()) {
  13. BlockNode block = workList.pop();
  14. BitSet domFrontier = block.getDomFrontier();
  15. for (int id = domFrontier.nextSetBit(0); id >= 0; id = domFrontier.nextSetBit(id + 1)) {
  16. if (!hasPhi.get(id) && la.isLive(id, regNum)) {
  17. BlockNode df = blocks.get(id);
  18. addPhi(mth, df, regNum);
  19. hasPhi.set(id);
  20. if (!processed.get(id)) {
  21. processed.set(id);
  22. workList.add(df);
  23. }
  24. }
  25. }
  26. }
  27. }

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

  1. @Benchmark
  2. public BitSet bitset() {
  3. BitSet result = new BitSet();
  4. for(int i = 0; i < bitSets.length; ++i) {
  5. BitSetWithOffset bit = bitSets[i];
  6. int currentBit = bit.bitset.nextSetBit(0);
  7. while(currentBit != -1) {
  8. result.set(currentBit + bit.offset);
  9. currentBit = bit.bitset.nextSetBit(currentBit + 1);
  10. }
  11. }
  12. return result;
  13. }

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

  1. if(origNumber != null) {
  2. for(ValueInfo vi : vals) {
  3. if(vi.origValues.get(origNumber.getNumber()) && !vi.derivedValues.get(number)) {
  4. vi.derivedValues.set(number);
  5. result = true;
  6. for (int i = outputSet.nextSetBit(0); i >= 0; i = outputSet.nextSetBit(i+1)) {
  7. list = values.get(i);
  8. if(list == null) {

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

  1. @SuppressWarnings("unchecked")
  2. public ArrayTypes getArrayTypesBefore(Stmt s, Local arrayLocal) {
  3. if (!isConstantBefore(s, arrayLocal)) {
  4. return null;
  5. }
  6. ArrayTypes toRet = new ArrayTypes();
  7. int varRef = localToInt.get(arrayLocal);
  8. ArrayTypesInternal ati = getFlowBefore(s).state[varRef];
  9. toRet.possibleSizes = new HashSet<Integer>();
  10. toRet.possibleTypes = new Set[ati.typeState.length];
  11. for (int i = ati.sizeState.nextSetBit(0); i >= 0; i = ati.sizeState.nextSetBit(i + 1)) {
  12. toRet.possibleSizes.add(rvSizeToInt.get(i));
  13. }
  14. for (int i = 0; i < toRet.possibleTypes.length; i++) {
  15. toRet.possibleTypes[i] = new HashSet<Type>();
  16. for (int j = ati.typeState[i].nextSetBit(0); j >= 0; j = ati.typeState[i].nextSetBit(j + 1)) {
  17. toRet.possibleTypes[i].add(rvTypeToInt.get(j));
  18. }
  19. if (!ati.mustAssign.get(i)) {
  20. toRet.possibleTypes[i].add(NullType.v());
  21. }
  22. }
  23. return toRet;
  24. }

代码示例来源:origin: google/guava

  1. static CharMatcher from(BitSet chars, String description) {
  2. // Compute the filter.
  3. long filter = 0;
  4. int size = chars.cardinality();
  5. boolean containsZero = chars.get(0);
  6. // Compute the hash table.
  7. char[] table = new char[chooseTableSize(size)];
  8. int mask = table.length - 1;
  9. for (int c = chars.nextSetBit(0); c != -1; c = chars.nextSetBit(c + 1)) {
  10. // Compute the filter at the same time.
  11. filter |= 1L << c;
  12. int index = smear(c) & mask;
  13. while (true) {
  14. // Check for empty.
  15. if (table[index] == 0) {
  16. table[index] = (char) c;
  17. break;
  18. }
  19. // Linear probing.
  20. index = (index + 1) & mask;
  21. }
  22. }
  23. return new SmallCharMatcher(table, filter, containsZero, description);
  24. }

代码示例来源: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: 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: osmandapp/Osmand

  1. protected Object calcSelectValue(BitSet types, ParameterContext paramContext) {
  2. if (selectValue instanceof String && selectValue.toString().startsWith("$")) {
  3. BitSet mask = tagRuleMask.get(selectValue.toString().substring(1));
  4. if (mask != null && mask.intersects(types)) {
  5. BitSet findBit = new BitSet(mask.length());
  6. findBit.or(mask);
  7. findBit.and(types);
  8. int value = findBit.nextSetBit(0);
  9. return parseValueFromTag(value, selectType);
  10. }
  11. } else if (selectValue instanceof String && selectValue.toString().startsWith(":")) {
  12. String p = ((String) selectValue).substring(1);
  13. if (paramContext != null && paramContext.vars.containsKey(p)) {
  14. selectValue = parseValue(paramContext.vars.get(p), selectType);
  15. } else {
  16. return null;
  17. }
  18. }
  19. return selectValue;
  20. }

代码示例来源:origin: opentripplanner/OpenTripPlanner

  1. public boolean doOneRound (int[] bestTimes, int[] bestNonTransferTimes, int[] previousPatterns, boolean useFrequencies) {
  2. stopsTouched.clear(); // clear any stops left over from previous round.
  3. PATTERNS: for (int p = patternsTouched.nextSetBit(0); p >= 0; p = patternsTouched.nextSetBit(p+1)) {
  4. bestNonTransferTimes[stopIndex] = remainOnBoardTime;
  5. stopsTouched.set(stopIndex);
  6. allStopsTouched.set(stopIndex);
  7. bestNonTransferTimes[stopIndex] = arrivalTime;
  8. stopsTouched.set(stopIndex);
  9. allStopsTouched.set(stopIndex);

代码示例来源:origin: mpetazzoni/ttorrent

  1. BitSet availablePieces = peer.getAvailablePieces();
  2. for (int i = availablePieces.nextSetBit(0); i >= 0;
  3. i = availablePieces.nextSetBit(i + 1)) {
  4. this.pieces[i].noLongerAt(peer);
  5. if (requested != null) {
  6. for (Piece piece : requested) {
  7. this.requestedPieces.set(piece.getIndex(), false);
  8. new Object[]{
  9. peer,
  10. availablePieces.cardinality(),
  11. this.completedPieces.cardinality(),
  12. this.pieces.length
  13. });
  14. logger.trace("We now have {} piece(s) and {} outstanding request(s): {}",
  15. new Object[]{
  16. this.completedPieces.cardinality(),
  17. this.requestedPieces.cardinality(),
  18. this.requestedPieces

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

  1. public BitSet getTransitiveOutputSet(int input) {
  2. BitSet visited = new BitSet();
  3. BitSet result = new BitSet();
  4. LinkedList<Integer> workList = new LinkedList<>();
  5. workList.addLast(input);
  6. while (!workList.isEmpty()) {
  7. Integer valueNumber = workList.removeFirst();
  8. visited.set(valueNumber);
  9. BitSet outputSet = getOutputSet(valueNumber);
  10. result.or(outputSet);
  11. for (int i = outputSet.nextSetBit(0); i >= 0; i = outputSet.nextSetBit(i+1)) {
  12. if (!visited.get(i)) {
  13. workList.addLast(i);
  14. }
  15. }
  16. }
  17. return result;
  18. }

代码示例来源:origin: fesh0r/fernflower

  1. public ConstantPool(DataInputStream in) throws IOException {
  2. int size = in.readUnsignedShort();
  3. pool = new ArrayList<>(size);
  4. BitSet[] nextPass = {new BitSet(size), new BitSet(size), new BitSet(size)};
  5. case CodeConstants.CONSTANT_MethodType:
  6. pool.add(new PrimitiveConstant(tag, in.readUnsignedShort()));
  7. nextPass[0].set(i);
  8. break;
  9. nextPass[0].set(i);
  10. break;
  11. case CodeConstants.CONSTANT_InvokeDynamic:
  12. pool.add(new LinkConstant(tag, in.readUnsignedShort(), in.readUnsignedShort()));
  13. nextPass[1].set(i);
  14. break;
  15. while ((idx = pass.nextSetBit(idx + 1)) > 0) {
  16. pool.get(idx).resolveConstant(this);

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

  1. DexStmtNode p = stack.pop();
  2. int index = p.__index;
  3. if (!access.get(index)) {
  4. access.set(index);
  5. } else {
  6. continue;
  7. if (handlers.get(index)) {
  8. Local ex = newLocal();
  9. emit(Stmts.nIdentity(ex, Exprs.nExceptionRef("Ljava/lang/Throwable;")));
  10. for (int i = ex.nextSetBit(0); i >= 0; i = ex.nextSetBit(i + 1)) {
  11. merge(frame, i);
  12. stack.push(insnList.get(i));

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

  1. if (bits.get(fromIndex)) {
  2. return singletonList(universe[fromIndex]);
  3. int i = bits.nextSetBit(fromIndex);
  4. if (i < 0 || i >= toIndex) {
  5. return emptyList();
  6. break;
  7. i = bits.nextSetBit(i + 1);
  8. if (i < 0 || i >= toIndex) {
  9. break;

代码示例来源:origin: prestodb/presto

  1. static CharMatcher from(BitSet chars, String description) {
  2. // Compute the filter.
  3. long filter = 0;
  4. int size = chars.cardinality();
  5. boolean containsZero = chars.get(0);
  6. // Compute the hash table.
  7. char[] table = new char[chooseTableSize(size)];
  8. int mask = table.length - 1;
  9. for (int c = chars.nextSetBit(0); c != -1; c = chars.nextSetBit(c + 1)) {
  10. // Compute the filter at the same time.
  11. filter |= 1L << c;
  12. int index = smear(c) & mask;
  13. while (true) {
  14. // Check for empty.
  15. if (table[index] == 0) {
  16. table[index] = (char) c;
  17. break;
  18. }
  19. // Linear probing.
  20. index = (index + 1) & mask;
  21. }
  22. }
  23. return new SmallCharMatcher(table, filter, containsZero, description);
  24. }

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

  1. void enhanceViaMergeTree() {
  2. values = new HashMap<>();
  3. for (Entry<Integer, ValueInfo> entry : observedValues.entrySet()) {
  4. BitSet outputSet = vna.getMergeTree().getTransitiveOutputSet(entry.getKey());
  5. outputSet.set(entry.getKey());
  6. entry.getValue().origValues = outputSet;
  7. for (int i = outputSet.nextSetBit(0); i >= 0; i = outputSet.nextSetBit(i+1)) {
  8. Set<ValueInfo> list = values.get(i);
  9. if(list == null) {
  10. list = new HashSet<>();
  11. values.put(i, list);
  12. }
  13. list.add(entry.getValue());
  14. }
  15. }
  16. }

代码示例来源: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. }

相关文章