Skip to content

Commit f691e0e

Browse files
committed
explicit binding for refinement
1 parent f4ca6db commit f691e0e

File tree

1 file changed

+20
-13
lines changed

1 file changed

+20
-13
lines changed

src/DFAMin.hs

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -179,21 +179,28 @@ groupEquivStates DFA { dfa_states = statemap }
179179
]
180180
#endif
181181

182+
refineWith
183+
:: IntSet -- preimage set that bisects the input equivalence class
184+
-> IntSet -- initial equivalence class
185+
-> Maybe (IntSet, IntSet)
186+
refineWith x y =
187+
if IS.null y1 || IS.null y2
188+
then Nothing
189+
else Just (y1, y2)
190+
where
191+
y1 = IS.intersection y x
192+
y2 = IS.difference y x
193+
182194
go0 (r,q) x = go1 r [] []
183195
where
184196
go1 [] r' q' = (r', go2 q q')
185-
go1 (y:r) r' q'
186-
| IS.null y1 || IS.null y2 = go1 r (y:r') q'
187-
| IS.size y1 <= IS.size y2 = go1 r (y2:r') (y1:q')
188-
| otherwise = go1 r (y1:r') (y2:q')
189-
where
190-
y1 = IS.intersection x y
191-
y2 = IS.difference y x
197+
go1 (y:r) r' q' = case refineWith x y of
198+
Nothing -> go1 r (y:r') q'
199+
Just (y1, y2)
200+
| IS.size y1 <= IS.size y2 -> go1 r (y2:r') (y1:q')
201+
| otherwise -> go1 r (y1:r') (y2:q')
192202

193203
go2 [] q' = q'
194-
go2 (y:q) q'
195-
| IS.null y1 || IS.null y2 = go2 q (y:q')
196-
| otherwise = go2 q (y1:y2:q')
197-
where
198-
y1 = IS.intersection x y
199-
y2 = IS.difference y x
204+
go2 (y:q) q' = case refineWith x y of
205+
Nothing -> go2 q (y:q')
206+
Just (y1, y2) -> go2 q (y1:y2:q')

0 commit comments

Comments
 (0)