30 if (c1 == 0 && c2 == 0)
35 while (StartOffset < c1 && StartOffset < c2 &&
36 S1[StartOffset].Equals(S2[StartOffset]))
44 while (EndOffset1 > StartOffset && EndOffset2 > StartOffset &&
45 S1[EndOffset1 - 1].Equals(S2[EndOffset2 - 1]))
51 int c1p = EndOffset1 - StartOffset + 1;
52 int c2p = EndOffset2 - StartOffset + 1;
53 long NrBits = ((long)c1p) * c2p;
54 long NrBytes = (NrBits + 7) >> 3;
56 if (NrBytes >
int.MaxValue)
57 throw new OutOfMemoryException(
"Unable to allocate enough memory to process the difference between the two sequences.");
59 byte[] Processed =
new byte[NrBytes];
71 for (i = 0; i <= StartOffset; i++)
84 if (P.i1 == EndOffset1 && P.i2 == EndOffset2)
87 i = P.i1 - StartOffset + (P.i2 - StartOffset) * c1p;
89 iBit = (byte)(1 << (i & 7));
91 if ((Processed[iByte] & iBit) == 0)
93 Processed[iByte] |= iBit;
95 if (b2 = P.i2 < EndOffset2)
98 if ((Processed[j >> 3] & (
byte)(1 << (j & 7))) == 0)
115 if (b1 = P.i1 < EndOffset1)
118 if ((Processed[j >> 3] & (
byte)(1 << (j & 7))) == 0)
135 if (b1 && b2 && S1[P.i1].Equals(S2[P.i2]))
138 if ((Processed[j >> 3] & (
byte)(1 << (j & 7))) == 0)
150 if (Q.i1 == EndOffset1 && Q.i2 == EndOffset2)
177 while (EndOffset1 < c1 && EndOffset2 < c2)
191 while (!(Loop.Prev is
null))
197 State<T>[] Steps =
new State<T>[NrSteps];
198 for (i = NrSteps, Loop = P; i > 0; Loop = Loop.Prev)
208 for (i = 0; i < NrSteps; i++)
220 Elements.
Add(S2[P.i2 - 1]);
222 Elements.
Add(S1[P.i1 - 1]);
230 private class State<T>
235 public State<T> Prev;
237 public override string ToString()
239 return this.Op.ToString() +
" " + this.i1.ToString() +
"," + this.i2.ToString();
251 return Analyze(s1.ToCharArray(), s2.ToCharArray());
272 return Text.Replace(
"\r\n",
"\n").Replace(
'\r',
'\n').Split(
'\n');
A chunked list is a linked list of chunks of objects of type T .
void Clear()
Clears the collection.
bool HasFirstItem
If there is a first item in the collection
void Insert(int Index, T Item)
Inserts an item to the list at the specified index.
T RemoveLast()
Removes the last item in the collection.
void Add(T Item)
Adds an item to the collection.
void AddLastItem(T Value)
Adds a new item last in the collection.
T[] ToArray()
Returns an array containing all elements of the collection.
Computes the difference between two sequences of symbols.
static EditScript< string > AnalyzeRows(string Text1, string Text2)
Analyzes two texts, estimating the difference between them, as a sequence of rows.
static string[] ExtractRows(string Text)
Extracts the rows from a text.
static EditScript< char > AnalyzeStrings(string s1, string s2)
Analyzes two text strings, estimating the difference between them.
static EditScript< T > Analyze< T >(T[] S1, T[] S2)
Analyzes two sequences of symbols to estimate the difference between them.
Represents an Edit-script, converting one sequence of symbols to another.
Represents a sub-sequence of symbols.
EditOperation
Type of edit-operation