public final class DiffXKumarRangan extends DiffXAlgorithmBase
Implementation note: this algorithm effectively detects the correct changes in the sequences, but suffers from two main problems:
SmartXMLFormatter
helps in solving the
problem as it maintains a stack of the elements that are being written and actually
ignores the name of the closing element, so all the elements are closed properly.
For S. Kiran Kumar and C. Pandu Rangan. A linear space algorithm for the LCS problem, Acta Informatica. Volume 24 , Issue 3 (June 1987); Copyright Springer-Verlag 1987
This class reuses portions of code originally written by Mikko Koivisto and Tuomo Saarni.
length1, length2, sequence1, sequence2
Constructor and Description |
---|
DiffXKumarRangan(EventSequence seq0,
EventSequence seq1)
Creates a new DiffXAlgorithmBase.
|
Modifier and Type | Method and Description |
---|---|
int |
length()
Calculates the length of LCS and returns it.
|
void |
process(DiffXFormatter formatter)
Writes the diff sequence using the specified formatter.
|
getFirstSequence, getSecondSequence
public DiffXKumarRangan(EventSequence seq0, EventSequence seq1)
seq0
- The first sequence to compare.seq1
- The second sequence to compare.public int length()
If the length is calculated already it'll not be calculated repeatedly.
This algorithm starts from the length of the first sequence as the maximum possible LCS and reduces the length for every difference with the second sequence.
The time complexity is O(n(m-p)) and the space complexity is O(n+m).
public void process(DiffXFormatter formatter) throws IOException
formatter
- The formatter that will handle the output.IOException
- If thrown by the formatter.Copyright © 2007-2019. All Rights Reserved.