Exemple #1
0
  /**
   * Removes a String from the MDAG.
   *
   * @param str the String to be removed from the MDAG
   */
  public void removeString(String str) {
    if (sourceNode != null) {
      // Split the _transition path corresponding to str to ensure that
      // any other _transition paths sharing nodes with it are not affected
      splitTransitionPath(sourceNode, str);

      // Remove from equivalenceClassMDAGNodeHashMap, the entries of all the nodes in the
      // _transition path corresponding to str.
      removeTransitionPathRegisterEntries(str);

      // Get the last node in the _transition path corresponding to str
      MDAGNode strEndNode = sourceNode.transition(str);
      if (strEndNode == null) return;

      if (!strEndNode.hasTransitions()) {
        int soleInternalTransitionPathLength = calculateSoleTransitionPathLength(str);
        int internalTransitionPathLength = str.length() - 1;

        if (soleInternalTransitionPathLength == internalTransitionPathLength) {
          sourceNode.removeOutgoingTransition(str.charAt(0));
          transitionCount -= str.length();
        } else {
          // Remove the sub-path in str's _transition path that is only used by str
          int toBeRemovedTransitionLabelCharIndex =
              (internalTransitionPathLength - soleInternalTransitionPathLength);
          MDAGNode latestNonSoloTransitionPathNode =
              sourceNode.transition(str.substring(0, toBeRemovedTransitionLabelCharIndex));
          latestNonSoloTransitionPathNode.removeOutgoingTransition(
              str.charAt(toBeRemovedTransitionLabelCharIndex));
          transitionCount -= str.substring(toBeRemovedTransitionLabelCharIndex).length();
          /////

          replaceOrRegister(sourceNode, str.substring(0, toBeRemovedTransitionLabelCharIndex));
        }

      } else {
        strEndNode.setAcceptStateStatus(false);
        replaceOrRegister(sourceNode, str);
      }
    } else {
      unSimplify();
    }
  }