本文整理汇总了Java中java.util.BitSet.nextSetBit方法的典型用法代码示例。如果您正苦于以下问题:Java BitSet.nextSetBit方法的具体用法?Java BitSet.nextSetBit怎么用?Java BitSet.nextSetBit使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.BitSet
的用法示例。
在下文中一共展示了BitSet.nextSetBit方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getPredecessors
import java.util.BitSet; //导入方法依赖的package包/类
private static List<Trace> getPredecessors(Trace trace, TraceBuilderResult traceBuilderResult) {
BitSet bs = new BitSet(traceBuilderResult.getTraces().size());
for (AbstractBlockBase<?> block : trace.getBlocks()) {
for (AbstractBlockBase<?> p : block.getPredecessors()) {
Trace otherTrace = traceBuilderResult.getTraceForBlock(p);
int otherTraceId = otherTrace.getId();
if (trace.getId() != otherTraceId || isLoopBackEdge(p, block)) {
bs.set(traceBuilderResult.getTraceForBlock(p).getId());
}
}
}
List<Trace> pred = new ArrayList<>();
for (int i = bs.nextSetBit(0); i >= 0; i = bs.nextSetBit(i + 1)) {
pred.add(traceBuilderResult.getTraces().get(i));
}
return pred;
}
示例2: precomputedPositive
import java.util.BitSet; //导入方法依赖的package包/类
/**
* Helper method for {@link #precomputedInternal} that doesn't test if the negation is cheaper.
*/
@GwtIncompatible("java.util.BitSet")
private static CharMatcher precomputedPositive(
int totalCharacters,
BitSet table,
String description) {
switch (totalCharacters) {
case 0:
return NONE;
case 1:
return is((char) table.nextSetBit(0));
case 2:
char c1 = (char) table.nextSetBit(0);
char c2 = (char) table.nextSetBit(c1 + 1);
return isEither(c1, c2);
default:
return isSmall(totalCharacters, table.length())
? SmallCharMatcher.from(table, description)
: new BitSetMatcher(table, description);
}
}
示例3: NetworkGraph
import java.util.BitSet; //导入方法依赖的package包/类
/**
* The constructor.
*
* @param graph
* The workflow graph.
* @param nodeMap
* The map of nodes.
* @param information
* The information for analysis.
*/
public NetworkGraph(WorkflowGraph graph, WGNode[] nodeMap, AnalysisInformation information) {
super(graph, nodeMap, information);
this.edges = new NetworkEdge[graph.getEdges().size()];
this.replaced = new BitSet(this.edges.length);
int max = 0;
BitSet forkSet = (BitSet) graph.getForkSet().clone();
forkSet.or(graph.getOrForkSet());
BitSet[] outgoing = graph.getOutgoingEdges();
// Determine the maximum number of outgoing edges of forks
for (int f = forkSet.nextSetBit(0); f >= 0; f = forkSet.nextSetBit(f + 1)) {
max = Math.max(outgoing[f].cardinality(), max);
}
this.maxAdditionalEdges = edges.length + max * 2;
this.tmpEdges = new NetworkEdge[maxAdditionalEdges];
int maxAdditionalNodes = nodeMap.length + max + 1;
this.incoming = new BitSet[maxAdditionalNodes];
this.outgoing = new BitSet[maxAdditionalNodes];
this.capacities = new BitSet(maxAdditionalEdges);
this.currentFlow = new BitSet(maxAdditionalEdges);
initialize();
}
示例4: precomputedPositive
import java.util.BitSet; //导入方法依赖的package包/类
/**
* Helper method for {@link #precomputedInternal} that doesn't test if the negation is cheaper.
*/
@GwtIncompatible // SmallCharMatcher
private static CharMatcher precomputedPositive(
int totalCharacters, BitSet table, String description) {
switch (totalCharacters) {
case 0:
return none();
case 1:
return is((char) table.nextSetBit(0));
case 2:
char c1 = (char) table.nextSetBit(0);
char c2 = (char) table.nextSetBit(c1 + 1);
return isEither(c1, c2);
default:
return isSmall(totalCharacters, table.length())
? SmallCharMatcher.from(table, description)
: new BitSetMatcher(table, description);
}
}
示例5: edgeSplitSuccessors
import java.util.BitSet; //导入方法依赖的package包/类
/**
* Inserts Z nodes for every node that needs a new
* successor.
*
* @param result {@code non-null;} method to process
*/
private static void edgeSplitSuccessors(SsaMethod result) {
ArrayList<SsaBasicBlock> blocks = result.getBlocks();
/*
* New blocks are added to the end of the block list during
* this iteration.
*/
for (int i = blocks.size() - 1; i >= 0; i-- ) {
SsaBasicBlock block = blocks.get(i);
// Successors list is modified in loop below.
BitSet successors = (BitSet)block.getSuccessors().clone();
for (int j = successors.nextSetBit(0);
j >= 0; j = successors.nextSetBit(j+1)) {
SsaBasicBlock succ = blocks.get(j);
if (needsNewSuccessor(block, succ)) {
block.insertNewSuccessor(succ);
}
}
}
}
示例6: CDString
import java.util.BitSet; //导入方法依赖的package包/类
public static String CDString(MethodNode mth) {
StringBuilder sb = new StringBuilder();
for (BlockNode block : mth.getBasicBlocks()) {
sb.append(block.getId()); sb.append(":\n");
BitSet set = block.getCdblocks();
for (int i = set.nextSetBit(0); i >= 0; i = set.nextSetBit(i + 1)) {
sb.append(i); sb.append(" ");
}
sb.append("\n-------------------\n");
}
return sb.toString();
}
示例7: PDFString
import java.util.BitSet; //导入方法依赖的package包/类
public static String PDFString(MethodNode mth) {
StringBuilder sb = new StringBuilder();
for (BlockNode block : mth.getBasicBlocks()) {
sb.append(block.getId()); sb.append(":\n");
BitSet set = block.getPdomFrontier();
for (int i = set.nextSetBit(0); i >= 0; i = set.nextSetBit(i + 1)) {
sb.append(i); sb.append(" ");
}
sb.append("\n-------------------\n");
}
return sb.toString();
}
示例8: postDominanceFrontierAnalysis
import java.util.BitSet; //导入方法依赖的package包/类
/**
* Performs the post dominance frontier analysis.
*/
private void postDominanceFrontierAnalysis() {
BitSet out = new BitSet(edges.size());
for (Edge e : edges) {
// An edge is visited
edgesVisited++;
out.clear();
out.or(outgoing[e.tgt.getId()]);
if (out.cardinality() >= 2) {
for (int i = out.nextSetBit(0); i >= 0; i = out
.nextSetBit(i + 1)) {
// An edge is visited
edgesVisited++;
Edge runner = edges.get(i);
while (runner.id != e.postDominatorList.getLast().id) {
// An edge is visited
edgesVisited++;
runner.postDominanceFrontierSet.set(e.id);
runner = runner.postDominatorList.getLast();
}
}
}
}
}
示例9: copy
import java.util.BitSet; //导入方法依赖的package包/类
/** Copies over all states/transitions from other. The states numbers
* are sequentially assigned (appended). */
public void copy(Automaton other) {
// Bulk copy and then fixup the state pointers:
int stateOffset = getNumStates();
states = ArrayUtil.grow(states, nextState + other.nextState);
System.arraycopy(other.states, 0, states, nextState, other.nextState);
for(int i=0;i<other.nextState;i += 2) {
if (states[nextState+i] != -1) {
states[nextState+i] += nextTransition;
}
}
nextState += other.nextState;
int otherNumStates = other.getNumStates();
BitSet otherAcceptStates = other.getAcceptStates();
int state = 0;
while (state < otherNumStates && (state = otherAcceptStates.nextSetBit(state)) != -1) {
setAccept(stateOffset + state, true);
state++;
}
// Bulk copy and then fixup dest for each transition:
transitions = ArrayUtil.grow(transitions, nextTransition + other.nextTransition);
System.arraycopy(other.transitions, 0, transitions, nextTransition, other.nextTransition);
for(int i=0;i<other.nextTransition;i += 3) {
transitions[nextTransition+i] += stateOffset;
}
nextTransition += other.nextTransition;
if (other.deterministic == false) {
deterministic = false;
}
}
示例10: sortArray
import java.util.BitSet; //导入方法依赖的package包/类
/**
* 进行数字排序
*/
public static void sortArray() {
int[] array = new int[] { 423, 700, 9999, 2323, 356, 6400, 1,2,3,2,2,2,2 };
BitSet bitSet = new BitSet(2 << 13);
// 虽然可以自动扩容,但尽量在构造时指定估算大小,默认为64
System.out.println("BitSet size: " + bitSet.size());
for (int i = 0; i < array.length; i++) {
bitSet.set(array[i]);
}
//剔除重复数字后的元素个数
int bitLen=bitSet.cardinality();
//进行排序,即把bit为true的元素复制到另一个数组
int[] orderedArray = new int[bitLen];
int k = 0;
for (int i = bitSet.nextSetBit(0); i >= 0; i = bitSet.nextSetBit(i + 1)) {
orderedArray[k++] = i;
}
System.out.println("After ordering: ");
for (int i = 0; i < bitLen; i++) {
System.out.print(orderedArray[i] + "\t");
}
System.out.println("iterate over the true bits in a BitSet");
//或直接迭代BitSet中bit为true的元素iterate over the true bits in a BitSet
for (int i = bitSet.nextSetBit(0); i >= 0; i = bitSet.nextSetBit(i + 1)) {
System.out.print(i+"\t");
}
System.out.println("---------------------------");
}
示例11: bitSetToIntArray
import java.util.BitSet; //导入方法依赖的package包/类
private int[] bitSetToIntArray(BitSet live) {
int[] vars = new int[live.cardinality()];
int cnt = 0;
for (int i = live.nextSetBit(0); i >= 0; i = live.nextSetBit(i + 1), cnt++) {
vars[cnt] = i;
}
return vars;
}
示例12: inverseDepthFirstSearch
import java.util.BitSet; //导入方法依赖的package包/类
/**
* Searches all edges with currently a path to the edge.
*
* @param current
* The current edge id.
* @param last
* The last edge id (the outgoing edge of join).
* @param notAllowed
* Removed edges.
* @param visited
* The already visited edges.
*/
private void inverseDepthFirstSearch(int current, int last, BitSet allowed, BitSet visited) {
// The current edge is visited
visited.set(current);
// An edge is visited
edgesVisited++;
// If we reach the outgoing edge (last) of the join
// node, then we not visited the other edges since
// we are in a deliver graph.
if (current != last) {
// Determine the edge
Edge curEdge = edges.get(current);
// Get the predecessors of the current edge
BitSet predCopy = (BitSet) incoming[curEdge.src.getId()].clone();
// Eliminate visited and not allowed edges
predCopy.and(allowed);
predCopy.andNot(visited);
// Visited the rest predecessors
for (int p = predCopy.nextSetBit(0); p >= 0; p = predCopy.nextSetBit(p + 1)) {
inverseDepthFirstSearch(p, last, allowed, visited);
}
}
}
示例13: toSet
import java.util.BitSet; //导入方法依赖的package包/类
private static Set<Integer> toSet(Automaton a, int offset) {
int numStates = a.getNumStates();
BitSet isAccept = a.getAcceptStates();
Set<Integer> result = new HashSet<Integer>();
int upto = 0;
while (upto < numStates && (upto = isAccept.nextSetBit(upto)) != -1) {
result.add(offset+upto);
upto++;
}
return result;
}
示例14: forEachBlockDepthFirst
import java.util.BitSet; //导入方法依赖的package包/类
/**
* Walks the basic block tree in depth-first order, calling the visitor
* method once for every block. This depth-first walk may be run forward
* from the method entry point or backwards from the method exit points.
*
* @param reverse true if this should walk backwards from the exit points
* @param v {@code non-null;} callback interface. {@code parent} is set
* unless this is the root node
*/
public void forEachBlockDepthFirst(boolean reverse,
SsaBasicBlock.Visitor v) {
BitSet visited = new BitSet(blocks.size());
// We push the parent first, then the child on the stack.
Stack<SsaBasicBlock> stack = new Stack<SsaBasicBlock>();
SsaBasicBlock rootBlock = reverse ? getExitBlock() : getEntryBlock();
if (rootBlock == null) {
// in the case there's no exit block
return;
}
stack.add(null); // Start with null parent.
stack.add(rootBlock);
while (stack.size() > 0) {
SsaBasicBlock cur = stack.pop();
SsaBasicBlock parent = stack.pop();
if (!visited.get(cur.getIndex())) {
BitSet children
= reverse ? cur.getPredecessors() : cur.getSuccessors();
for (int i = children.nextSetBit(0); i >= 0
; i = children.nextSetBit(i + 1)) {
stack.add(cur);
stack.add(blocks.get(i));
}
visited.set(cur.getIndex());
v.visitBlock(cur, parent);
}
}
}
示例15: decCounters
import java.util.BitSet; //导入方法依赖的package包/类
private void decCounters(BitSet bs) {
int idx = -1;
while(true) {
idx = bs.nextSetBit(idx + 1);
if (idx < 0) break;
if (counters[idx] > 0) counters[idx]--;
}
}