unionfind

package
v0.0.0-...-d229d73 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2024 License: MIT Imports: 0 Imported by: 0

README

并查集(union-find)

在计算机科学中,并查集是一种树型的数据结构,用于处理一些不相交集合(Disjoint Sets)的合并及查询问题。有一个联合-查找算法(union-find algorithm)定义了两个用于此数据结构的操作:

  • Find:确定元素属于哪一个子集。它可以被用来确定两个元素是否属于同一子集。
  • Union:将两个子集合并成同一个集合。

动态连通性

假设输入是一列整数对,其中每个整数都表示某种类型的对象。输入的的整数对是p和q,我们可以理解p和q是相连的。也就意味着具有三个特性:

  • 自反性:p和q是相连的;
  • 对称性:如果p和q是相连的,那么q和p也是相连的;
  • 传递性:如果p和q是相连的并且q和是相连的,那么p和r也是相连的。

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type UF

type UF struct {
	// contains filtered or unexported fields
}

UF : Union-Find.

func New

func New() *UF

New : create a empty Union-Find.

func (*UF) Connected

func (uf *UF) Connected(p, q interface{}) bool

Connected : return true if p ∈ setA && q ∈ setA else false.

func (*UF) Count

func (uf *UF) Count() int

Count : count of disjoint sets.

func (*UF) Find

func (uf *UF) Find(value interface{}) interface{}

Find : return ancestor's value.

func (*UF) SetCount

func (uf *UF) SetCount() map[interface{}]int

SetCount : value

func (*UF) Union

func (uf *UF) Union(p, q interface{})

Union : add a connection for p and q.

Jump to

Keyboard shortcuts

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