/** * 给节点添加一个转移路径<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); }
/** * 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(); } }