@@ -14,81 +14,6 @@ pub struct DiffWalker {
14
14
pub rhs_root : RootSchema ,
15
15
}
16
16
17
- trait DiffScore {
18
- fn diff_score ( & mut self , rhs : & mut Self ) -> usize ;
19
- }
20
-
21
- impl DiffScore for Schema {
22
- fn diff_score ( & mut self , rhs : & mut Self ) -> usize {
23
- self . clone ( )
24
- . into_object ( )
25
- . diff_score ( & mut rhs. clone ( ) . into_object ( ) )
26
- }
27
- }
28
- impl DiffScore for SchemaObject {
29
- fn diff_score ( & mut self , rhs : & mut Self ) -> usize {
30
- let mut score = 0 ;
31
- if self . effective_type ( ) != rhs. effective_type ( ) {
32
- score += 10 ;
33
- }
34
- score += self . number ( ) . diff_score ( rhs. number ( ) )
35
- + self . string ( ) . diff_score ( rhs. string ( ) )
36
- + self . object ( ) . diff_score ( rhs. object ( ) ) ;
37
- score
38
- }
39
- }
40
-
41
- impl DiffScore for NumberValidation {
42
- fn diff_score ( & mut self , rhs : & mut Self ) -> usize {
43
- let mut score = 0 ;
44
- if self . multiple_of != rhs. multiple_of {
45
- score += 1 ;
46
- }
47
- if self . minimum != rhs. minimum {
48
- score += 1 ;
49
- }
50
- if self . maximum != rhs. maximum {
51
- score += 1 ;
52
- }
53
- score
54
- }
55
- }
56
-
57
- impl DiffScore for StringValidation {
58
- fn diff_score ( & mut self , rhs : & mut Self ) -> usize {
59
- let mut score = 0 ;
60
- if self . pattern != rhs. pattern {
61
- score += 1 ;
62
- }
63
- if self . min_length != rhs. min_length {
64
- score += 1 ;
65
- }
66
- if self . max_length != rhs. max_length {
67
- score += 1 ;
68
- }
69
- score
70
- }
71
- }
72
-
73
- impl DiffScore for ObjectValidation {
74
- fn diff_score ( & mut self , rhs : & mut Self ) -> usize {
75
- let mut score = 0 ;
76
- if self . required != rhs. required {
77
- score += 1 ;
78
- }
79
- if self . properties != rhs. properties {
80
- score += 1 ;
81
- }
82
- if self . pattern_properties != rhs. pattern_properties {
83
- score += 1 ;
84
- }
85
- if self . additional_properties != rhs. additional_properties {
86
- score += 1 ;
87
- }
88
- score
89
- }
90
- }
91
-
92
17
impl DiffWalker {
93
18
fn diff_any_of (
94
19
& mut self ,
@@ -113,11 +38,21 @@ impl DiffWalker {
113
38
114
39
let mut mat = vec ! [ ] ;
115
40
let len = lhs_any_of. len ( ) ;
116
- lhs_any_of. iter_mut ( ) . for_each ( |l| {
117
- rhs_any_of
118
- . iter_mut ( )
119
- . for_each ( |r| mat. push ( l. diff_score ( r) ) )
120
- } ) ;
41
+ for l in lhs_any_of. iter_mut ( ) {
42
+ for r in rhs_any_of. iter_mut ( ) {
43
+ let mut walker = DiffWalker {
44
+ changes : vec ! [ ] ,
45
+ lhs_root : self . lhs_root . clone ( ) ,
46
+ rhs_root : self . rhs_root . clone ( ) ,
47
+ } ;
48
+ walker. diff (
49
+ "" ,
50
+ & mut l. clone ( ) . into_object ( ) ,
51
+ & mut r. clone ( ) . into_object ( ) ,
52
+ ) ?;
53
+ mat. push ( walker. changes . len ( ) ) ;
54
+ }
55
+ }
121
56
let pairs = hungarian:: minimize ( & mat, len, len)
122
57
. into_iter ( )
123
58
. enumerate ( )
0 commit comments