From fba36429b4abaa37690b6e55d43148a67fa9528b Mon Sep 17 00:00:00 2001 From: "hongze.zhz" Date: Sat, 1 Apr 2017 15:48:37 +0800 Subject: [PATCH 1/7] Update Intro information --- README.md | 9 +++------ pom.xml | 8 ++++---- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index d952bfa..8c29148 100644 --- a/README.md +++ b/README.md @@ -42,9 +42,6 @@ Regex | Input | Time Cost (Java Native) | Time Cost (DFA Regex) - escape characters - brackets -### Features Not Allowed Yet: -- capture groups `()` -- some zero width tokens `\b` -- look forward / look back `(?=)` `(?<)` -- anchor points `^` `$` -- ranged set `[0-9]` \ No newline at end of file +### Todo List: +- [POSIX-Extended Regex](http://www.boost.org/doc/libs/1_44_0/libs/regex/doc/html/boost_regex/syntax/basic_extended.html) syntax support +- Liner time searching \ No newline at end of file diff --git a/pom.xml b/pom.xml index 002614f..51d4e83 100644 --- a/pom.xml +++ b/pom.xml @@ -10,8 +10,8 @@ jar DFA-Regex - https://github.com/zbdzzg/DFA-Regex - A pretty fast regex engine built in java using pure DFA. + https://github.com/zhztheplayer/DFA-Regex + A Java DFA regex engine implementation. 2015 @@ -44,9 +44,9 @@ - zbdzzg + zhz Zhang Hongze - zbdzzg@sina.cn + talktozhz@126.com From d43099669bddb83386424560d997b5eb99e490a8 Mon Sep 17 00:00:00 2001 From: hongzezhang Date: Wed, 24 Jan 2018 11:57:53 +0800 Subject: [PATCH 2/7] Fixes #1; Clean code / Use checkstyle --- LICENSE | 2 +- checkstyle.xml | 148 ++++++++++++++++++ pom.xml | 42 ++++- .../java/top/yatt/dfargx/automata/DFA.java | 26 +-- .../java/top/yatt/dfargx/automata/NFA.java | 11 +- .../top/yatt/dfargx/automata/NFAState.java | 8 +- .../yatt/dfargx/automata/NFAStateFactory.java | 2 +- .../java/top/yatt/dfargx/tree/SyntaxTree.java | 34 ++-- src/test/java/RegexTest.java | 7 +- src/test/java/TreePrinter.java | 29 ++-- 10 files changed, 262 insertions(+), 47 deletions(-) create mode 100644 checkstyle.xml diff --git a/LICENSE b/LICENSE index 0f19a6c..c8a31ac 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright 2015-2016 yatt.top +Copyright 2015-2018 yatt.top Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/checkstyle.xml b/checkstyle.xml new file mode 100644 index 0000000..6d951d1 --- /dev/null +++ b/checkstyle.xml @@ -0,0 +1,148 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml index 51d4e83..0a27599 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ top.yatt.dfargx dfargx - 0.2.1 + 0.2.2-SNAPSHOT jar DFA-Regex @@ -36,9 +36,9 @@ - scm:git:git@github.com:zbdzzg/DFA-Regex.git - scm:git:git@github.com:zbdzzg/DFA-Regex.git - https://github.com/zbdzzg/DFA-Regex + scm:git:git@github.com:zhztheplayer/DFA-Regex.git + scm:git:git@github.com:zhztheplayer/DFA-Regex.git + https://github.com/zhztheplayer/DFA-Regex HEAD @@ -52,7 +52,7 @@ GitHub Issues - https://github.com/zbdzzg/DFA-Regex/issues + https://github.com/zhztheplayer/DFA-Regex/issues @@ -120,7 +120,37 @@ - + + org.apache.maven.plugins + maven-checkstyle-plugin + + + verify-style + process-classes + + check + + + + + checkstyle.xml + true + true + + + ${project.build.sourceDirectory} + + + + + + + com.puppycrawl.tools + checkstyle + 8.1 + + + diff --git a/src/main/java/top/yatt/dfargx/automata/DFA.java b/src/main/java/top/yatt/dfargx/automata/DFA.java index 0d0ec76..32b90e5 100644 --- a/src/main/java/top/yatt/dfargx/automata/DFA.java +++ b/src/main/java/top/yatt/dfargx/automata/DFA.java @@ -10,9 +10,12 @@ public class DFA { private int[][] transitionTable; - private int is; // init state - private int rs; // rejected state - private boolean[] fs; // final states + // init state + private int is; + // rejected state + private int rs; + // final states + private boolean[] fs; public DFA(List nfaStateList) { transitionTable = null; @@ -143,7 +146,7 @@ private void minimize(Map, Map>> oriDFATr // rename all states for (Set nfaState : oriDFATransitionMap.keySet()) { if (initStateAfterRenaming == -1 && nfaState.equals(initClosure)) { - initStateAfterRenaming = renamingStateID; // record init state id + initStateAfterRenaming = renamingStateID; // preserve init state id } stateRenamingMap.put(nfaState, renamingStateID++); } @@ -161,15 +164,20 @@ private void minimize(Map, Map>> oriDFATr renamedDFATransitionTable.put(renamingStateID, state); if (entry.getKey().contains(finalNFAState)) { finalFlags.put(renamingStateID, true); - } else finalFlags.put(renamingStateID, false); + } else { + finalFlags.put(renamingStateID, false); + } } - // split states to final states and non-final states + // group states to final states and non-final states Map groupFlags = new HashMap<>(); for (int i = 0; i < finalFlags.size(); i++) { boolean b = finalFlags.get(i); - if (b) groupFlags.put(i, 0); - else groupFlags.put(i, 1); + if (b) { + groupFlags.put(i, 0); + } else { + groupFlags.put(i, 1); + } } int groupTotal = 2; @@ -230,7 +238,7 @@ private void minimize(Map, Map>> oriDFATr fs[i] = finalGroupFlags.contains(i); } - // construct the final transition table + // construct the output transition table transitionTable = new int[groupTotal][]; for (int groupID = 0; groupID < groupTotal; groupID++) { diff --git a/src/main/java/top/yatt/dfargx/automata/NFA.java b/src/main/java/top/yatt/dfargx/automata/NFA.java index c96d428..f811658 100644 --- a/src/main/java/top/yatt/dfargx/automata/NFA.java +++ b/src/main/java/top/yatt/dfargx/automata/NFA.java @@ -7,13 +7,16 @@ import java.util.Stack; /** + * Only able to accept wfs accessing order, the class constructs a NFA by iterating the input syntax tree recursively + * from the root node. + * * Created on 2015/5/10. */ -public class NFA { // only able to accept wfs accessing order, this class construct a NFA with iterate the syntax tree recursively from the root node. +public class NFA { - private Stack stateStack; - private NFAStateFactory stateFactory; - private List stateList; + private final Stack stateStack; + private final NFAStateFactory stateFactory; + private final List stateList; public NFA(Node root) { stateList = new ArrayList<>(); diff --git a/src/main/java/top/yatt/dfargx/automata/NFAState.java b/src/main/java/top/yatt/dfargx/automata/NFAState.java index 3689188..c0a8d84 100644 --- a/src/main/java/top/yatt/dfargx/automata/NFAState.java +++ b/src/main/java/top/yatt/dfargx/automata/NFAState.java @@ -36,8 +36,12 @@ public int getId() { @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } NFAState state = (NFAState) o; return Objects.equals(id, state.id); } diff --git a/src/main/java/top/yatt/dfargx/automata/NFAStateFactory.java b/src/main/java/top/yatt/dfargx/automata/NFAStateFactory.java index c8ecf76..8031e97 100644 --- a/src/main/java/top/yatt/dfargx/automata/NFAStateFactory.java +++ b/src/main/java/top/yatt/dfargx/automata/NFAStateFactory.java @@ -4,7 +4,7 @@ * Created on 2015/5/10. */ public class NFAStateFactory { - private static int nextID; + private int nextID; public NFAStateFactory() { nextID = 0; diff --git a/src/main/java/top/yatt/dfargx/tree/SyntaxTree.java b/src/main/java/top/yatt/dfargx/tree/SyntaxTree.java index e6cb1bb..f3c39f0 100644 --- a/src/main/java/top/yatt/dfargx/tree/SyntaxTree.java +++ b/src/main/java/top/yatt/dfargx/tree/SyntaxTree.java @@ -2,11 +2,11 @@ import top.yatt.dfargx.stack.OperatingStack; import top.yatt.dfargx.stack.ShuntingStack; +import top.yatt.dfargx.tree.node.*; import top.yatt.dfargx.tree.node.bracket.LeftBracket; import top.yatt.dfargx.tree.node.bracket.RightBracket; import top.yatt.dfargx.util.CommonSets; import top.yatt.dfargx.util.InvalidSyntaxException; -import top.yatt.dfargx.tree.node.*; import java.util.*; @@ -69,17 +69,23 @@ private void normalize() { if (regex.charAt(index) == '^') { isComplementarySet = true; index++; - } else isComplementarySet = false; + } else { + isComplementarySet = false; + } for (char next = regex.charAt(index++); next != ']'; next = regex.charAt(index++)) { if (next == '\\' || next == '.') { String token; if (next == '\\') { char nextNext = regex.charAt(index++); token = new String(new char[]{next, nextNext}); - } else token = String.valueOf(next); + } else { + token = String.valueOf(next); + } List tokenSet = CommonSets.interpretToken(token); all.addAll(tokenSet); - } else all.add(next); + } else { + all.add(next); + } } char[] chSet = CommonSets.minimum(CommonSets.listToArray(all)); if (isComplementarySet) { @@ -88,7 +94,9 @@ private void normalize() { nodeList.add(new LeftBracket()); for (int i = 0; i < chSet.length; i++) { nodeList.add(new LChar(chSet[i])); - if (i == chSet.length - 1 || chSet[i + 1] == 0) break; + if (i == chSet.length - 1 || chSet[i + 1] == 0) { + break; + } nodeList.add(new BOr()); } nodeList.add(new RightBracket()); @@ -123,7 +131,9 @@ private void normalize() { most = Integer.parseInt(sb.toString()); } } - } else most = least; + } else { + most = least; + } performMany(least, most); itemTerminated = true; @@ -167,7 +177,9 @@ private void normalize() { if (ch == '\\') { char next = regex.charAt(index++); token = new String(new char[]{ch, next}); - } else token = String.valueOf(ch); + } else { + token = String.valueOf(ch); + } List tokenSet = CommonSets.interpretToken(token); nodeList.add(new LeftBracket()); nodeList.add(new LChar(tokenSet.get(0))); @@ -176,7 +188,9 @@ private void normalize() { nodeList.add(new LChar(tokenSet.get(i))); } nodeList.add(new RightBracket()); - } else nodeList.add(new LChar(ch)); + } else { + nodeList.add(new LChar(ch)); + } itemTerminated = true; break; @@ -209,7 +223,9 @@ private void performMany(int least, int most) { break; } } - } else sample = Collections.singletonList(nodeList.remove(nodeList.size() - 1)); + } else { + sample = Collections.singletonList(nodeList.remove(nodeList.size() - 1)); + } if (most == -1) { for (int i = 0; i < least; i++) { diff --git a/src/test/java/RegexTest.java b/src/test/java/RegexTest.java index f3ad4ed..889903a 100644 --- a/src/test/java/RegexTest.java +++ b/src/test/java/RegexTest.java @@ -1,15 +1,12 @@ import org.junit.Assert; import org.junit.Test; -import top.yatt.dfargx.MatchedText; import top.yatt.dfargx.RegexMatcher; -import top.yatt.dfargx.RegexSearcher; import top.yatt.dfargx.automata.DFA; import top.yatt.dfargx.automata.NFA; import top.yatt.dfargx.tree.SyntaxTree; import top.yatt.dfargx.tree.node.Node; import java.util.UUID; -import java.util.regex.Matcher; import java.util.regex.Pattern; /** @@ -20,7 +17,7 @@ public class RegexTest { //"([ab]([^cd]*\\w+(abc|abcd){2,5})+)?.*" @Test public void testProcessing() { - long pre = System.currentTimeMillis(); + final long pre = System.currentTimeMillis(); String regex = "(a*b|ab*)"; SyntaxTree tree = new SyntaxTree(regex); Node root = tree.getRoot(); @@ -69,7 +66,7 @@ public void testLog() { public void testFor(String regex, String str) { long prev; prev = System.currentTimeMillis(); - boolean expected = Pattern.compile(regex).matcher(str).matches(); + final boolean expected = Pattern.compile(regex).matcher(str).matches(); System.out.println(System.currentTimeMillis() - prev); prev = System.currentTimeMillis(); boolean actual = new RegexMatcher(regex).match(str); diff --git a/src/test/java/TreePrinter.java b/src/test/java/TreePrinter.java index daf9e54..bac11b0 100644 --- a/src/test/java/TreePrinter.java +++ b/src/test/java/TreePrinter.java @@ -39,8 +39,12 @@ public void printTree(Node root) { System.out.print(' '); } else if (i == width / 2) { System.out.print('|'); - } else System.out.print('-'); - } else System.out.print(' '); + } else { + System.out.print('-'); + } + } else { + System.out.print(' '); + } } System.out.print(s); for (int i = s.length(); i < width; i++) { @@ -49,8 +53,12 @@ public void printTree(Node root) { System.out.print('-'); } else if (i == width / 2 && t != h) { System.out.print('|'); - } else System.out.print(' '); - } else System.out.print(' '); + } else { + System.out.print(' '); + } + } else { + System.out.print(' '); + } } } if (++j == Math.pow(2, t) - 1) { @@ -79,16 +87,17 @@ private void complete(Node node, int k, int h) { } } - private int calculateDepth(Node node, int depth) { - depth += 1; - int l = depth, r = depth; + private int calculateDepth(Node node, final int depth) { + int td = depth + 1; + int l = td; + int r = td; if (node.hasLeft()) { - l = calculateDepth(node.left(), depth); + l = calculateDepth(node.left(), td); } if (node.hasRight()) { - r = calculateDepth(node.right(), depth); + r = calculateDepth(node.right(), td); } - return l > r ? l : r > depth ? r : depth; + return l > r ? l : r > td ? r : td; } private Node copyTree(Node root) { From 2a8bfdbdb7f24ce914e90a3cb6a9284f8058bc31 Mon Sep 17 00:00:00 2001 From: amuniz Date: Wed, 11 Apr 2018 11:44:32 +0200 Subject: [PATCH 3/7] Regular expressions comparison --- .../java/top/yatt/dfargx/RegexComparator.java | 24 +++++++++++++ .../java/top/yatt/dfargx/automata/DFA.java | 27 ++++++++++++++ src/test/java/RegexComparatorTest.java | 35 +++++++++++++++++++ 3 files changed, 86 insertions(+) create mode 100644 src/main/java/top/yatt/dfargx/RegexComparator.java create mode 100644 src/test/java/RegexComparatorTest.java diff --git a/src/main/java/top/yatt/dfargx/RegexComparator.java b/src/main/java/top/yatt/dfargx/RegexComparator.java new file mode 100644 index 0000000..576defa --- /dev/null +++ b/src/main/java/top/yatt/dfargx/RegexComparator.java @@ -0,0 +1,24 @@ +package top.yatt.dfargx; + +import top.yatt.dfargx.automata.DFA; +import top.yatt.dfargx.automata.NFA; +import top.yatt.dfargx.tree.SyntaxTree; + +public class RegexComparator { + + /** + * Checks if the matching space of regexp2 is contained by the matching space of regexp1. + */ + public static final boolean isContained(String regexp1, String regexp2) { + SyntaxTree syntaxTree = new SyntaxTree(regexp1); + NFA nfa = new NFA(syntaxTree.getRoot()); + DFA dfa = new DFA(nfa.getStateList()); + + SyntaxTree syntaxTree2 = new SyntaxTree(regexp1 + "|" + regexp2); + NFA nfa2 = new NFA(syntaxTree2.getRoot()); + DFA dfa2 = new DFA(nfa2.getStateList()); + + return dfa.equals(dfa2); + + } +} diff --git a/src/main/java/top/yatt/dfargx/automata/DFA.java b/src/main/java/top/yatt/dfargx/automata/DFA.java index 32b90e5..f2165e8 100644 --- a/src/main/java/top/yatt/dfargx/automata/DFA.java +++ b/src/main/java/top/yatt/dfargx/automata/DFA.java @@ -40,6 +40,33 @@ public boolean[] getFinalStates() { return fs; } + @Override + public boolean equals(Object o) { + if (!(o instanceof DFA)) { + return false; + } + DFA other = (DFA) o; + if (other.is == this.is && other.rs == this.rs) { + if (other.fs.length != this.fs.length) { + return false; + } + for (int i = 0; i < other.fs.length; i++) { + if (other.fs[i] != this.fs[i]) { + return false; + } + } + for (int i = 0; i < other.transitionTable.length; i++) { + for (int j = 0; j < other.transitionTable[i].length; j++) { + if (other.transitionTable[i][j] != this.transitionTable[i][j]) { + return false; + } + } + } + return true; + } + return false; + } + private void convert(List nfaStateList) { NFAState initState = nfaStateList.get(0); NFAState finalState = nfaStateList.get(1); diff --git a/src/test/java/RegexComparatorTest.java b/src/test/java/RegexComparatorTest.java new file mode 100644 index 0000000..6d3a1a9 --- /dev/null +++ b/src/test/java/RegexComparatorTest.java @@ -0,0 +1,35 @@ +import org.junit.Test; +import top.yatt.dfargx.RegexComparator; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +public class RegexComparatorTest { + + @Test + public void basicComparisons() { + // /A/**/* vs /A/B/C + assertTrue(RegexComparator.isContained("/A/(.)+", "/A/B/C")); + + // /A/**/D vs /A/**/B/D + assertTrue(RegexComparator.isContained("/A/(.)+/D", "/A/(.)+/B/D")); + + // /A/**/D vs /A/**/B/C + assertFalse(RegexComparator.isContained("/A/(.)+/D", "/A/(.)+/B/C")); + + // /A/B/C vs /A/B/C/D + assertFalse(RegexComparator.isContained("/A/B/C", "/A/B/C/D")); + + // /A/B/C/* vs /A/B/C/D + assertTrue(RegexComparator.isContained("/A/B/C/[^/]+", "/A/B/C/D")); + + // /A/B/C/* vs /A/B/C/D/E + assertFalse(RegexComparator.isContained("/A/B/C/[^/]+", "/A/B/C/D/E")); + + // /**/* vs /A/B/C/D/E + assertTrue(RegexComparator.isContained("/(.)*", "/A/B/C/D/E")); + + // /**/C/* vs /**/* + assertFalse(RegexComparator.isContained("/(.)+/C/[^/]+", "/(.)*")); + } +} From c888e79fea2976039c18e67071cb77a4d6fc4299 Mon Sep 17 00:00:00 2001 From: amuniz Date: Wed, 11 Apr 2018 11:55:11 +0200 Subject: [PATCH 4/7] A little explanation --- src/main/java/top/yatt/dfargx/RegexComparator.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/top/yatt/dfargx/RegexComparator.java b/src/main/java/top/yatt/dfargx/RegexComparator.java index 576defa..5e7416d 100644 --- a/src/main/java/top/yatt/dfargx/RegexComparator.java +++ b/src/main/java/top/yatt/dfargx/RegexComparator.java @@ -14,6 +14,8 @@ public static final boolean isContained(String regexp1, String regexp2) { NFA nfa = new NFA(syntaxTree.getRoot()); DFA dfa = new DFA(nfa.getStateList()); + // by definition if the matching space of A is equal than the matching space of A|B then B is contained in A + // similarly, if DFA(A) is identical to DFA(A|B) then B is contained in A. SyntaxTree syntaxTree2 = new SyntaxTree(regexp1 + "|" + regexp2); NFA nfa2 = new NFA(syntaxTree2.getRoot()); DFA dfa2 = new DFA(nfa2.getStateList()); From 3a098cdb519d932c9ff4cdacfdbfa32b1fdd34cc Mon Sep 17 00:00:00 2001 From: amuniz Date: Fri, 13 Apr 2018 18:19:57 +0200 Subject: [PATCH 5/7] Improved DFA#equals to properly check equivalent transition graphs --- .../java/top/yatt/dfargx/RegexComparator.java | 4 +- .../java/top/yatt/dfargx/automata/DFA.java | 47 +++++++++++++------ src/test/java/RegexComparatorTest.java | 24 ++++++---- 3 files changed, 50 insertions(+), 25 deletions(-) diff --git a/src/main/java/top/yatt/dfargx/RegexComparator.java b/src/main/java/top/yatt/dfargx/RegexComparator.java index 5e7416d..fc76ed7 100644 --- a/src/main/java/top/yatt/dfargx/RegexComparator.java +++ b/src/main/java/top/yatt/dfargx/RegexComparator.java @@ -7,9 +7,9 @@ public class RegexComparator { /** - * Checks if the matching space of regexp2 is contained by the matching space of regexp1. + * Checks if the matching space of regexp1 contains the matching space of regexp1. */ - public static final boolean isContained(String regexp1, String regexp2) { + public static final boolean contains(String regexp1, String regexp2) { SyntaxTree syntaxTree = new SyntaxTree(regexp1); NFA nfa = new NFA(syntaxTree.getRoot()); DFA dfa = new DFA(nfa.getStateList()); diff --git a/src/main/java/top/yatt/dfargx/automata/DFA.java b/src/main/java/top/yatt/dfargx/automata/DFA.java index f2165e8..652e93d 100644 --- a/src/main/java/top/yatt/dfargx/automata/DFA.java +++ b/src/main/java/top/yatt/dfargx/automata/DFA.java @@ -46,25 +46,44 @@ public boolean equals(Object o) { return false; } DFA other = (DFA) o; - if (other.is == this.is && other.rs == this.rs) { - if (other.fs.length != this.fs.length) { - return false; + + int [][] checked = new int[transitionTable.length][other.transitionTable.length]; + return dfaEquivalenceCheck(other, is, other.is, checked); + } + + private boolean dfaEquivalenceCheck(DFA other, int initialState, int otherInitialState, int [][] checked) { + // transitions for this DFA for state initialState + int initialTransitions[] = transitionTable[initialState]; + // transitions for the other DFA for state otherInitialState + int otherInitialTransitions[] = other.transitionTable[otherInitialState]; + + // For every possible transition from initialState (and otherInitialState) + for (int i = 0; i < initialTransitions.length; i++) { + + // if the target state is already computed in previous iterations, skip + if (checked[initialTransitions[i]][otherInitialTransitions[i]] == 1) { + continue; } - for (int i = 0; i < other.fs.length; i++) { - if (other.fs[i] != this.fs[i]) { + // mark the transition as computed + checked[initialTransitions[i]][otherInitialTransitions[i]] = 1; + + if (fs[initialTransitions[i]] != other.fs[otherInitialTransitions[i]]) { + // one transition goes to a final state and the other does not, this DFA is not equivalent + return false; + } else if ((initialTransitions[i] == rs && otherInitialTransitions[i] != other.rs) + || (initialTransitions[i] != rs && otherInitialTransitions[i] == other.rs)) { + // one transition goes to rejected state and the other does not, this DFA is not equivalent + return false; + } else if (fs[initialTransitions[i]] == false && other.fs[otherInitialTransitions[i]] == false) { + // both transitions go to intermediate states, needs further computing using current states as initial + if (!dfaEquivalenceCheck(other, initialTransitions[i], otherInitialTransitions[i], checked)) { + // the transition is not equivalent further down, this DFA is not equivalent return false; } } - for (int i = 0; i < other.transitionTable.length; i++) { - for (int j = 0; j < other.transitionTable[i].length; j++) { - if (other.transitionTable[i][j] != this.transitionTable[i][j]) { - return false; - } - } - } - return true; } - return false; + // All transitions check were equivalent, this DFA is equivalent + return true; } private void convert(List nfaStateList) { diff --git a/src/test/java/RegexComparatorTest.java b/src/test/java/RegexComparatorTest.java index 6d3a1a9..ff841c2 100644 --- a/src/test/java/RegexComparatorTest.java +++ b/src/test/java/RegexComparatorTest.java @@ -9,27 +9,33 @@ public class RegexComparatorTest { @Test public void basicComparisons() { // /A/**/* vs /A/B/C - assertTrue(RegexComparator.isContained("/A/(.)+", "/A/B/C")); + assertTrue(RegexComparator.contains("/A/(.)+", "/A/B/C")); // /A/**/D vs /A/**/B/D - assertTrue(RegexComparator.isContained("/A/(.)+/D", "/A/(.)+/B/D")); + assertTrue(RegexComparator.contains("/A/(.)+/D", "/A/(.)+/B/D")); // /A/**/D vs /A/**/B/C - assertFalse(RegexComparator.isContained("/A/(.)+/D", "/A/(.)+/B/C")); + assertFalse(RegexComparator.contains("/A/(.)+/D", "/A/(.)+/B/C")); // /A/B/C vs /A/B/C/D - assertFalse(RegexComparator.isContained("/A/B/C", "/A/B/C/D")); + assertFalse(RegexComparator.contains("/A/B/C$", "/A/B/C/D$")); // /A/B/C/* vs /A/B/C/D - assertTrue(RegexComparator.isContained("/A/B/C/[^/]+", "/A/B/C/D")); + assertTrue(RegexComparator.contains("/A/B/C/[^/]+", "/A/B/C/D")); - // /A/B/C/* vs /A/B/C/D/E - assertFalse(RegexComparator.isContained("/A/B/C/[^/]+", "/A/B/C/D/E")); + // /A/B/C/* vs /A/B/C/D/* + assertFalse(RegexComparator.contains("/A/B/C/[^/]+$", "/A/B/C/D/(.)+$")); // /**/* vs /A/B/C/D/E - assertTrue(RegexComparator.isContained("/(.)*", "/A/B/C/D/E")); + assertTrue(RegexComparator.contains("/(.)*", "/A/B/C/D/E")); // /**/C/* vs /**/* - assertFalse(RegexComparator.isContained("/(.)+/C/[^/]+", "/(.)*")); + assertFalse(RegexComparator.contains("/(.)+/C/[^/]+", "/(.)*")); + + // **/B/* vs /A/B/* + assertTrue(RegexComparator.contains("/(.)+/B/[^/]+", "/A/B/[^/]+")); + + // **/* vs A/B/* + assertTrue(RegexComparator.contains("/(.)*", "/A/B/[^/]+")); } } From 233c20256a98f83a587c8f0c02c188509a973cce Mon Sep 17 00:00:00 2001 From: amuniz Date: Fri, 13 Apr 2018 18:24:14 +0200 Subject: [PATCH 6/7] Fix checkstyle --- src/main/java/top/yatt/dfargx/automata/DFA.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/top/yatt/dfargx/automata/DFA.java b/src/main/java/top/yatt/dfargx/automata/DFA.java index 652e93d..4fc9d90 100644 --- a/src/main/java/top/yatt/dfargx/automata/DFA.java +++ b/src/main/java/top/yatt/dfargx/automata/DFA.java @@ -53,9 +53,9 @@ public boolean equals(Object o) { private boolean dfaEquivalenceCheck(DFA other, int initialState, int otherInitialState, int [][] checked) { // transitions for this DFA for state initialState - int initialTransitions[] = transitionTable[initialState]; + int [] initialTransitions = transitionTable[initialState]; // transitions for the other DFA for state otherInitialState - int otherInitialTransitions[] = other.transitionTable[otherInitialState]; + int [] otherInitialTransitions = other.transitionTable[otherInitialState]; // For every possible transition from initialState (and otherInitialState) for (int i = 0; i < initialTransitions.length; i++) { From c7e56f0f67bce932b9ecdc26112ec3c133aba2a1 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 12 Oct 2020 22:24:08 +0000 Subject: [PATCH 7/7] Bump junit from 4.12 to 4.13.1 Bumps [junit](https://github.com/junit-team/junit4) from 4.12 to 4.13.1. - [Release notes](https://github.com/junit-team/junit4/releases) - [Changelog](https://github.com/junit-team/junit4/blob/main/doc/ReleaseNotes4.12.md) - [Commits](https://github.com/junit-team/junit4/compare/r4.12...r4.13.1) Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 0a27599..77157ce 100644 --- a/pom.xml +++ b/pom.xml @@ -159,7 +159,7 @@ junit junit - 4.12 + 4.13.1 test