fast-myers-diff-0.0.1: A fast implementation of the Myers diff algorithm.
Safe HaskellNone
LanguageHaskell2010

Myers.Diff

Description

Myers Diff

This is an implementation of the O(ND) diff algorithm as described in "An O(ND) Difference Algorithm and Its Variations (1986)" http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.4.6927.

Synopsis

Diffing

type Diff a = PolyDiff a a Source #

data PolyDiff a b Source #

A value is either from the First list, the Second or from Both. 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 custom equality relation to only perform equality on side of a tuple).

Constructors

First a 
Second b 
Both a b 

Instances

Instances details
Generic (PolyDiff a b) Source # 
Instance details

Defined in Myers.Diff

Associated Types

type Rep (PolyDiff a b) 
Instance details

Defined in Myers.Diff

Methods

from :: PolyDiff a b -> Rep (PolyDiff a b) x #

to :: Rep (PolyDiff a b) x -> PolyDiff a b #

(Show a, Show b) => Show (PolyDiff a b) Source # 
Instance details

Defined in Myers.Diff

Methods

showsPrec :: Int -> PolyDiff a b -> ShowS #

show :: PolyDiff a b -> String #

showList :: [PolyDiff a b] -> ShowS #

(NFData a, NFData b) => NFData (PolyDiff a b) Source # 
Instance details

Defined in Myers.Diff

Methods

rnf :: PolyDiff a b -> () #

(Eq a, Eq b) => Eq (PolyDiff a b) Source # 
Instance details

Defined in Myers.Diff

Methods

(==) :: PolyDiff a b -> PolyDiff a b -> Bool #

(/=) :: PolyDiff a b -> PolyDiff a b -> Bool #

type Rep (PolyDiff a b) Source # 
Instance details

Defined in Myers.Diff

getTextDiff :: Text -> Text -> Vector (Diff Text) Source #

Text diff

Uses pack and unpack, so does not roundtrip. It uses pack and unpack because Text is not the same as Vector Char; You can't index a text in O(1) time, it takes O(n) time.

getStringDiff :: String -> String -> [Diff Char] Source #

String diff

You probably want to use getTextDiff with packed strings instead, but this function doesn't have the roundtripping problem that getTextDiff has.

getGroupedStringDiff :: String -> String -> [Diff String] Source #

Grouped String diff

Like getStringDiff but with entire strings instead of individual characters.

getVectorDiff :: Eq a => Vector a -> Vector a -> Vector (Diff a) Source #

Diff two Vectors

Prefer getGroupedVectorDiff for performance reasons.

getGroupedVectorDiff :: Eq a => Vector a -> Vector a -> Vector (Diff (Vector a)) Source #

Diff two Vectors with grouped results

getVectorDiffBy :: (a -> b -> Bool) -> Vector a -> Vector b -> Vector (PolyDiff a b) Source #

Diff two Vectors with different types using a custom equality operator

Prefer getGroupedVectorDiffBy for performance reasons.

getGroupedVectorDiffBy :: (a -> b -> Bool) -> Vector a -> Vector b -> Vector (PolyDiff (Vector a) (Vector b)) Source #

Diff two Vectors with grouped results using a custom equality operator

Internals

data Edit Source #

Constructors

Delete Int Int

Delete from the old vector

Insert Int Int Int

Insert into the old vector

Instances

Instances details
Show Edit Source # 
Instance details

Defined in Myers.Diff

Methods

showsPrec :: Int -> Edit -> ShowS #

show :: Edit -> String #

showList :: [Edit] -> ShowS #

Eq Edit Source # 
Instance details

Defined in Myers.Diff

Methods

(==) :: Edit -> Edit -> Bool #

(/=) :: Edit -> Edit -> Bool #

Ord Edit Source # 
Instance details

Defined in Myers.Diff

Methods

compare :: Edit -> Edit -> Ordering #

(<) :: Edit -> Edit -> Bool #

(<=) :: Edit -> Edit -> Bool #

(>) :: Edit -> Edit -> Bool #

(>=) :: Edit -> Edit -> Bool #

max :: Edit -> Edit -> Edit #

min :: Edit -> Edit -> Edit #

getEditScript :: Eq a => Vector a -> Vector a -> Vector Edit Source #

Compute the edit script to turn a given Vector into the second given Vector

getEditScriptBy :: (a -> b -> Bool) -> Vector a -> Vector b -> Vector Edit Source #

Compute the edit script to turn a given Vector into the second given Vector with a custom equality relation

From https://blog.robertelder.org/diff-algorithm/

computeDiffFromEditScript :: Vector a -> Vector b -> Vector Edit -> Vector (PolyDiff a b) Source #

Compute a diff using an edit script.

Prefer computeGroupedDiffFromEditScript for performance reasons.

computeGroupedDiffFromEditScript :: Vector a -> Vector b -> Vector Edit -> Vector (PolyDiff (Vector a) (Vector b)) Source #

Compute a diff using an edit script.

Prefer computeGroupedDiffFromEditScript for performance reasons.

Backwards compatibility with Diff

getDiff :: Eq a => [a] -> [a] -> [Diff a] Source #

For backward compatibility with Diff, use more specific functions if you can.

getDiffBy :: (a -> b -> Bool) -> [a] -> [b] -> [PolyDiff a b] Source #

For backward compatibility with Diff, use more specific functions if you can.

getGroupedDiff :: Eq a => [a] -> [a] -> [Diff [a]] Source #

For backward compatibility with Diff, use more specific functions if you can.

getGroupedDiffBy :: (a -> b -> Bool) -> [a] -> [b] -> [PolyDiff [a] [b]] Source #

For backward compatibility with Diff, use more specific functions if you can.