Skip to content

Commit 1247c37

Browse files
sozelfistvil02
authored andcommitted
chore: replace if else by match
1 parent 38431b0 commit 1247c37

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/data_structures/union_find.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
//! It provides near-constant-time operations to add new sets, to find the
66
//! representative of a set, and to merge sets.
77
8+
use std::cmp::Ordering;
89
use std::collections::HashMap;
910
use std::fmt::Debug;
1011
use std::hash::Hash;
@@ -73,12 +74,15 @@ impl<T: Debug + Eq + Hash> UnionFind<T> {
7374
return false;
7475
}
7576

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+
}
8286
}
8387

8488
self.count -= 1;

0 commit comments

Comments
 (0)