|
Class: Diff
Object
|
+--Diff
- Package:
- stx:libtool
- Category:
- Collections-Sequenceable-Diff
- Version:
- rev:
1.10
date: 2021/04/21 17:31:51
- user: cg
- file: Diff.st directory: libtool
- module: stx stc-classLibrary: libtool
I'm standard diff implementation written purely in Smalltalk. I can
compute differences between two sequenceable collections, not necessarily
holding strings. Elements are compared using #=.
Result of comparison is an edit script, a linked list of Diff::Changes,
each keeping one difference: whether change is insert and/or delete,
and positions in A and B.
I'm a port of Java diff.
[instance variables:]
[class variables:]
copyrightCopyright (c) 2007-2010 Jan Vrany, SWING Research Group, Czech Technical University in Prague
Copyright (c) 2009-2010 eXept Software AG
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the 'Software'), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
documentation_czechprvní fáze:
#############################################################################################################################
first := #('prvni' 'druhy' 'treti' 'treti' 'paty' 'zeleny' 'ruzovy' ).
second := #('prvni' 'treti' 'zeleny' 'ruzovy' 'treti' 'bbb' 'ccc' 'aaa' 'aaa' 'hhh' 'iii' 'mmm' 'nnn' 'ppp' 'aaa' 'aaa' ).
############################################################################################################################
First a second pøedstavujou dvì pole, které chceme porovnávat. Jednotlivé poloky v poli si lze pøedstavit jako øádky, pøípadnì jako slova v øádku.
Podle toho, co je potøeba porovnávat.
*****************************************************************************************************************************
diff := Diff new diff.
*****************************************************************************************************************************
Zde probíhá inicializace defaultníh promìnných. Funguje to jako konstruktor.
############################################################################################################################
diff diff: first b: second
############################################################################################################################
První fáze nutná pro porovnávání polí. Vzniknou dvì instance tøíde filedata uloené do pole. Tyto instance budou obsahovat následující údaje:
filevec[1].equivs=#(1 2 3 3 4 5 6)
filevec[1].bufferedLines=7
filevec[1].changedFlag=#()
filevec[2].equivs=#(1 3 6 7 3 8 9 10 10 11 12 13 14 15 10 10)
filevec[2].bufferedLines=16
filevec[2].changedFlag=#()
V zásadì se vytvoøila structura Dictionary, která jednotlivé øádky(slova) pøevedla na èísla. Pole equvs pak pøedstavuje èíselnì slova(øádky).
èísla, která se nalézají v obou dbou polí equivs znaèí, e soubory sdílí alespoò nìjaké slovo(øádek).
*****************************************************************************************************************************
change:= diff diff2: true.
*****************************************************************************************************************************
Zde ji dochází k porovnání obou dvou polí s øádky(slovy). Lze si vybrat mezi forwardscriptem a reversescriptem.
1) metoda discardconfusinglines
výsledek:
filevec[1].undiscardeded=#(1 3 3 5 6 0 0)
filevec[1].realIndexes= #(0 2 3 5 6 0 0)
filevec[1].nondiscardedLines=5
filevec[1].changedFlag=#(false false true false false true false false false)
filevec[2].undiscardeded=#(1 3 5 6 3 0 0 0 0 0 0 0 0 0 0 0)
filevec[2].realIndexes= #(0 1 2 3 4 0 0 0 0 0 0 0 0 0 0 0)
filevec[2].nondiscardedLines=5
Undiscarded- Øádky soubory, které jsou shodné.
RealIndexes - indexy øádkù v poli(je potøeba pøièíst jedna)
- to znamená e index prvního 3->3 pozice v prvním vstupním poli
- index druhého 3->2 pozice v druhém vstupním poli a 3->5 pozice v druhém vstupním poli
NondiscardedLines- znaèí kolik èádkù(slov) je shodných v obou polích.
2)Následuje porovnávání jednotlivých polí a vytvoøení výsledku
3)Výsledek Reverse skript
inserted=12('treti' 'bbb' 'ccc' 'aaa' 'aaa' 'hhh' 'iii' 'mmm' 'nnn' 'ppp' 'aaa' 'aaa')
deleted=0
line0=7('ruzovy')
line1=4('ruzovy')
link=next
inserted- kolik znakù bylo vloeno
deleted - kolik znakù bylo smazáno
line0 - poøadí znaku za kterým bylo nìco vloeno(smazáno) v prvním poli(poslední znak který je shodný v obou polích)
line1 - poøadí znaku za kterým bylo nìco smazáno(vloeno) v prvním poli(poslední znak který je shodný v obou polích)
Take po znaku na pozici 4, je 12 vloených znakù oproti prvnímu
Zbytek pole vypadá takto:
first := #('prvni' 'druhy' 'treti' 'treti' 'paty' 'zeleny' 'ruzovy' ).
second := #('prvni' 'treti' 'zeleny' 'ruzovy').
link není null a tudí odkazuje na dalí informace o zmìnách.
inserted=0
deleted=2('treti' 'paty')
line0=3('treti')
line1=2('treti')
link=next
zbytek pole vypadá takto:
first := #('prvni' 'druhy' 'treti' 'zeleny' 'ruzovy' ).
second := #('prvni' 'treti' 'zeleny' 'ruzovy').
link není null a tudí odkazuje na dalí informace o zmìnách.
inserted=0
deleted=1('druhy')
line0=1('prvni')
line1=1('prvni')
link=nil
zbytek pole vypadá takto:
first := #('prvni' 'treti' 'zeleny' 'ruzovy' ).
second := #('prvni' 'treti' 'zeleny' 'ruzovy').
link je nil. Neexistuje ádná zmìna a tato pole jsou shodná.
4)Výsledek Forward skript
inserted=0
deleted=1('druhy')
line0=1('prvni')
line1=1('prvni')
link=next
zbytek pole vypadá takto:
first := #('prvni' 'treti' 'treti' 'paty' 'zeleny' 'ruzovy' ).
second := #('prvni' 'treti' 'zeleny' 'ruzovy' 'treti' 'bbb' 'ccc' 'aaa' 'aaa' 'hhh' 'iii' 'mmm' 'nnn' 'ppp' 'aaa' 'aaa' ).
link není nil jdeme na odkaz:
inserted=0
deleted=2('treti' 'paty')
line0=3('treti')
line1=2('treti')
link=next
zbytek pole vypadá takto:
first := #('prvni' 'treti' 'zeleny' 'ruzovy' ).
second := #('prvni' 'treti' 'zeleny' 'ruzovy' 'treti' 'bbb' 'ccc' 'aaa' 'aaa' 'hhh' 'iii' 'mmm' 'nnn' 'ppp' 'aaa' 'aaa' ).
link není nil jdeme na odkaz:
inserted=12('treti' 'bbb' 'ccc' 'aaa' 'aaa' 'hhh' 'iii' 'mmm' 'nnn' 'ppp' 'aaa' 'aaa')
deleted=0
line0=7('ruzovy')
line1=4('ruzovy')
link=nil
zbytek pole vypadá takto:
first := #('prvni' 'treti' 'zeleny' 'ruzovy' ).
second := #('prvni' 'treti' 'zeleny' 'ruzovy').
Konec
diffing
-
between: a and: b
-
-
between: a and: b reverse: reverse
-
instance creation
-
new
-
return an initialized instance
diffing
-
a: gA b: gB
-
Prepare to find differences between two arrays. Each element of
the arrays is translated to an
-
diff
-
-
diff: reverse
-
-
diffUsingScript: bld
-
Get the results of comparison as an edit script. The script
is described by a list of changes. The standard ScriptBuilder
implementations provide for forward and reverse edit scripts.
Alternate implementations could, for instance, list common elements
instead of differences.
@param bld an object to build the script from change flags
@return the head of a list of changes
Some lines are obviously insertions or deletions
because they don't match anything. Detect them now,
and avoid even thinking about them in the main comparison algorithm.
initialization
-
initialize
-
konstruktor
private
-
compareseq: gXoff xlim: gXlim yoff: gYoff ylim: gYlim
-
Compare in detail contiguous subsequences of the two files
which are known, as a whole, to match each other.
The results are recorded in the vectors filevec[N].changedflag, by
storing a 1 in the element for each line that is an insertion or deletion.
The subsequence of file 0 is [XOFF, XLIM) and likewise for file 1.
Note that XLIM, YLIM are exclusive bounds.
All line numbers are origin-0 and discarded lines are not counted.
-
diag: anXoff xlim: anXlim yoff: aYoff ylim: aYlim
-
Give the compiler a chance.
-
discardConfusingLines
-
Discard lines from one file that have no matches in the other file.
-
equivMax
-
-
equivMax: something
-
-
filevec
-
-
nodiscards
-
-
nodiscards: something
-
-
shiftBoundaries
-
Adjust inserts/deletes of blank lines to join changes
as much as possible.
Change
Data
ForwardScript
ReverseScript
|first second diff|
first := #('prvni' 'druhy' 'treti' 'treti' 'paty' 'zeleny' 'ruzovy' ).
second := #('prvni' 'treti' 'zeleny' 'ruzovy' 'treti' 'bbb' 'ccc' 'aaa' 'aaa' 'hhh' 'iii' 'mmm' 'nnn' 'ppp' 'aaa' 'aaa' ).
diff := Diff between:first and:second
|