1 | namespace my.utils { |
2 | using System; |
3 | using System.Collections; |
4 | using System.Text; |
5 | using System.Text.RegularExpressions; |
6 | |
7 | /// <summary> |
8 | /// This Class implements the Difference Algorithm published in |
9 | /// "An O(ND) Difference Algorithm and its Variations" by Eugene Myers |
10 | /// Algorithmica Vol. 1 No. 2, 1986, p 251. |
11 | /// |
12 | /// There are many C, Java, Lisp implementations public available but they all seem to come |
13 | /// from the same source (diffutils) that is under the (unfree) GNU public License |
14 | /// and cannot be reused as a sourcecode for a commercial application. |
15 | /// There are very old C implementations that use other (worse) algorithms. |
16 | /// Microsoft also published sourcecode of a diff-tool (windiff) that uses some tree data. |
17 | /// Also, a direct transfer from a C source to C# is not easy because there is a lot of pointer |
18 | /// arithmetic in the typical C solutions and i need a managed solution. |
19 | /// These are the reasons why I implemented the original published algorithm from the scratch and |
20 | /// make it avaliable without the GNU license limitations. |
21 | /// I do not need a high performance diff tool because it is used only sometimes. |
22 | /// I will do some performace tweaking when needed. |
23 | /// |
24 | /// The algorithm itself is comparing 2 arrays of numbers so when comparing 2 text documents |
25 | /// each line is converted into a (hash) number. See DiffText(). |
26 | /// |
27 | /// Some chages to the original algorithm: |
28 | /// The original algorithm was described using a recursive approach and comparing zero indexed arrays. |
29 | /// Extracting sub-arrays and rejoining them is very performance and memory intensive so the same |
30 | /// (readonly) data arrays are passed arround together with their lower and upper bounds. |
31 | /// This circumstance makes the LCS and SMS functions more complicate. |
32 | /// I added some code to the LCS function to get a fast response on sub-arrays that are identical, |
33 | /// completely deleted or inserted. |
34 | /// |
35 | /// The result from a comparisation is stored in 2 arrays that flag for modified (deleted or inserted) |
36 | /// lines in the 2 data arrays. These bits are then analysed to produce a array of Item objects. |
37 | /// |
38 | /// Further possible optimizations: |
39 | /// (first rule: don't do it; second: don't do it yet) |
40 | /// The arrays DataA and DataB are passed as parameters, but are never changed after the creation |
41 | /// so they can be members of the class to avoid the paramter overhead. |
42 | /// In SMS is a lot of boundary arithmetic in the for-D and for-k loops that can be done by increment |
43 | /// and decrement of local variables. |
44 | /// The DownVector and UpVector arrays are alywas created and destroyed each time the SMS gets called. |
45 | /// It is possible to reuse tehm when transfering them to members of the class. |
46 | /// See TODO: hints. |
47 | /// |
48 | /// diff.cs: A port of the algorythm to C# |
49 | /// Created by Matthias Hertel, see http://www.mathertel.de |
50 | /// This work is licensed under a Creative Commons Attribution 2.0 Germany License. |
51 | /// see http://creativecommons.org/licenses/by/2.0/de/ |
52 | /// |
53 | /// Changes: |
54 | /// 2002.09.20 There was a "hang" in some situations. |
55 | /// Now I undestand a little bit more of the SMS algorithm. |
56 | /// There have been overlapping boxes; that where analyzed partial differently. |
57 | /// One return-point is enough. |
58 | /// A assertion was added in CreateDiffs when in debug-mode, that counts the number of equal (no modified) lines in both arrays. |
59 | /// They must be identical. |
60 | /// |
/// Changes: | |
61 | /// 2003.02.07 Out of bounds error in the Up/Down vector arrays in some situations. |
62 | /// The two vetors are now accessed using different offsets that are adjusted using the start k-Line. |
63 | /// A test case is added. |
64 | /// |
65 | /// 2006.03.05 Some documentation and a direct Diff entry point. |
66 | /// </summary> |
67 | |
68 | public class Diff { |
69 | |
70 | /// <summary>details of one difference.</summary> |
71 | public struct Item { |
72 | /// <summary>Start Line number in Data A.</summary> |
73 | public int StartA; |
74 | /// <summary>Start Line number in Data B.</summary> |
75 | public int StartB; |
76 | |
77 | /// <summary>Number of changes in Data A.</summary> |
78 | public int deletedA; |
79 | /// <summary>Number of changes in Data A.</summary> |
80 | public int insertedB; |
81 | } // Item |
82 | |
83 | /// <summary> |
84 | /// Shortest Middle Snake Return Data |
85 | /// </summary> |
86 | private struct SMSRD { |
87 | internal int x, y; |
88 | // internal int u, v; // 2002.09.20: no need for 2 points |
89 | } |
90 | |
91 | /// <summary>The A-Version of the data (original data) to be compared.</summary> |
92 | private DiffData DataA; |
93 | |
94 | /// <summary>The B-Version of the data (modified data) to be compared.</summary> |
95 | private DiffData DataB; |
96 | |
97 | #region self-Test |
98 | |
99 | #if (SELFTEST) |
100 | /// <summary> |
101 | /// start a self- / box-test for some diff cases and report to the debug output. |
102 | /// </summary> |
103 | /// <param name="args">not used</param> |
104 | /// <returns>always 0</returns> |
105 | public static int Main(string[] args) { |
106 | Diff d = new Diff(); |
107 | StringBuilder ret = new StringBuilder(); |
108 | string a, b; |
109 | |
110 | Debug.setDebug(true); |
111 | Debug.setDebugLevel(0); |
112 | |
113 | // test all changes |
114 | a = "a,b,c,d,e,f,g,h,i,j,k,l".Replace(',', '\n'); |
115 | b = "0,1,2,3,4,5,6,7,8,9".Replace(',', '\n'); |
116 | Debug.Assert(TestHelper(d.DiffText(a, b, false, false, false)) |
117 | == "12.10.0.0*", |
118 | "Diff-Selftest", "all-changes test failed."); |
119 | Debug.Write(Debug.LEVEL_INFO, "Selftest", "all-changes test passed."); |
120 | |
121 | // test all same |
122 | a = "a,b,c,d,e,f,g,h,i,j,k,l".Replace(',', '\n'); |
123 | b = a; |
124 | Debug.Assert(TestHelper(d.DiffText(a, b, false, false, false)) |
125 | == "", |
126 | "Diff-Selftest", "all-same test failed."); |
127 | Debug.Write(Debug.LEVEL_INFO, "Selftest", "all-same test passed."); |
128 | |
129 | // test snake |
130 | a = "a,b,c,d,e,f".Replace(',', '\n'); |
131 | b = "b,c,d,e,f,x".Replace(',', '\n'); |
132 | Debug.Assert(TestHelper(d.DiffText(a, b, false, false, false)) |
133 | == "1.0.0.0*0.1.6.5*", |
134 | "Diff-Selftest", "snake test failed."); |
135 | Debug.Write(Debug.LEVEL_INFO, "Selftest", "snake test passed."); |
136 | |
137 | // 2002.09.20 - repro |
138 | a = "c1,a,c2,b,c,d,e,g,h,i,j,c3,k,l".Replace(',', '\n'); |
139 | b = "C1,a,C2,b,c,d,e,I1,e,g,h,i,j,C3,k,I2,l".Replace(',', '\n'); |
140 | Debug.Assert(TestHelper(d.DiffText(a, b, false, false, false)) |
141 | == "1.1.0.0*1.1.2.2*0.2.7.7*1.1.11.13*0.1.13.15*", |
142 | "Diff-Selftest", "repro20020920 test failed."); |
143 | Debug.Write(Debug.LEVEL_INFO, "Selftest", "repro20020920 test passed."); |
144 | |
145 | // 2003.02.07 - repro |
146 | a = "F".Replace(',', '\n'); |
147 | b = "0,F,1,2,3,4,5,6,7".Replace(',', '\n'); |
148 | Debug.Assert(TestHelper(d.DiffText(a, b, false, false, false)) |
149 | == "0.1.0.0*0.7.1.2*", |
150 | "Diff-Selftest", "repro20030207 test failed."); |
151 | Debug.Write(Debug.LEVEL_INFO, "Selftest", "repro20030207 test passed."); |
152 | |
153 | // Muegel - repro |
154 | a = "HELLO\nWORLD"; |
155 | b = "\n\nhello\n\n\n\nworld\n"; |
156 | Debug.Assert(TestHelper(d.DiffText(a, b, false, false, false)) |
157 | == "2.8.0.0*", |
158 | "Diff-Selftest", "repro20030409 test failed."); |
159 | Debug.Write(Debug.LEVEL_INFO, "Selftest", "repro20030409 test passed."); |
160 | |
161 | // test some differences |
162 | a = "a,b,-,c,d,e,f,f".Replace(',', '\n'); |
163 | b = "a,b,x,c,e,f".Replace(',', '\n'); |
164 | Debug.Assert(TestHelper(d.DiffText(a, b, false, false, false)) |
165 | == "1.1.2.2*1.0.4.4*1.0.6.5*", |
166 | "Diff-Selftest", "some-changes test failed."); |
167 | |
168 | Debug.Write(Debug.LEVEL_INFO, "Selftest", "some-changes test passed."); |
169 | |
170 | Debug.Write(Debug.LEVEL_INFO, "Selftest", "End."); |
171 | return (0); |
172 | } |
173 | |
174 | |
175 | public static string TestHelper(Item []f) { |
176 | StringBuilder ret = new StringBuilder(); |
177 | for (int n = 0; n < f.Length; n++) { |
178 | ret.Append(f[n].deletedA.ToString() + "." + f[n].insertedB.ToString() + "." + f[n].StartA.ToString() + "." + f[n].StartB.ToString() + "*"); |
179 | } |
180 | // Debug.Write(5, "TestHelper", ret.ToString()); |
181 | return (ret.ToString()); |
182 | } |
183 | #endif |
184 | #endregion |
185 | |
186 | /// <summary> |
187 | /// Find the difference in 2 texts, comparing by textlines. |
188 | /// </summary> |
189 | /// <param name="TextA">A-version of the text (usualy the old one)</param> |
190 | /// <param name="TextB">B-version of the text (usualy the new one)</param> |
191 | /// <returns>Returns a array of Items that describe the differences.</returns> |
192 | public Item [] DiffText(string TextA, string TextB) { |
193 | return(DiffText(TextA, TextB, false, false, false)); |
194 | } // DiffText |
195 | |
196 | |
197 | /// <summary> |
198 | /// Find the difference in 2 text documents, comparing by textlines. |
199 | /// The algorithm itself is comparing 2 arrays of numbers so when comparing 2 text documents |
200 | /// each line is converted into a (hash) number. This hash-value is computed by storing all |
201 | /// textlines into a common hashtable so i can find dublicates in there, and generating a |
202 | /// new number each time a new textline is inserted. |
203 | /// </summary> |
204 | /// <param name="TextA">A-version of the text (usualy the old one)</param> |
205 | /// <param name="TextB">B-version of the text (usualy the new one)</param> |
206 | /// <param name="trimSpace">When set to true, all leading and trailing whitespace characters are stripped out before the comparation is done.</param> |
207 | /// <param name="ignoreSpace">When set to true, all whitespace characters are converted to a single space character before the comparation is done.</param> |
208 | /// <param name="ignoreCase">When set to true, all characters are converted to their lowercase equivivalence before the comparation is done.</param> |
/// <returns></returns> | |
209 | /// <returns>Returns a array of Items that describe the differences.</returns> |
210 | public Item [] DiffText(string TextA, string TextB, bool trimSpace, bool ignoreSpace, bool ignoreCase) { |
211 | // prepare the input-text and convert to comparable numbers. |
212 | Hashtable h = new Hashtable(TextA.Length + TextB.Length); |
213 | DataA = new DiffData(DiffCodes(TextA, h, trimSpace, ignoreSpace, ignoreCase)); |
214 | DataB = new DiffData(DiffCodes(TextB, h, trimSpace, ignoreSpace, ignoreCase)); |
215 | h = null; // free up hashtable memory (maybe) |
216 | |
217 | LCS(DataA, 0, DataA.Length, DataB, 0, DataB.Length); |
218 | return CreateDiffs(); |
219 | } // DiffText |
220 | |
221 | |
222 | /// <summary> |
223 | /// Find the difference in 2 arrays of integers. |
224 | /// </summary> |
225 | /// <param name="ArrayA">A-version of the numbers (usualy the old one)</param> |
226 | /// <param name="ArrayB">B-version of the numbers (usualy the new one)</param> |
227 | /// <returns>Returns a array of Items that describe the differences.</returns> |
228 | public Item [] DiffInt(int[] ArrayA, int[] ArrayB) { |
229 | DataA = new DiffData(ArrayA); |
230 | DataB = new DiffData(ArrayB); |
231 | LCS(DataA, 0, DataA.Length, DataB, 0, DataB.Length); |
232 | return CreateDiffs(); |
233 | } // Diff |
234 | |
235 | |
236 | /// <summary> |
237 | /// This function converts all textlines of the text into unique numbers for every unique textline |
238 | /// so further work can work only with simple numbers. |
239 | /// </summary> |
240 | /// <param name="aText">the input text</param> |
241 | /// <param name="h">This extern initialized hashtable is used for storing all ever used textlines.</param> |
242 | /// <param name="trimSpace">ignore leading and trailing space characters</param> |
243 | /// <returns>a array of integers.</returns> |
244 | private int[] DiffCodes(string aText, Hashtable h, bool trimSpace, bool ignoreSpace, bool ignoreCase) { |
245 | // get all codes of the text |
246 | string []Lines; |
247 | int []Codes; |
248 | int lastUsedCode = h.Count; |
249 | object aCode; |
250 | string s; |
251 | |
252 | // strip off all cr, only use lf as textline separator. |
253 | aText = aText.Replace("\r", ""); |
254 | Lines = aText.Split('\n'); |
255 | |
256 | Codes = new int[Lines.Length]; |
257 | |
258 | for (int i = 0; i < Lines.Length; ++i) { |
259 | s = Lines[i]; |
260 | if (trimSpace) |
261 | s = s.Trim(); |
262 | |
263 | if (ignoreSpace) { |
264 | s = Regex.Replace(s, "\\s+", " "); // TODO: optimization: faster blank removal. |
265 | } |
266 | |
267 | if (ignoreCase) |
268 | s = s.ToLower(); |
269 | |
270 | aCode = h[s]; |
271 | if (aCode == null) { |
272 | lastUsedCode++; |
273 | h[s] = lastUsedCode; |
274 | Codes[i] = lastUsedCode; |
275 | } else { |
276 | Codes[i] = (int)aCode; |
277 | } // if |
278 | } // for |
279 | return(Codes); |
280 | } // DiffCodes |
281 | |
282 | |
283 | /// <summary> |
284 | /// This is the algorithm to find the Shortest Middle Snake (SMS). |
285 | /// </summary> |
286 | /// <param name="DataA">sequence A</param> |
287 | /// <param name="LowerA">lower bound of the actual range in DataA</param> |
288 | /// <param name="UpperA">upper bound of the actual range in DataA (exclusive)</param> |
289 | /// <param name="DataB">sequence B</param> |
290 | /// <param name="LowerB">lower bound of the actual range in DataB</param> |
291 | /// <param name="UpperB">upper bound of the actual range in DataB (exclusive)</param> |
292 | /// <returns>a MiddleSnakeData record containing x,y and u,v</returns> |
293 | private SMSRD SMS(DiffData DataA, int LowerA, int UpperA, DiffData DataB, int LowerB, int UpperB) { |
294 | SMSRD ret; |
295 | int MAX = DataA.Length + DataB.Length + 1; |
296 | |
297 | int DownK = LowerA - LowerB; // the k-line to start the forward search |
298 | int UpK = UpperA - UpperB; // the k-line to start the reverse search |
299 | |
300 | int Delta = (UpperA - LowerA) - (UpperB - LowerB); |
301 | bool oddDelta = (Delta & 1) != 0; |
302 | |
303 | /// vector for the (0,0) to (x,y) search |
304 | int[] DownVector = new int[2* MAX + 2]; |
305 | |
306 | /// vector for the (u,v) to (N,M) search |
307 | int[] UpVector = new int[2 * MAX + 2]; |
308 | |
309 | // The vectors in the publication accepts negative indexes. the vectors implemented here are 0-based |
310 | // and are access using a specific offset: UpOffset UpVector and DownOffset for DownVektor |
311 | int DownOffset = MAX - DownK; |
312 | int UpOffset = MAX - UpK; |
313 | |
314 | int MaxD = ((UpperA - LowerA + UpperB - LowerB) / 2) + 1; |
315 | |
316 | // Debug.Write(2, "SMS", String.Format("Search the box: A[{0}-{1}] to B[{2}-{3}]", LowerA, UpperA, LowerB, UpperB)); |
317 | |
318 | // init vectors |
319 | DownVector[DownOffset + DownK + 1] = LowerA; |
320 | UpVector[UpOffset + UpK - 1] = UpperA; |
321 | |
322 | for (int D = 0; D <= MaxD; D++) { |
323 | |
324 | // Extend the forward path. |
325 | for (int k = DownK - D; k <= DownK + D; k += 2) { |
326 | // Debug.Write(0, "SMS", "extend forward path " + k.ToString()); |
327 | |
328 | // find the only or better starting point |
329 | int x, y; |
330 | if (k == DownK - D) { |
331 | x = DownVector[DownOffset + k+1]; // down |
332 | } else { |
333 | x = DownVector[DownOffset + k-1] + 1; // a step to the right |
334 | if ((k < DownK + D) && (DownVector[DownOffset + k+1] >= x)) |
335 | x = DownVector[DownOffset + k+1]; // down |
336 | } |
337 | y = x - k; |
338 | |
339 | // find the end of the furthest reaching forward D-path in diagonal k. |
340 | while ((x < UpperA) && (y < UpperB) && (DataA.data[x] == DataB.data[y])) { |
341 | x++; y++; |
342 | } |
343 | DownVector[DownOffset + k] = x; |
344 | |
345 | // overlap ? |
346 | if (oddDelta && (UpK-D < k) && (k < UpK+D)) { |
347 | if (UpVector[UpOffset + k] <= DownVector[DownOffset + k]) { |
348 | ret.x = DownVector[DownOffset + k]; |
349 | ret.y = DownVector[DownOffset + k] - k; |
350 | // ret.u = UpVector[UpOffset + k]; // 2002.09.20: no need for 2 points |
351 | // ret.v = UpVector[UpOffset + k] - k; |
352 | return (ret); |
353 | } // if |
354 | } // if |
355 | |
356 | } // for k |
357 | |
358 | // Extend the reverse path. |
359 | for (int k = UpK - D; k <= UpK + D; k += 2) { |
360 | // Debug.Write(0, "SMS", "extend reverse path " + k.ToString()); |
361 | |
362 | // find the only or better starting point |
363 | int x, y; |
364 | if (k == UpK + D) { |
365 | x = UpVector[UpOffset + k-1]; // up |
366 | } else { |
367 | x = UpVector[UpOffset + k+1] - 1; // left |
368 | if ((k > UpK - D) && (UpVector[UpOffset + k-1] < x)) |
369 | x = UpVector[UpOffset + k-1]; // up |
370 | } // if |
371 | y = x - k; |
372 | |
373 | while ((x > LowerA) && (y > LowerB) && (DataA.data[x-1] == DataB.data[y-1])) { |
374 | x--; y--; // diagonal |
375 | } |
376 | UpVector[UpOffset + k] = x; |
377 | |
378 | // overlap ? |
379 | if (! oddDelta && (DownK-D <= k) && (k <= DownK+D)) { |
380 | if (UpVector[UpOffset + k] <= DownVector[DownOffset + k]) { |
381 | ret.x = DownVector[DownOffset + k]; |
382 | ret.y = DownVector[DownOffset + k] - k; |
383 | // ret.u = UpVector[UpOffset + k]; // 2002.09.20: no need for 2 points |
384 | // ret.v = UpVector[UpOffset + k] - k; |
385 | return (ret); |
386 | } // if |
387 | } // if |
388 | |
389 | } // for k |
390 | |
391 | } // for D |
392 | |
393 | throw new ApplicationException("the algorithm should never come here."); |
394 | } // SMS |
395 | |
396 | |
397 | /// <summary> |
398 | /// This is the divide-and-conquer implementation of the longes common-subsequence (LCS) |
399 | /// algorithm. |
400 | /// The published algorithm passes recursively parts of the A and B sequences. |
401 | /// To avoid copying these arrays the lower and upper bounds are passed while the sequences stay constant. |
402 | /// </summary> |
403 | /// <param name="DataA">sequence A</param> |
404 | /// <param name="LowerA">lower bound of the actual range in DataA</param> |
405 | /// <param name="UpperA">upper bound of the actual range in DataA (exclusive)</param> |
406 | /// <param name="DataB">sequence B</param> |
407 | /// <param name="LowerB">lower bound of the actual range in DataB</param> |
408 | /// <param name="UpperB">upper bound of the actual range in DataB (exclusive)</param> |
409 | private void LCS(DiffData DataA, int LowerA, int UpperA, DiffData DataB, int LowerB, int UpperB) { |
410 | // Debug.Write(2, "LCS", String.Format("Analyse the box: A[{0}-{1}] to B[{2}-{3}]", LowerA, UpperA, LowerB, UpperB)); |
411 | |
412 | // Fast walkthrough equal lines at the start |
413 | while (LowerA < UpperA && LowerB < UpperB && DataA.data[LowerA] == DataB.data[LowerB]) { |
414 | LowerA++; LowerB++; |
415 | } |
416 | |
417 | // Fast walkthrough equal lines at the end |
418 | while (LowerA < UpperA && LowerB < UpperB && DataA.data[UpperA-1] == DataB.data[UpperB-1]) { |
419 | --UpperA; --UpperB; |
420 | } |
421 | |
422 | if (LowerA == UpperA) { |
423 | // mark as inserted lines. |
424 | while (LowerB < UpperB) |
425 | DataB.modified[LowerB++] = true; |
426 | |
427 | } else if (LowerB == UpperB) { |
428 | // mark as deleted lines. |
429 | while (LowerA < UpperA) |
430 | DataA.modified[LowerA++] = true; |
431 | |
432 | } else { |
433 | // Find the middle snakea and length of an optimal path for A and B |
434 | SMSRD smsrd = SMS(DataA, LowerA, UpperA, DataB, LowerB, UpperB); |
435 | // Debug.Write(2, "MiddleSnakeData", String.Format("{0},{1}", smsrd.x, smsrd.y)); |
436 | |
437 | // The path is from LowerX to (x,y) and (x,y) ot UpperX |
438 | LCS(DataA, LowerA, smsrd.x, DataB, LowerB, smsrd.y); |
439 | LCS(DataA, smsrd.x, UpperA, DataB, smsrd.y, UpperB); // 2002.09.20: no need for 2 points |
440 | } |
441 | } // LCS() |
442 | |
443 | |
444 | /// <summary>Scan the tables of which lines are inserted and deleted, |
445 | /// producing an edit script in forward order. |
446 | /// </summary> |
447 | /// dynamic array |
448 | private Item [] CreateDiffs() { |
449 | ArrayList a = new ArrayList(); |
450 | Item aItem; |
451 | Item []result; |
452 | |
453 | int StartA, StartB; |
454 | int LineA, LineB; |
455 | |
456 | LineA = 0; |
457 | LineB = 0; |
458 | while (LineA < DataA.Length || LineB < DataB.Length) { |
459 | if ((LineA < DataA.Length) && (! DataA.modified[LineA]) |
460 | && (LineB < DataB.Length) && (! DataB.modified[LineB])) { |
461 | // equal lines |
462 | LineA++; |
463 | LineB++; |
464 | |
465 | } else { |
466 | // maybe deleted and/or inserted lines |
467 | StartA = LineA; |
468 | StartB = LineB; |
469 | |
470 | while (LineA < DataA.Length && (LineB >= DataB.Length || DataA.modified[LineA])) |
471 | // while (LineA < DataA.Length && DataA.modified[LineA]) |
472 | LineA++; |
473 | |
474 | while (LineB < DataB.Length && (LineA >= DataA.Length || DataB.modified[LineB])) |
475 | // while (LineB < DataB.Length && DataB.modified[LineB]) |
476 | LineB++; |
477 | |
478 | if ((StartA < LineA) || (StartB < LineB)) { |
479 | // store a new difference-item |
480 | aItem = new Item(); |
481 | aItem.StartA = StartA; |
482 | aItem.StartB = StartB; |
483 | aItem.deletedA = LineA - StartA; |
484 | aItem.insertedB = LineB - StartB; |
485 | a.Add(aItem); |
486 | } // if |
487 | } // if |
488 | } // while |
489 | |
490 | result = new Item[a.Count]; |
491 | a.CopyTo(result); |
492 | |
493 | return (result); |
494 | } |
495 | |
496 | } // class Diff |
497 | |
498 | /// <summary>Data on one input file being compared. |
499 | /// </summary> |
500 | internal class DiffData { |
501 | |
502 | /// <summary>Number of elements (lines).</summary> |
503 | internal int Length; |
504 | |
505 | /// <summary>Buffer of numbers that will be compared.</summary> |
506 | internal int[] data; |
507 | |
508 | /// <summary> |
509 | /// Array of booleans that flag for modified data. |
510 | /// This is the result of the diff. |
511 | /// This means deletedA in the first Data or inserted in the second Data. |
512 | /// </summary> |
513 | internal bool[] modified; |
514 | |
515 | /// <summary> |
516 | /// Initialize the Diff-Data buffer. |
517 | /// </summary> |
518 | /// <param name="data">reference to the buffer</param> |
519 | internal DiffData(int[] initData) { |
520 | data = initData; |
521 | Length = initData.Length; |
522 | modified = new bool[Length + 2]; |
523 | } // DiffData |
524 | |
525 | } // class DiffData |
526 | |
527 | } // namespace |
This page is part of the http://www.mathertel.de/ web site.