]> gitweb.factorcode.org Git - factor.git/blobdiff - basis/regexp/dfa/dfa.factor
use reject instead of [ ... not ] filter.
[factor.git] / basis / regexp / dfa / dfa.factor
index 2de4e8b0e02322d7a3391c86f607944d18125ace..5c77741032499c70d8967074a5ba88f96cf00c8e 100644 (file)
@@ -25,7 +25,7 @@ IN: regexp.dfa
     ] unless ;
 
 : epsilon-table ( states nfa -- table )
-    [ H{ } clone tuck ] dip
+    [ [ H{ } clone ] dip over ] dip
     '[ _ _ t epsilon-loop ] each ;
 
 : find-epsilon-closure ( states nfa -- dfa-state )
@@ -40,12 +40,10 @@ IN: regexp.dfa
 : find-transitions ( dfa-state nfa -- next-dfa-state )
     transitions>>
     '[ _ at keys [ condition-states ] map concat ] gather
-    [ tagged-epsilon? not ] filter ;
+    [ tagged-epsilon? ] reject ;
 
 : add-todo-state ( state visited-states new-states -- )
-    3dup drop key? [ 3drop ] [
-        [ conjoin ] [ push ] bi-curry* bi
-    ] if ;
+    2over ?adjoin [ nip push ] [ 3drop ] if ;
 
 : add-todo-states ( state/condition visited-states new-states -- )
     [ condition-states ] 2dip
@@ -69,11 +67,11 @@ IN: regexp.dfa
 
 : set-final-states ( nfa dfa -- )
     [
-        [ final-states>> keys ]
+        [ final-states>> members ]
         [ transitions>> keys ] bi*
         [ intersects? ] with filter
-        unique
-    ] keep (>>final-states) ;
+        fast-set
+    ] keep final-states<< ;
 
 : initialize-dfa ( nfa -- dfa )
     <transition-table>
@@ -82,6 +80,6 @@ IN: regexp.dfa
 : construct-dfa ( nfa -- dfa )
     dup initialize-dfa
     dup start-state>> condition-states >vector
-    H{ } clone
+    HS{ } clone
     new-transitions
     [ set-final-states ] keep ;