Java 类com.intellij.util.containers.IntStack 实例源码

项目:intellij-ce-playground    文件:ControlFlowUtil.java   
/**
 * 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;
}
项目:tools-idea    文件:ControlFlowUtil.java   
/**
 * 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;
}
项目:consulo    文件:ControlFlowUtil.java   
/**
 * 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;
}
项目:intellij-ce-playground    文件:DfsUtil.java   
public void nodeDfsIterator(int startRowIndex, @NotNull 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();
}
项目:intellij-ce-playground    文件:ControlFlowUtil.java   
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;
}
项目:tools-idea    文件:ControlFlowUtil.java   
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;
}
项目:consulo    文件:DfsUtil.java   
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();
}
项目:consulo    文件:ControlFlowUtil.java   
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;
}