Documentation ¶
Index ¶
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
}
DSU is the type used to the Disjoint Set data structure. it maps from a value to a node pointer corresponding to the element in the set.
func (*DSU) Add ¶
Add takes an element as a parameter and inserts it in the disjoint set. If the element already exists in the set, then nothing is done, and the return is false otherwise returns true
func (*DSU) Find ¶
func (d *DSU) Find(x interface{}) interface{}
Find returns the root element that represents the set to which x belongs to. If the element doesn't exist in the set, Find returns the nil value.
func (*DSU) Union ¶
Union replaces the set containing x and the set containing y with their union. Union uses Find to determine the roots of the trees containing x and y. If the roots are the same of one of the elements doesn't exist in the set, there is nothing more to do. and Union returns false Otherwise, the two sets get be merged. This is done by either setting the parent element of the element with the smaller size to the other parent and the return of the function in this case is true