mirror of
https://github.com/github/semantic.git
synced 2024-12-24 07:25:44 +03:00
Clean up some insertDiff
This commit is contained in:
parent
3d36d0fc59
commit
24e02273d1
@ -22,7 +22,6 @@ import Data.Functor.Foldable as Foldable
|
|||||||
import Data.Hashable
|
import Data.Hashable
|
||||||
import qualified Data.IntMap as IntMap
|
import qualified Data.IntMap as IntMap
|
||||||
import qualified Data.KdTree.Static as KdTree
|
import qualified Data.KdTree.Static as KdTree
|
||||||
import qualified Data.List as List
|
|
||||||
import Data.Semigroup (Min(..), Option(..))
|
import Data.Semigroup (Min(..), Option(..))
|
||||||
import Data.Record
|
import Data.Record
|
||||||
import qualified Data.Vector as Vector
|
import qualified Data.Vector as Vector
|
||||||
@ -166,16 +165,15 @@ insertDiff a@(ij1, _) (b@(ij2, _):rest) = case (ij1, ij2) of
|
|||||||
(That _, This _) -> b : insertDiff a rest -- Amb a b rest
|
(That _, This _) -> b : insertDiff a rest -- Amb a b rest
|
||||||
|
|
||||||
(These i1 i2, _) -> case break (isThese . fst) rest of
|
(These i1 i2, _) -> case break (isThese . fst) rest of
|
||||||
(rest, tail) -> let (before, after) = foldr' (combine i1 i2) ([] {- elements before a -}, [] {- elements after a -}) (b : rest) in
|
(rest, tail) -> let (before, after) = foldr' (combine i1 i2) ([], []) (b : rest) in
|
||||||
case after of
|
case after of
|
||||||
[] -> before <> insertDiff a tail
|
[] -> before <> insertDiff a tail
|
||||||
_ -> before <> (a : after) <> tail
|
_ -> before <> (a : after) <> tail
|
||||||
where
|
where
|
||||||
combine i1 i2 = (\each (before, after) -> case fst each of
|
combine i1 i2 each (before, after) = case fst each of
|
||||||
This j1 -> if i1 <= j1 then (before, each : after) else (each : before, after)
|
This j1 -> if i1 <= j1 then (before, each : after) else (each : before, after)
|
||||||
That j2 -> if i2 <= j2 then (before, each : after) else (each : before, after)
|
That j2 -> if i2 <= j2 then (before, each : after) else (each : before, after)
|
||||||
)
|
These _ _ -> (before, after)
|
||||||
|
|
||||||
-- | Return an edit distance as the sum of it's term sizes, given an cutoff and a syntax of terms 'f a'.
|
-- | Return an edit distance as the sum of it's term sizes, given an cutoff and a syntax of terms 'f a'.
|
||||||
-- | Computes a constant-time approximation to the edit distance of a diff. This is done by comparing at most _m_ nodes, & assuming the rest are zero-cost.
|
-- | Computes a constant-time approximation to the edit distance of a diff. This is done by comparing at most _m_ nodes, & assuming the rest are zero-cost.
|
||||||
editDistanceUpTo :: (Prologue.Foldable f, Functor f) => Integer -> Free (CofreeF f (Both a)) (Patch (Cofree f a)) -> Int
|
editDistanceUpTo :: (Prologue.Foldable f, Functor f) => Integer -> Free (CofreeF f (Both a)) (Patch (Cofree f a)) -> Int
|
||||||
|
Loading…
Reference in New Issue
Block a user