Add epsilon transitions

This commit is contained in:
Joscha 2019-10-26 10:10:45 +00:00
parent 11f0f68513
commit 02bf60b095
4 changed files with 109 additions and 57 deletions

19
src/Rextra/Util.hs Normal file
View file

@ -0,0 +1,19 @@
module Rextra.Util
( connectedElements
) where
import Control.Monad
import Control.Monad.Trans.State
import qualified Data.Map as Map
import qualified Data.Set as Set
explore :: (Ord n) => (n -> Set.Set n) -> n -> State (Set.Set n) ()
explore trans node = do
visited <- get
unless (node `Set.member` visited) $ do
modify (Set.insert node)
mapM_ (explore trans) . Set.toList $ trans node
connectedElements :: (Ord n) => (n -> Set.Set n) -> Set.Set n -> Set.Set n
connectedElements trans startingNodes =
flip execState Set.empty . mapM (explore trans) $ Set.toList startingNodes