Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Dsu ¶
type Dsu struct {
// contains filtered or unexported fields
}
Example ¶
package main
import (
"fmt"
"alon.kr/x/dsu"
)
func main() {
d := dsu.NewDsu(3)
d.Union(0, 1)
if d.Find(0) == d.Find(1) {
fmt.Println("0 and 1 are in the same set")
}
if d.Find(1) != d.Find(2) {
fmt.Println("1 and 2 are in different sets")
}
if d.Size(0) == 2 {
fmt.Println("Set with the element 0 has 2 elements")
}
}
Output: 0 and 1 are in the same set 1 and 2 are in different sets Set with the element 0 has 2 elements
func NewDsu ¶
Create a new Disjoint Set Union data structure with n elements. The elements are referred to by their index in the range [0, n). The element values are not stored explicitly in the data structure, and the user of the data structure is responsible for maintaining a correspondence between the element values and their indices.
Click to show internal directories.
Click to hide internal directories.