Documentation
¶
Overview ¶
Package unionfind implements a UnionFind (disjoint-set) data structure, as described, for example, here: http://algs4.cs.princeton.edu/15uf .
The Union() and Connected() operations take O(log* N) “log-star” time, which is close to O(1).
The MakeSet() operation when used with multiple arguments, unions elements in one set.
Basic usage:
u := unionfind.New() // Create sets (optional). u.MakeSet(1, 2, 3, 4) // Join them together. u.Union(1, 2) u.Union(3, 4) u.Union(2, 3) // Check if they're connected. fmt.Println(u.Connected(1, 4))
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type UnionFind ¶
type UnionFind struct {
// contains filtered or unexported fields
}
UnionFind maintains sets and a number of connected elements.
func (UnionFind) Connected ¶
Connected returns true if the elements belong to the same set, false otherwise.
func (UnionFind) Find ¶
Find returns the root element of the set. The root element is the same for all elements within the same set.
func (*UnionFind) MakeSet ¶
MakeSet makes an independent set of one element. If called with multiple arguments, an independent set for every element is made.