Skip to content

Commit 9aaebc2

Browse files
committed
Made Dsu struct fields public
1 parent 0d70435 commit 9aaebc2

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

dsu.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ package dsu
33
const noParent = ^uint(0)
44

55
type Dsu struct {
6-
parent []uint
7-
size []uint
6+
Parent []uint
7+
Size []uint
88
}
99

1010
// Create a new Disjoint Set Union data structure with n elements.
@@ -14,22 +14,22 @@ type Dsu struct {
1414
// a correspondence between the element values and their indices.
1515
func NewDsu(n uint) Dsu {
1616
dsu := Dsu{
17-
parent: make([]uint, n),
18-
size: make([]uint, n),
17+
Parent: make([]uint, n),
18+
Size: make([]uint, n),
1919
}
20-
for i := range dsu.parent {
21-
dsu.parent[i] = noParent
22-
dsu.size[i] = 1
20+
for i := range dsu.Parent {
21+
dsu.Parent[i] = noParent
22+
dsu.Size[i] = 1
2323
}
2424
return dsu
2525
}
2626

2727
func (d *Dsu) Find(v uint) uint {
28-
if d.parent[v] == noParent {
28+
if d.Parent[v] == noParent {
2929
return v
3030
}
31-
d.parent[v] = d.Find(d.parent[v])
32-
return d.parent[v]
31+
d.Parent[v] = d.Find(d.Parent[v])
32+
return d.Parent[v]
3333
}
3434

3535
func (d *Dsu) Union(v1, v2 uint) {
@@ -38,9 +38,9 @@ func (d *Dsu) Union(v1, v2 uint) {
3838
if v1 == v2 {
3939
return
4040
}
41-
if d.size[v1] < d.size[v2] {
41+
if d.Size[v1] < d.Size[v2] {
4242
v1, v2 = v2, v1
4343
}
44-
d.parent[v2] = v1
45-
d.size[v1] += d.size[v2]
44+
d.Parent[v2] = v1
45+
d.Size[v1] += d.Size[v2]
4646
}

0 commit comments

Comments
 (0)