File tree Expand file tree Collapse file tree 1 file changed +10
-6
lines changed Expand file tree Collapse file tree 1 file changed +10
-6
lines changed Original file line number Diff line number Diff line change 5
5
//! It provides near-constant-time operations to add new sets, to find the
6
6
//! representative of a set, and to merge sets.
7
7
8
+ use std:: cmp:: Ordering ;
8
9
use std:: collections:: HashMap ;
9
10
use std:: fmt:: Debug ;
10
11
use std:: hash:: Hash ;
@@ -73,12 +74,15 @@ impl<T: Debug + Eq + Hash> UnionFind<T> {
73
74
return false ;
74
75
}
75
76
76
- if self . sizes [ first_root] < self . sizes [ sec_root] {
77
- self . parent_links [ first_root] = sec_root;
78
- self . sizes [ sec_root] += self . sizes [ first_root] ;
79
- } else {
80
- self . parent_links [ sec_root] = first_root;
81
- self . sizes [ first_root] += self . sizes [ sec_root] ;
77
+ match self . sizes [ first_root] . cmp ( & self . sizes [ sec_root] ) {
78
+ Ordering :: Less => {
79
+ self . parent_links [ first_root] = sec_root;
80
+ self . sizes [ sec_root] += self . sizes [ first_root] ;
81
+ }
82
+ _ => {
83
+ self . parent_links [ sec_root] = first_root;
84
+ self . sizes [ first_root] += self . sizes [ sec_root] ;
85
+ }
82
86
}
83
87
84
88
self . count -= 1 ;
You can’t perform that action at this time.
0 commit comments