File tree 1 file changed +5
-4
lines changed
src/main/java/pascal/taie/util/collection
1 file changed +5
-4
lines changed Original file line number Diff line number Diff line change 26
26
import java .util .HashMap ;
27
27
import java .util .Map ;
28
28
import java .util .Set ;
29
+ import java .util .concurrent .atomic .AtomicInteger ;
29
30
import java .util .stream .Collectors ;
30
31
31
32
public class UnionFindSet <E > {
@@ -38,11 +39,11 @@ public class UnionFindSet<E> {
38
39
/**
39
40
* Number of disjoint sets.
40
41
*/
41
- private int setCount ;
42
+ private final AtomicInteger setCount = new AtomicInteger () ;
42
43
43
44
public UnionFindSet (Collection <E > elems ) {
44
45
elems .forEach (elem -> entries .put (elem , new Entry (elem )));
45
- setCount = entries .size ();
46
+ setCount . set ( entries .size () );
46
47
}
47
48
48
49
/**
@@ -65,7 +66,7 @@ public boolean union(E e1, E e2) {
65
66
root2 .parent = root1 ;
66
67
++root2 .rank ;
67
68
}
68
- -- setCount ;
69
+ setCount . decrementAndGet () ;
69
70
return true ;
70
71
}
71
72
}
@@ -90,7 +91,7 @@ public E findRoot(E e) {
90
91
* @return number of disjoint sets in this union-find set.
91
92
*/
92
93
public int numberOfSets () {
93
- return setCount ;
94
+ return setCount . get () ;
94
95
}
95
96
96
97
/**
You can’t perform that action at this time.
0 commit comments