// Constructor
 internal OperationDescrPrefixChange( DiffgramGenerator.PrefixChange prefixChange )
     : base(prefixChange._opid)
 {
     _prefixChange = prefixChange;
 }
Esempio n. 2
0
    Diffgram ZhangShashaAlgorithm()
    {
        // Preprocess the trees for the tree-to-tree comparison algorithm and diffgram generation.
        // This includes post-order numbering of all nodes (the source and target nodes are stored
        // in post-order in the _sourceNodes and _targetNodes arrays).
#if DEBUG
        Trace.WriteLineIf( T_Phases.Enabled, "* Using Zhang-Shasha Algorithm" );
        Trace.WriteLineIf( T_Phases.Enabled, "* Preprocessing trees..." );
#endif
#if MEASURE_PERF 
        int startTickCount = Environment.TickCount;
#endif
        PreprocessTree( _sourceDoc, ref _sourceNodes );
        PreprocessTree( _targetDoc, ref _targetNodes );
#if MEASURE_PERF 
        _xmlDiffPerf._preprocessTime = Environment.TickCount - startTickCount;
#endif

        // Find minimal edit distance between the trees
#if DEBUG
        Trace.WriteLineIf( T_Phases.Enabled, "* Computing minimal tree distance..." );
        if ( T_Tree.Enabled ) 
        {
            Trace.WriteLine( "Source tree: " );
            _sourceDoc.Dump( string.Empty );
            Trace.WriteLine( "Target tree: " );
            _targetDoc.Dump( string.Empty );
        }
#endif
#if MEASURE_PERF 
        startTickCount = Environment.TickCount;
#endif

        EditScript editScript = ( new MinimalTreeDistanceAlgo( this ) ).FindMinimalDistance();
        Debug.Assert( editScript != null );
#if MEASURE_PERF 
        _xmlDiffPerf._treeDistanceTime = Environment.TickCount - startTickCount;
#endif
#if DEBUG 
        if ( T_EditScript.Enabled )
        {
            Trace.Write( "\nMinimal edit script: \n" ); 
            editScript.Dump();
        }
#endif

        // Generate the diffgram
#if DEBUG
        Trace.WriteLineIf( T_Phases.Enabled, "* Generating diffgram..." );
#endif
#if MEASURE_PERF 
        startTickCount = Environment.TickCount;
#endif
        Diffgram diffgram = new DiffgramGenerator( this ).GenerateFromEditScript( editScript );

#if MEASURE_PERF 
        _xmlDiffPerf._diffgramGenerationTime = Environment.TickCount - startTickCount;
#endif
        return diffgram;
    }
 // Constructor
 internal OperationDescrNamespaceChange( DiffgramGenerator.NamespaceChange nsChange )
     : base(nsChange._opid)
 {
     _nsChange = nsChange;
 }
Esempio n. 4
0
    private bool Diff( XmlWriter diffgramWriter )
    {
        try
        {
#if MEASURE_PERF 
            int startTickCount = Environment.TickCount;
#endif
            // compare hash values of root nodes and return if same (the hash values were computed during load)
            if ( IdenticalSubtrees( _sourceDoc, _targetDoc ) )
            {
				if ( diffgramWriter != null )
				{
					Diffgram emptyDiffgram = new DiffgramGenerator( this ).GenerateEmptyDiffgram();

					emptyDiffgram.WriteTo( diffgramWriter );
					diffgramWriter.Flush();
				}
#if DEBUG
                Trace.WriteLineIf( T_Phases.Enabled, "* Done." );
#endif
#if MEASURE_PERF 
                _xmlDiffPerf._identicalOrNoDiffWriterTime = Environment.TickCount - startTickCount;
#endif
                return true;
            }
			else if ( diffgramWriter == null )
            {
#if DEBUG
                Trace.WriteLineIf( T_Phases.Enabled, "* Done." );
#endif
#if MEASURE_PERF 
                _xmlDiffPerf._identicalOrNoDiffWriterTime = Environment.TickCount - startTickCount;
#endif
				return false;
            }
#if MEASURE_PERF 
            _xmlDiffPerf._identicalOrNoDiffWriterTime = Environment.TickCount - startTickCount;
#endif

            // Match & shrink identical subtrees
#if DEBUG
            Trace.WriteLineIf( T_Phases.Enabled, "* Matching identical subtrees..." );
#endif
#if MEASURE_PERF 
            startTickCount = Environment.TickCount;
#endif
            MatchIdenticalSubtrees();

#if MEASURE_PERF 
            _xmlDiffPerf._matchTime = Environment.TickCount - startTickCount;
#endif
#if DEBUG
            Trace.WriteLineIf( T_Phases.Enabled, "* Source document shrinked: " + _sourceDoc.NodesCount + " nodes" );
            Trace.WriteLineIf( T_Phases.Enabled, "* Target document shrinked: " + _targetDoc.NodesCount + " nodes" );
#endif

            Diffgram diffgram = null;

            // Choose algorithm
            switch ( _algorithm ) {
                case XmlDiffAlgorithm.Fast:
                    diffgram = WalkTreeAlgorithm();
                    break;
                case XmlDiffAlgorithm.Precise:
                    diffgram = ZhangShashaAlgorithm();
                    break;
                case XmlDiffAlgorithm.Auto:
                    if ( _sourceDoc.NodesCount + _targetDoc.NodesCount <= MaxTotalNodesCountForTreeDistance )
                        diffgram = ZhangShashaAlgorithm();
                    else
                        diffgram = WalkTreeAlgorithm();
                    break;
                default:
                    Debug.Assert( false );
                    break;
            }

            // Output the diffgram
#if MEASURE_PERF 
            startTickCount = Environment.TickCount;
#endif
            Debug.Assert( diffgramWriter != null );
            diffgram.WriteTo( diffgramWriter );
            diffgramWriter.Flush();
#if MEASURE_PERF 
            _xmlDiffPerf._diffgramSaveTime = Environment.TickCount - startTickCount;
#endif

#if DEBUG
            Trace.WriteLineIf( T_Phases.Enabled, "* Done." );
#endif
        }
        finally
        {
            _sourceNodes = null;
            _targetNodes = null;

        }

        return false;
    }