Diff 0.3.4 → 0.4.0
raw patch · 6 files changed
+23/−15 lines, 6 filessetup-changedPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
- Data.Algorithm.Diff: data Diff a
- Data.Algorithm.Diff: instance GHC.Classes.Eq a => GHC.Classes.Eq (Data.Algorithm.Diff.Diff a)
- Data.Algorithm.Diff: instance GHC.Show.Show a => GHC.Show.Show (Data.Algorithm.Diff.Diff a)
+ Data.Algorithm.Diff: data PolyDiff a b
+ Data.Algorithm.Diff: instance (GHC.Classes.Eq a, GHC.Classes.Eq b) => GHC.Classes.Eq (Data.Algorithm.Diff.PolyDiff a b)
+ Data.Algorithm.Diff: instance (GHC.Show.Show a, GHC.Show.Show b) => GHC.Show.Show (Data.Algorithm.Diff.PolyDiff a b)
+ Data.Algorithm.Diff: type Diff a = PolyDiff a a
- Data.Algorithm.Diff: Both :: a -> a -> Diff a
+ Data.Algorithm.Diff: Both :: a -> b -> PolyDiff a b
- Data.Algorithm.Diff: First :: a -> Diff a
+ Data.Algorithm.Diff: First :: a -> PolyDiff a b
- Data.Algorithm.Diff: Second :: a -> Diff a
+ Data.Algorithm.Diff: Second :: b -> PolyDiff a b
- Data.Algorithm.Diff: getDiff :: (Eq t) => [t] -> [t] -> [Diff t]
+ Data.Algorithm.Diff: getDiff :: Eq a => [a] -> [a] -> [Diff a]
- Data.Algorithm.Diff: getDiffBy :: (t -> t -> Bool) -> [t] -> [t] -> [Diff t]
+ Data.Algorithm.Diff: getDiffBy :: (a -> b -> Bool) -> [a] -> [b] -> [PolyDiff a b]
- Data.Algorithm.Diff: getGroupedDiff :: (Eq t) => [t] -> [t] -> [Diff [t]]
+ Data.Algorithm.Diff: getGroupedDiff :: Eq a => [a] -> [a] -> [Diff [a]]
- Data.Algorithm.Diff: getGroupedDiffBy :: (t -> t -> Bool) -> [t] -> [t] -> [Diff [t]]
+ Data.Algorithm.Diff: getGroupedDiffBy :: (a -> b -> Bool) -> [a] -> [b] -> [PolyDiff [a] [b]]
Files
- Diff.cabal +5/−1
- Setup.hs +3/−0
- Setup.lhs +0/−3
- src/Data/Algorithm/Diff.hs +13/−9
- src/Data/Algorithm/DiffContext.hs +1/−1
- test/Test.hs +1/−1
Diff.cabal view
@@ -1,5 +1,5 @@ name: Diff-version: 0.3.4+version: 0.4.0 synopsis: O(ND) diff algorithm in haskell. description: Implementation of the standard diff algorithm, and utilities for pretty printing. category: Algorithms@@ -32,3 +32,7 @@ , pretty, QuickCheck, test-framework , test-framework-quickcheck2, process , directory+ other-modules:+ Data.Algorithm.Diff,+ Data.Algorithm.DiffOutput+ Data.Algorithm.DiffContext
+ Setup.hs view
@@ -0,0 +1,3 @@+#!/usr/bin/env runhaskell+import Distribution.Simple+main = defaultMain
− Setup.lhs
@@ -1,3 +0,0 @@-#!/usr/bin/env runhaskell-> import Distribution.Simple-> main = defaultMain
src/Data/Algorithm/Diff.hs view
@@ -14,7 +14,7 @@ ----------------------------------------------------------------------------- module Data.Algorithm.Diff- ( Diff(..)+ ( Diff, PolyDiff(..) -- * Comparing lists for differences , getDiff , getDiffBy@@ -26,7 +26,7 @@ import Prelude hiding (pi) -import Data.Array+import Data.Array (listArray, (!)) data DI = F | S | B deriving (Show, Eq) @@ -34,8 +34,12 @@ -- 'Both' contains both the left and right values, in case you are using a form -- of equality that doesn't check all data (for example, if you are using a -- newtype to only perform equality on side of a tuple).-data Diff a = First a | Second a | Both a a deriving (Show, Eq)+data PolyDiff a b = First a | Second b | Both a b+ deriving (Show, Eq) +-- | This is 'PolyDiff' specialized so both sides are the same type.+type Diff a = PolyDiff a a+ data DL = DL {poi :: !Int, poj :: !Int, path::[DI]} deriving (Show, Eq) instance Ord DL@@ -43,7 +47,7 @@ then poj x > poj y else poi x <= poi y -canDiag :: (a -> a -> Bool) -> [a] -> [a] -> Int -> Int -> Int -> Int -> Bool+canDiag :: (a -> b -> Bool) -> [a] -> [b] -> Int -> Int -> Int -> Int -> Bool canDiag eq as bs lena lenb = \ i j -> if i < lena && j < lenb then (arAs ! i) `eq` (arBs ! j) else False where arAs = listArray (0,lena - 1) as@@ -68,7 +72,7 @@ | otherwise = dl where pi = poi dl; pj = poj dl -lcs :: (a -> a -> Bool) -> [a] -> [a] -> [DI]+lcs :: (a -> b -> Bool) -> [a] -> [b] -> [DI] lcs eq as bs = path . head . dropWhile (\dl -> poi dl /= lena || poj dl /= lenb) . concat . iterate (dstep cd) . (:[]) . addsnake cd $ DL {poi=0,poj=0,path=[]}@@ -77,24 +81,24 @@ -- | Takes two lists and returns a list of differences between them. This is -- 'getDiffBy' with '==' used as predicate.-getDiff :: (Eq t) => [t] -> [t] -> [Diff t]+getDiff :: (Eq a) => [a] -> [a] -> [Diff a] getDiff = getDiffBy (==) -- | Takes two lists and returns a list of differences between them, grouped -- into chunks. This is 'getGroupedDiffBy' with '==' used as predicate.-getGroupedDiff :: (Eq t) => [t] -> [t] -> [Diff [t]]+getGroupedDiff :: (Eq a) => [a] -> [a] -> [Diff [a]] getGroupedDiff = getGroupedDiffBy (==) -- | A form of 'getDiff' with no 'Eq' constraint. Instead, an equality predicate -- is taken as the first argument.-getDiffBy :: (t -> t -> Bool) -> [t] -> [t] -> [Diff t]+getDiffBy :: (a -> b -> Bool) -> [a] -> [b] -> [PolyDiff a b] getDiffBy eq a b = markup a b . reverse $ lcs eq a b where markup (x:xs) ys (F:ds) = First x : markup xs ys ds markup xs (y:ys) (S:ds) = Second y : markup xs ys ds markup (x:xs) (y:ys) (B:ds) = Both x y : markup xs ys ds markup _ _ _ = [] -getGroupedDiffBy :: (t -> t -> Bool) -> [t] -> [t] -> [Diff [t]]+getGroupedDiffBy :: (a -> b -> Bool) -> [a] -> [b] -> [PolyDiff [a] [b]] getGroupedDiffBy eq a b = go $ getDiffBy eq a b where go (First x : xs) = let (fs, rest) = goFirsts xs in First (x:fs) : go rest go (Second x : xs) = let (fs, rest) = goSeconds xs in Second (x:fs) : go rest
src/Data/Algorithm/DiffContext.hs view
@@ -15,7 +15,7 @@ , prettyContextDiff ) where -import Data.Algorithm.Diff (Diff(..), getGroupedDiff)+import Data.Algorithm.Diff (PolyDiff(..), Diff, getGroupedDiff) import Data.List (groupBy) import Data.Monoid (mappend) import Text.PrettyPrint (Doc, text, empty, hcat)
test/Test.hs view
@@ -134,7 +134,7 @@ prop_ppDiffR (DiffInput le ri) = let haskDiff=ppDiff $ getGroupedDiff le ri utilDiff= unsafePerformIO (runDiff (unlines le) (unlines ri))- in cover (haskDiff == utilDiff) 90 "exact match" $+ in cover 90 (haskDiff == utilDiff) "exact match" $ classify (haskDiff == utilDiff) "exact match" (div ((length haskDiff)*100) (length utilDiff) < 110) -- less than 10% bigger where