1
1
mirror of https://github.com/github/semantic.git synced 2024-12-03 00:16:52 +03:00

Extract the SES evaluator.

This commit is contained in:
Rob Rix 2017-03-23 10:03:03 -04:00
parent 2ef802e8d7
commit 5955e7665d

View File

@ -90,17 +90,9 @@ runMyersStep eq state step = let ?callStack = popCallStack callStack in case ste
decompose :: HasCallStack => MyersF a b c -> Myers a b c
decompose myers = let ?callStack = popCallStack callStack in case myers of
SES graph -> runSES graph
LCS graph -> runLCS graph
SES (EditGraph as bs)
| null bs -> return (This <$> toList as)
| null as -> return (That <$> toList bs)
| otherwise -> do
result <- for [0..(length as + length bs)] (searchUpToD (EditGraph as bs) . Distance)
case result of
Just (script, _) -> return (reverse script)
_ -> fail "no shortest edit script found in edit graph (this is a bug in SES.Myers)."
EditDistance graph -> length . filter (these (const True) (const True) (const (const False))) <$> ses graph
SearchUpToD graph (Distance d) -> for [negate d, negate d + 2 .. d] (searchAlongK graph (Distance d) . Diagonal)
@ -166,6 +158,16 @@ decompose myers = let ?callStack = popCallStack callStack in case myers of
throw (MyersException ("index " <> show i <> " out of bounds") callStack)
runSES :: HasCallStack => EditGraph a b -> Myers a b (EditScript a b)
runSES (EditGraph as bs)
| null bs = return (This <$> toList as)
| null as = return (That <$> toList bs)
| otherwise = let ?callStack = popCallStack callStack in do
result <- for [0..(length as + length bs)] (searchUpToD (EditGraph as bs) . Distance)
case result of
Just (script, _) -> return (reverse script)
_ -> fail "no shortest edit script found in edit graph (this is a bug in SES.Myers)."
runLCS :: HasCallStack => EditGraph a b -> Myers a b [(a, b)]
runLCS (EditGraph as bs)
| null as || null bs = return []