Package org.eclipse.compare.internal
Class LCS
java.lang.Object
org.eclipse.compare.internal.LCS
- Direct Known Subclasses:
RangeComparatorLCS
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate intfind_middle_snake(int bottoml1, int topl1, int bottoml2, int topl2, int[][] V, int[] snake) Helper function for Myers' LCS algorithm to find the middle snake for l1[bottoml1..topl1] and l2[bottoml2..topl2] The x, y coodrdinates of the start of the middle snake are saved in snake[0], snake[1] respectively and the length of the snake is saved in s[2].private static int[]findMostProgress(int M, int N, int limit, int[][] V) Takes the array with furthest reaching D-paths from an LCS computation and returns the x,y coordinates and progress made in the middle diagonal among those with maximum progress, both from the front and from the back.intprotected abstract intprotected abstract intprotected abstract voidinitializeLcs(int lcsLength) protected abstract booleanisRangeEqual(int i1, int i2) private intlcs_rec(int bottoml1, int topl1, int bottoml2, int topl2, int[][] V, int[] snake) The recursive helper function for Myers' LCS.voidlongestCommonSubsequence(LCSSettings settings) Myers' algorithm for longest common subsequence.protected abstract voidsetLcs(int sl1, int sl2)
-
Field Details
-
max_differences
private int max_differences -
length
private int length
-
-
Constructor Details
-
LCS
public LCS()
-
-
Method Details
-
longestCommonSubsequence
Myers' algorithm for longest common subsequence. O((M + N)D) worst case time, O(M + N + D^2) expected time, O(M + N) space (http://citeseer.ist.psu.edu/myers86ond.html) Note: Beyond implementing the algorithm as described in the paper I have added diagonal range compression which helps when finding the LCS of a very long and a very short sequence, also bound the running time to (N + M)^1.5 when both sequences are very long. After this method is called, the longest common subsequence is available by calling getResult() where result[0] is composed of entries from l1 and result[1] is composed of entries from l2- Parameters:
subMonitor-
-
lcs_rec
private int lcs_rec(int bottoml1, int topl1, int bottoml2, int topl2, int[][] V, int[] snake) The recursive helper function for Myers' LCS. Computes the LCS of l1[bottoml1 .. topl1] and l2[bottoml2 .. topl2] fills in the appropriate location in lcs and returns the length- Parameters:
l1- The 1st sequencebottoml1- Index in the 1st sequence to start from (inclusive)topl1- Index in the 1st sequence to end on (inclusive)l2- The 2nd sequencebottoml2- Index in the 2nd sequence to start from (inclusive)topl2- Index in the 2nd sequence to end on (inclusive)V- should be allocated as int[2][l1.length + l2.length + 1], used to store furthest reaching D-pathssnake- should be allocated as int[3], used to store the beginning x, y coordinates and the length of the latest snake traversedsubMonitor-lcs- should be allocated as TextLine[2][l1.length], used to store the common points found to be part of the LCS where lcs[0] references lines of l1 and lcs[1] references lines of l2.- Returns:
- the length of the LCS
-
find_middle_snake
private int find_middle_snake(int bottoml1, int topl1, int bottoml2, int topl2, int[][] V, int[] snake) Helper function for Myers' LCS algorithm to find the middle snake for l1[bottoml1..topl1] and l2[bottoml2..topl2] The x, y coodrdinates of the start of the middle snake are saved in snake[0], snake[1] respectively and the length of the snake is saved in s[2].- Parameters:
l1- The 1st sequencebottoml1- Index in the 1st sequence to start from (inclusive)topl1- Index in the 1st sequence to end on (inclusive)l2- The 2nd sequencebottoml2- Index in the 2nd sequence to start from (inclusive)topl2- Index in the 2nd sequence to end on (inclusive)V- should be allocated as int[2][l1.length + l2.length + 1], used to store furthest reaching D-pathssnake- should be allocated as int[3], used to store the beginning x, y coordinates and the length of the middle snake- Returns:
- The number of differences (SES) between l1[bottoml1..topl1] and l2[bottoml2..topl2]
-
findMostProgress
private static int[] findMostProgress(int M, int N, int limit, int[][] V) Takes the array with furthest reaching D-paths from an LCS computation and returns the x,y coordinates and progress made in the middle diagonal among those with maximum progress, both from the front and from the back.- Parameters:
M- the length of the 1st sequence for which LCS is being computedN- the length of the 2nd sequence for which LCS is being computedlimit- the number of steps made in an attempt to find the LCS from the front and backV- the array storing the furthest reaching D-paths for the LCS computation- Returns:
- The result as an array of 3 integers where result[0] is the x coordinate of the current location in the diagonal with the most progress, result[1] is the y coordinate of the current location in the diagonal with the most progress and result[2] is the amount of progress made in that diagonal
-
getLength2
protected abstract int getLength2() -
getLength1
protected abstract int getLength1() -
isRangeEqual
protected abstract boolean isRangeEqual(int i1, int i2) -
setLcs
protected abstract void setLcs(int sl1, int sl2) -
initializeLcs
protected abstract void initializeLcs(int lcsLength) -
getLength
public int getLength()
-