Пример #1
0
  /**
   * 给节点添加一个转移路径<br>
   * Adds a _transition path starting from a specific node in the MDAG.
   *
   * @param originNode the MDAGNode which will serve as the start point of the to-be-created
   *     _transition path
   * @param str the String to be used to create a new _transition path from {@code originNode}
   */
  private void addTransitionPath(MDAGNode originNode, String str) {
    if (!str.isEmpty()) {
      MDAGNode currentNode = originNode;
      int charCount = str.length();

      // Loop through the characters in str, iteratevely adding
      // a _transition path corresponding to it from originNode
      for (int i = 0; i < charCount; i++, transitionCount++) {
        char currentChar = str.charAt(i);
        boolean isLastChar = (i == charCount - 1);
        currentNode = currentNode.addOutgoingTransition(currentChar, isLastChar);

        charTreeSet.add(currentChar);
      }
      /////
    } else originNode.setAcceptStateStatus(true);
  }
Пример #2
0
  /**
   * 递归创建节点<br>
   *
   * @param current 当前简易节点
   * @param fromIndex 起点下标
   * @param toNodeArray 终点数组
   * @param fromNodeArray 起点数组,它们两个按照下标一一对应
   */
  private void createMDAGNode(
      SimpleMDAGNode current, int fromIndex, MDAGNode[] toNodeArray, MDAGNode[] fromNodeArray) {
    MDAGNode from = (fromIndex == -1 ? sourceNode : toNodeArray[fromIndex]);
    int transitionSetBegin = current.getTransitionSetBeginIndex();
    int onePastTransitionSetEnd = transitionSetBegin + current.getOutgoingTransitionSetSize();

    for (int i = transitionSetBegin; i < onePastTransitionSetEnd; i++) {
      SimpleMDAGNode targetNode = mdagDataArray[i];
      if (toNodeArray[i] != null) {
        fromNodeArray[fromIndex].addOutgoingTransition(current.getLetter(), fromNodeArray[i]);
        toNodeArray[fromIndex] = fromNodeArray[i];
        continue;
      }
      toNodeArray[i] =
          from.addOutgoingTransition(targetNode.getLetter(), targetNode.isAcceptNode());
      fromNodeArray[i] = from;
      createMDAGNode(targetNode, i, toNodeArray, fromNodeArray);
    }
  }