All Projects → theodesp → unionfind

theodesp / unionfind

Licence: MIT license
An idiomatic implementation of a weighted Union Find data structure with path compression in Go.

Programming Languages

go
31211 projects - #10 most used programming language
Makefile
30231 projects

Projects that are alternatives of or similar to unionfind

DEPRECATED-data-structures
A collection of powerful data structures
Stars: ✭ 2,648 (+15476.47%)
Mutual labels:  union-find
unionfind
A union-find disjoint sets data structure implemented in Python with the "Weighted Quick Union with Path Compression" algorithm.
Stars: ✭ 51 (+200%)
Mutual labels:  union-find
Data Structures
A collection of powerful data structures
Stars: ✭ 2,534 (+14805.88%)
Mutual labels:  union-find
py-algorithms
Algorithms and Data Structures, solutions to common CS problems.
Stars: ✭ 26 (+52.94%)
Mutual labels:  union-find
DSA
Data Structures and Algorithms
Stars: ✭ 13 (-23.53%)
Mutual labels:  union-find
connected-component
Map Reduce Implementation of Connected Component on Apache Spark
Stars: ✭ 68 (+300%)
Mutual labels:  union-find

unionfind

An idiomatic implementation of a weighted Union Find data structure with path compression in go.

Install

$ go get github.com/theodesp/unionfind

Usage

// Initialize with size
uf := unionfind.New(10)

// Union a,b connects components at index a and b
uf.Union(1, 2)
uf.Union(2, 3)
uf.Union(5, 6)
uf.Union(4, 6)

fmt.PrintLn(uf.Find(2)) // Prints 1
fmt.PrintLn(uf.Connected(1, 2)) // Prints true
fmt.PrintLn(uf.Connected(1, 3)) // Prints false

API

uf := unionfind.New(N)

Create a new Union Find Structure with size N.

uf.Union(p, q)

Connects p and q components.

uf.Find(p)

Attempts to find the Root component of p. Returns -1 if p is out of bounds.

uf.Root(p, q)

Same as Find.

uf.Connected(p, q)

Checks if p and q are connected.

EXTRA

There is also a goroutine safe version of unionfind in the file safe-unionfind.

Licence

MIT - Theo Despoudis

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].