union_find

package
v0.0.0-...-881dfb5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 9, 2024 License: MIT Imports: 0 Imported by: 0

Documentation

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 can union two disjoint sets and find the disjoint set an element belong to in O(1) time. Each element is identified by an integer as an index of the underlying array.

func NewUnionFind

func NewUnionFind(n int) *UnionFind

NewUnionFind creates a UnionFind that identifies n elements, from 0 to n-1.

func (*UnionFind) Find

func (uf *UnionFind) Find(x int) int

Find returns the disjoint set x belongs to.

func (*UnionFind) Size

func (uf *UnionFind) Size(x int) int

Size returns the number of elements the disjoint set x belongs to.

func (*UnionFind) Union

func (uf *UnionFind) Union(x, y int)

Union merges the disjoint set x belongs to and the disjoint set y belongs to. If x and y belong to the same set, Union is a noop.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL