mirror of
https://github.com/github/semantic.git
synced 2024-11-24 08:54:07 +03:00
Revert "Represent term/diff costs as Rational
s."
This reverts commit aea4e7ec784422696631156415855eab920af38a.
This commit is contained in:
parent
9049478594
commit
338ed4a5ce
@ -15,9 +15,9 @@ type instance Base (Free f a) = FreeF f a
|
||||
instance (Functor f) => Foldable.Foldable (Free f a) where project = runFree
|
||||
instance (Functor f) => Foldable.Unfoldable (Free f a) where embed = free
|
||||
|
||||
diffSum :: (Patch (Term a annotation) -> Rational) -> Diff a annotation -> Rational
|
||||
diffSum :: (Patch (Term a annotation) -> Integer) -> Diff a annotation -> Integer
|
||||
diffSum patchCost diff = sum $ fmap patchCost diff
|
||||
|
||||
-- | The sum of the node count of the diff’s patches.
|
||||
diffCost :: Diff a annotation -> Rational
|
||||
diffCost :: Diff a annotation -> Integer
|
||||
diffCost = diffSum $ patchSum termSize
|
||||
|
@ -86,11 +86,11 @@ diffFiles parser renderer sourceBlobs = do
|
||||
pure $! renderer (runBothWith (diffTerms diffCostWithCachedTermSizes) $ replaceLeaves <*> terms) sourceBlobs
|
||||
|
||||
-- | The sum of the node count of the diff’s patches.
|
||||
diffCostWithCachedTermSizes :: Diff a Info -> Rational
|
||||
diffCostWithCachedTermSizes :: Diff a Info -> Integer
|
||||
diffCostWithCachedTermSizes = diffSum (getSum . foldMap (Sum . size . extract))
|
||||
|
||||
-- | The absolute difference between the node counts of a diff.
|
||||
diffCostWithAbsoluteDifferenceOfCachedDiffSizes :: Diff a Info -> Rational
|
||||
diffCostWithAbsoluteDifferenceOfCachedDiffSizes :: Diff a Info -> Integer
|
||||
diffCostWithAbsoluteDifferenceOfCachedDiffSizes diff = case runFree diff of
|
||||
Free (Join (before, after) :< _) -> abs $ size before - size after
|
||||
Pure patch -> sum $ size . extract <$> patch
|
||||
|
@ -6,7 +6,7 @@ import Range
|
||||
|
||||
-- | An annotation for a source file, including the source range and semantic
|
||||
-- | categories.
|
||||
data Info = Info { characterRange :: !Range, categories :: !(Set Category), size :: !Rational }
|
||||
data Info = Info { characterRange :: !Range, categories :: !(Set Category), size :: !Integer }
|
||||
deriving (Eq, Show)
|
||||
|
||||
instance Categorizable Info where
|
||||
|
@ -33,7 +33,7 @@ unPatch (Insert b) = That b
|
||||
unPatch (Delete a) = This a
|
||||
|
||||
-- | Calculate the cost of the patch given a function to compute the cost of a item.
|
||||
patchSum :: (a -> Rational) -> Patch a -> Rational
|
||||
patchSum :: (a -> Integer) -> Patch a -> Integer
|
||||
patchSum termCost patch = maybe 0 termCost (before patch) + maybe 0 termCost (after patch)
|
||||
|
||||
-- | Return Just the value in This, or the first value in These, if any.
|
||||
|
@ -10,7 +10,7 @@ import qualified Data.Map as Map
|
||||
type Compare a annotation = Term a annotation -> Term a annotation -> Maybe (Diff a annotation)
|
||||
|
||||
-- | A function that computes the cost of a diff.
|
||||
type Cost a annotation = Diff a annotation -> Rational
|
||||
type Cost a annotation = Diff a annotation -> Integer
|
||||
|
||||
-- | Find the shortest edit script (diff) between two terms given a function to compute the cost.
|
||||
ses :: Compare a annotation -> Cost a annotation -> [Term a annotation] -> [Term a annotation] -> [Diff a annotation]
|
||||
@ -18,7 +18,7 @@ ses diffTerms cost as bs = fst <$> evalState diffState Map.empty where
|
||||
diffState = diffAt diffTerms cost (0, 0) as bs
|
||||
|
||||
-- | Find the shortest edit script between two terms at a given vertex in the edit graph.
|
||||
diffAt :: Compare a annotation -> Cost a annotation -> (Integer, Integer) -> [Term a annotation] -> [Term a annotation] -> State (Map.Map (Integer, Integer) [(Diff a annotation, Rational)]) [(Diff a annotation, Rational)]
|
||||
diffAt :: Compare a annotation -> Cost a annotation -> (Integer, Integer) -> [Term a annotation] -> [Term a annotation] -> State (Map.Map (Integer, Integer) [(Diff a annotation, Integer)]) [(Diff a annotation, Integer)]
|
||||
diffAt _ _ _ [] [] = pure []
|
||||
diffAt _ cost _ [] bs = pure $ foldr toInsertions [] bs where
|
||||
toInsertions each = consWithCost cost (free . Pure . Insert $ each)
|
||||
@ -48,5 +48,5 @@ diffAt diffTerms cost (i, j) (a : as) (b : bs) = do
|
||||
recur = diffAt diffTerms cost
|
||||
|
||||
-- | Prepend a diff to the list with the cumulative cost.
|
||||
consWithCost :: Cost a annotation -> Diff a annotation -> [(Diff a annotation, Rational)] -> [(Diff a annotation, Rational)]
|
||||
consWithCost :: Cost a annotation -> Diff a annotation -> [(Diff a annotation, Integer)] -> [(Diff a annotation, Integer)]
|
||||
consWithCost cost diff rest = (diff, cost diff + maybe 0 snd (fst <$> uncons rest)) : rest
|
||||
|
@ -30,6 +30,6 @@ zipTerms t1 t2 = annotate (zipUnwrap a b)
|
||||
zipUnwrapMaps a' b' key = (,) key <$> zipTerms (a' ! key) (b' ! key)
|
||||
|
||||
-- | Return the node count of a term.
|
||||
termSize :: Term a annotation -> Rational
|
||||
termSize :: Term a annotation -> Integer
|
||||
termSize = cata size where
|
||||
size (_ :< syntax) = 1 + sum syntax
|
||||
|
Loading…
Reference in New Issue
Block a user