com.intellij.util.containers.IntStack Java Examples

The following examples show how to use com.intellij.util.containers.IntStack. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ControlFlowUtil.java    From consulo with Apache License 2.0 6 votes vote down vote up
/**
 * Process control flow graph in depth first order
 */
public static boolean process(final Instruction[] flow, final int start, final Processor<Instruction> processor){
  final int length = flow.length;
  boolean[] visited = new boolean[length];
  Arrays.fill(visited, false);

  final IntStack stack = new IntStack(length);
  stack.push(start);

  while (!stack.empty()) {
    ProgressManager.checkCanceled();
    final int num = stack.pop();
    final Instruction instruction = flow[num];
    if (!processor.process(instruction)){
      return false;
    }
    for (Instruction succ : instruction.allSucc()) {
      final int succNum = succ.num();
      if (!visited[succNum]) {
        visited[succNum] = true;
        stack.push(succNum);
      }
    }
  }
  return true;
}
 
Example #2
Source File: DfsUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void nodeDfsIterator(int startRowIndex, @Nonnull NextNode nextNodeFun) {
  IntStack myStack = new IntStack();
  myStack.push(startRowIndex);

  while (!myStack.empty()) {
    int nextNode = nextNodeFun.fun(myStack.peek());
    if (nextNode != NextNode.NODE_NOT_FOUND) {
      myStack.push(nextNode);
    }
    else {
      myStack.pop();
    }
  }
  myStack.clear();
}
 
Example #3
Source File: ControlFlowUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static int[] postOrder(Instruction[] flow) {
  final int length = flow.length;
  int[] result = new int[length];
  boolean[] visited = new boolean[length];
  Arrays.fill(visited, false);
  final IntStack stack = new IntStack(length);

  int N = 0;
  for (int i = 0; i < length; i++) { //graph might not be connected
    if (!visited[i]) {
      visited[i] = true;
      stack.clear();
      stack.push(i);

      while (!stack.empty()) {
        final int num = stack.pop();
        result[N++] = num;
        for (Instruction succ : flow[num].allSucc()) {
          final int succNum = succ.num();
          if (!visited[succNum]) {
            visited[succNum] = true;
            stack.push(succNum);
          }
        }
      }
    }
  }
  LOG.assertTrue(N == length);
  return result;
}