11//! Main diff engine
22
3- use crate :: matching:: FunctionMatcher ;
4- use crate :: tree_edit:: { TreeEditDistance , EditCost } ;
53use crate :: changes:: ChangeClassifier ;
4+ use crate :: matching:: FunctionMatcher ;
65use crate :: refactoring:: RefactoringDetector ;
6+ use crate :: tree_edit:: { EditCost , TreeEditDistance } ;
7+ use serde:: { Deserialize , Serialize } ;
78use smart_diff_parser:: { Function , MatchResult } ;
89use thiserror:: Error ;
9- use serde:: { Deserialize , Serialize } ;
1010
1111/// Main diff engine that orchestrates the comparison process
1212pub struct DiffEngine {
@@ -41,10 +41,10 @@ pub struct DiffStatistics {
4141pub enum DiffError {
4242 #[ error( "Comparison failed: {0}" ) ]
4343 ComparisonFailed ( String ) ,
44-
44+
4545 #[ error( "Invalid input: {0}" ) ]
4646 InvalidInput ( String ) ,
47-
47+
4848 #[ error( "Processing error: {0}" ) ]
4949 ProcessingError ( String ) ,
5050}
@@ -58,39 +58,55 @@ impl DiffEngine {
5858 refactoring_detector : RefactoringDetector :: new ( ) ,
5959 }
6060 }
61-
61+
6262 /// Compare two sets of functions
63- pub fn compare_functions ( & self , source_functions : & [ Function ] , target_functions : & [ Function ] ) -> Result < DiffResult , DiffError > {
63+ pub fn compare_functions (
64+ & self ,
65+ source_functions : & [ Function ] ,
66+ target_functions : & [ Function ] ,
67+ ) -> Result < DiffResult , DiffError > {
6468 let start_time = std:: time:: Instant :: now ( ) ;
65-
69+
6670 // Match functions
67- let match_result = self . function_matcher . match_functions ( source_functions, target_functions) ;
68-
71+ let match_result = self
72+ . function_matcher
73+ . match_functions ( source_functions, target_functions) ;
74+
6975 // Detect refactoring patterns
70- let refactoring_patterns = self . refactoring_detector . detect_patterns ( & match_result. changes ) ;
71-
76+ let refactoring_patterns = self
77+ . refactoring_detector
78+ . detect_patterns ( & match_result. changes ) ;
79+
7280 // Calculate statistics
73- let statistics = self . calculate_statistics ( source_functions, target_functions, & match_result) ;
74-
81+ let statistics =
82+ self . calculate_statistics ( source_functions, target_functions, & match_result) ;
83+
7584 let execution_time_ms = start_time. elapsed ( ) . as_millis ( ) as u64 ;
76-
85+
7786 Ok ( DiffResult {
7887 match_result,
7988 refactoring_patterns,
8089 execution_time_ms,
8190 statistics,
8291 } )
8392 }
84-
85- fn calculate_statistics ( & self , source : & [ Function ] , target : & [ Function ] , match_result : & MatchResult ) -> DiffStatistics {
93+
94+ fn calculate_statistics (
95+ & self ,
96+ source : & [ Function ] ,
97+ target : & [ Function ] ,
98+ match_result : & MatchResult ,
99+ ) -> DiffStatistics {
86100 let functions_compared = source. len ( ) + target. len ( ) ;
87101 let functions_matched = match_result. mapping . len ( ) ;
88102 let functions_added = match_result. unmatched_target . len ( ) ;
89103 let functions_removed = match_result. unmatched_source . len ( ) ;
90- let functions_modified = match_result. changes . iter ( )
104+ let functions_modified = match_result
105+ . changes
106+ . iter ( )
91107 . filter ( |c| matches ! ( c. change_type, smart_diff_parser:: ChangeType :: Modify ) )
92108 . count ( ) ;
93-
109+
94110 DiffStatistics {
95111 functions_compared,
96112 functions_matched,
0 commit comments