Exemple #1
0
  /**
   * Creates a SimpleMDAGNode version of an MDAGNode's outgoing _transition set in mdagDataArray.
   *
   * @param node the MDAGNode containing the _transition set to be inserted in to {@code
   *     mdagDataArray}
   * @param mdagDataArray an array of SimpleMDAGNodes containing a subset of the data of the MDAG
   * @param onePastLastCreatedTransitionSetIndex an int of the index in {@code mdagDataArray} that
   *     the outgoing _transition set of {@code node} is to start from
   * @return an int of one past the end of the _transition set located farthest in {@code
   *     mdagDataArray}
   */
  private int createSimpleMDAGTransitionSet(
      MDAGNode node, SimpleMDAGNode[] mdagDataArray, int onePastLastCreatedTransitionSetIndex) {
    int pivotIndex = onePastLastCreatedTransitionSetIndex; // node自己的位置
    node.setTransitionSetBeginIndex(pivotIndex);

    onePastLastCreatedTransitionSetIndex += node.getOutgoingTransitionCount(); // 这个参数代表id的消耗

    // Create a SimpleMDAGNode representing each _transition label/target combo in
    // transitionTreeMap, recursively calling this method (if necessary)
    // to set indices in these SimpleMDAGNodes that the set of transitions emitting from their
    // respective _transition targets starts from.
    TreeMap<Character, MDAGNode> transitionTreeMap = node.getOutgoingTransitions();
    for (Entry<Character, MDAGNode> transitionKeyValuePair : transitionTreeMap.entrySet()) {
      // Use the current _transition's label and target node to create a SimpleMDAGNode
      // (which is a space-saving representation of the _transition), and insert it in to
      // mdagDataArray
      char transitionLabelChar = transitionKeyValuePair.getKey();
      MDAGNode transitionTargetNode = transitionKeyValuePair.getValue();
      mdagDataArray[pivotIndex] =
          new SimpleMDAGNode(
              transitionLabelChar,
              transitionTargetNode.isAcceptNode(),
              transitionTargetNode.getOutgoingTransitionCount());
      /////

      // If targetTransitionNode's outgoing _transition set hasn't been inserted in to mdagDataArray
      // yet, call this method on it to do so.
      // After this call returns, transitionTargetNode will contain the index in mdagDataArray that
      // its _transition set starts from
      if (transitionTargetNode.getTransitionSetBeginIndex() == -1)
        onePastLastCreatedTransitionSetIndex =
            createSimpleMDAGTransitionSet(
                transitionTargetNode, mdagDataArray, onePastLastCreatedTransitionSetIndex);

      mdagDataArray[pivotIndex++].setTransitionSetBeginIndex(
          transitionTargetNode.getTransitionSetBeginIndex());
    }
    /////

    return onePastLastCreatedTransitionSetIndex;
  }