LibreOffice Module xmerge (master) 1
Public Member Functions | Private Member Functions | List of all members
org.openoffice.xmerge.merger.diff.CharArrayLCSAlgorithm Class Reference

This is an implementations of DiffAlgorithm interface which will difference char arrays. More...

Public Member Functions

Difference[] computeDiffs (char[] orgSeq, char[] modSeq)
 Return an Difference array. More...
 

Private Member Functions

int[][] createDiffTable (char[] orgSeq, char[] modSeq)
 Create the difference table. More...
 
void generateResult (int[][] diffTable, int i, int j, ArrayList< Difference > diffVector)
 Generate the Difference result vector. More...
 

Detailed Description

This is an implementations of DiffAlgorithm interface which will difference char arrays.

It also use Longest Common Subsequence (LCS). The algorithm is based on the book "Introduction to Algorithms" by Thomas H.Cormen, Charles E.Leiserson, and Ronald L.Riverst (MIT Press 1990) page 314.

Definition at line 32 of file CharArrayLCSAlgorithm.java.

Member Function Documentation

◆ computeDiffs()

Difference[] org.openoffice.xmerge.merger.diff.CharArrayLCSAlgorithm.computeDiffs ( char[]  orgSeq,
char[]  modSeq 
)
inline

Return an Difference array.

This method finds out the difference between two sequences.

Parameters
orgSeqThe original sequence.
modSeqThe modified (or changed) sequence to compare against the original.
Returns
A Difference array.

Definition at line 45 of file CharArrayLCSAlgorithm.java.

References org.openoffice.xmerge.merger.diff.CharArrayLCSAlgorithm.createDiffTable(), and org.openoffice.xmerge.merger.diff.CharArrayLCSAlgorithm.generateResult().

Referenced by org.openoffice.xmerge.merger.merge.CharacterBaseParagraphMerge.merge().

◆ createDiffTable()

int[][] org.openoffice.xmerge.merger.diff.CharArrayLCSAlgorithm.createDiffTable ( char[]  orgSeq,
char[]  modSeq 
)
inlineprivate

Create the difference table.

The difference table is used internal to keep track what elements are common or different in the two sequences.

Parameters
orgSeqThe original sequence to be used as a base.
modSeqThe modified sequence to compare.
Returns
A difference table as a two-dimensional array of integers.

Definition at line 77 of file CharArrayLCSAlgorithm.java.

References i.

Referenced by org.openoffice.xmerge.merger.diff.CharArrayLCSAlgorithm.computeDiffs().

◆ generateResult()

void org.openoffice.xmerge.merger.diff.CharArrayLCSAlgorithm.generateResult ( int  diffTable[][],
int  i,
int  j,
ArrayList< Difference diffVector 
)
inlineprivate

Generate the Difference result vector.

This method will be called recursively to backtrack the difference table to get the difference result (and also the LCS).

Parameters
diffTableThe difference table containing the Difference result.
iThe nth element in original sequence to compare. This method is called recursively with i and j decreased until 0.
jThe nth element in modified sequence to compare.
diffVectorA vector to output the Difference result. Can not use a return variable as it is a recursive method. The vector will contain Difference objects with operation and positions filled in.

Definition at line 126 of file CharArrayLCSAlgorithm.java.

References org.openoffice.xmerge.merger.Difference.ADD, org.openoffice.xmerge.merger.Difference.CHANGE, org.openoffice.xmerge.merger.Difference.DELETE, org.openoffice.xmerge.merger.diff.CharArrayLCSAlgorithm.generateResult(), and i.

Referenced by org.openoffice.xmerge.merger.diff.CharArrayLCSAlgorithm.computeDiffs(), and org.openoffice.xmerge.merger.diff.CharArrayLCSAlgorithm.generateResult().


The documentation for this class was generated from the following file: