@@ -53,6 +53,7 @@ struct Pair {
53
53
std::vector<Match> matches;
54
54
Directory *directory1;
55
55
Directory *directory2;
56
+ float match_ratio;
56
57
};
57
58
58
59
std::regex *glob = nullptr ;
@@ -153,6 +154,8 @@ void do_diff(Pair *pair, Directory *d1, Directory *d2) {
153
154
pair->directory1 = d1;
154
155
pair->directory2 = d2;
155
156
157
+ unsigned file_count = 0 ;
158
+ double totalSim = 0.0 ;
156
159
for (size_t i = 0 ; i < d1->sexps .size (); i++) {
157
160
for (size_t j = 0 ; j < d2->sexps .size (); j++) {
158
161
const std::string &p1 = d1->sexps [i].path ;
@@ -176,10 +179,18 @@ void do_diff(Pair *pair, Directory *d1, Directory *d2) {
176
179
if (s < sim)
177
180
continue ;
178
181
182
+ totalSim += s;
183
+ file_count++;
184
+
179
185
pair->matches .emplace_back (&d1->sexps [i], &d2->sexps [j], s,
180
186
MappingsVec2 (t1, mapping));
181
187
}
182
188
}
189
+
190
+ if (file_count == 0 )
191
+ pair->match_ratio = 0.0 ;
192
+ else
193
+ pair->match_ratio = totalSim / file_count;
183
194
}
184
195
185
196
std::ostream &dump_match (const Match &match, std::ostream &os) {
@@ -219,6 +230,7 @@ void dump_pairs(const std::vector<Pair> &pairs) {
219
230
220
231
f << " \" directory1\" : \" " << pair.directory1 ->cc_path << " \" ," ;
221
232
f << " \" directory2\" : \" " << pair.directory2 ->cc_path << " \" ," ;
233
+ f << " \" match_ratio\" : " << pair.match_ratio << " ," ;
222
234
f << " \" matches\" : [" ;
223
235
for (size_t i = 0 ; i < pair.matches .size (); i++) {
224
236
dump_match (pair.matches [i], f);
0 commit comments