JLibDiff
Class GnuDiffAlgorithm

java.lang.Object
  |
  +--JLibDiff.GnuDiffAlgorithm
All Implemented Interfaces:
DiffAlgorithm, DiffMaker

public class GnuDiffAlgorithm
extends java.lang.Object
implements DiffAlgorithm, DiffMaker

Title: $FileName: GnuDiffAlgorithm.java$

Version:
$VerNum: 1$
Author:
$AuthorName: Rob MacGrogan$

$Description: GNU diff algorithm.$
$KeyWordsOff: $

This class implements GNU diff and is adapted and copied (where possible) from Java implementation of this program created by Stuart D Gathman.

The code has been significantly modified by Robert MacGrogan to fit into SourceJammer and use the JLibDiff objects.

Please note that this module is released under the GNU Public License only. If the version of SourceJammer you are using contains this module it is released as GPL and can only be re-distributed as GPL.

Original file header and copyright information follows:

A class to compare vectors of objects. The result of comparison is a list of change objects which form an edit script. The objects compared are traditionally lines of text from two files. Comparison options such as "ignore whitespace" are implemented by modifying the equals and hashcode methods for the objects compared.

The basic algorithm is described in:
"An O(ND) Difference Algorithm and its Variations", Eugene Myers, Algorithmica Vol. 1 No. 2, 1986, p 251.

This class outputs different results from GNU diff 1.15 on some inputs. Our results are actually better (smaller change list, smaller total size of changes), but it would be nice to know why. Perhaps there is a memory overwrite bug in GNU diff 1.15., Stuart D. Gathman, translated from GNU diff 1.15 Copyright (C) 2000 Business Management Systems, Inc.

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.


Field Summary
private  int[] bdiag
           
private  int bdiagoff
           
private  int cost
           
private  int equivMax
           
private  int[] fdiag
           
private  int fdiagoff
           
private  FileData[] fileInfo
           
 boolean heuristic
           
private  boolean noDiscards
           
private  int[] xvec
           
private  int[] yvec
           
 
Constructor Summary
GnuDiffAlgorithm()
           
 
Method Summary
private  java.util.Vector buildChangeList(java.lang.String[] A, java.lang.String[] B)
           
private  void compareseq(int xoff, int xlim, int yoff, int ylim)
           
private  int diag(int xoff, int xlim, int yoff, int ylim)
           
private  void discardConfusingLines()
           
 int getEquivMax()
          Returns the equivMax.
private  java.lang.Object[] getLines(int firstLine, int numLines, java.lang.Object[] parent)
           
 void incrimentEquivMax()
           
 boolean isNoDiscards()
          Returns the noDiscards.
 java.util.Vector makeDiff(java.lang.String[] A, java.lang.String[] B)
           
 void setEol(java.lang.String s)
           
private  void shiftBoundaries()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

equivMax

private int equivMax

noDiscards

private boolean noDiscards

fileInfo

private FileData[] fileInfo

xvec

private int[] xvec

yvec

private int[] yvec

fdiag

private int[] fdiag

bdiag

private int[] bdiag

fdiagoff

private int fdiagoff

bdiagoff

private int bdiagoff

cost

private int cost

heuristic

public boolean heuristic
Constructor Detail

GnuDiffAlgorithm

public GnuDiffAlgorithm()
Method Detail

makeDiff

public java.util.Vector makeDiff(java.lang.String[] A,
                                 java.lang.String[] B)
Specified by:
makeDiff in interface DiffAlgorithm
See Also:
DiffAlgorithm.makeDiff(String[], String[])

setEol

public void setEol(java.lang.String s)
Specified by:
setEol in interface DiffAlgorithm

compareseq

private void compareseq(int xoff,
                        int xlim,
                        int yoff,
                        int ylim)

diag

private int diag(int xoff,
                 int xlim,
                 int yoff,
                 int ylim)

discardConfusingLines

private void discardConfusingLines()

shiftBoundaries

private void shiftBoundaries()

getLines

private java.lang.Object[] getLines(int firstLine,
                                    int numLines,
                                    java.lang.Object[] parent)

buildChangeList

private java.util.Vector buildChangeList(java.lang.String[] A,
                                         java.lang.String[] B)

getEquivMax

public int getEquivMax()
Returns the equivMax.

Specified by:
getEquivMax in interface DiffMaker
Returns:
int

incrimentEquivMax

public void incrimentEquivMax()
Specified by:
incrimentEquivMax in interface DiffMaker

isNoDiscards

public boolean isNoDiscards()
Returns the noDiscards.

Specified by:
isNoDiscards in interface DiffMaker
Returns:
boolean


Copyright © 2003 Soucejammer project.