Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mikolalysenko/union-find
A basic union-find data structure for node.js
https://github.com/mikolalysenko/union-find
Last synced: about 2 months ago
JSON representation
A basic union-find data structure for node.js
- Host: GitHub
- URL: https://github.com/mikolalysenko/union-find
- Owner: mikolalysenko
- License: mit
- Created: 2013-01-12T22:25:56.000Z (almost 12 years ago)
- Default Branch: master
- Last Pushed: 2017-11-26T16:48:26.000Z (about 7 years ago)
- Last Synced: 2024-10-20T14:24:55.604Z (2 months ago)
- Language: JavaScript
- Size: 249 KB
- Stars: 26
- Watchers: 6
- Forks: 9
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
union-find
==========A basic union-find data structure for node.js. For more information, see wikipdia:
[Disjoint Set Datastructures](http://en.wikipedia.org/wiki/Disjoint-set_data_structure)
Union find data structures solve the incremental connectivity problem. (That is maintaining a spanning forest under incremental insertions of edges.) To handle fully dynamic connectivity, you can use a [dynamic forest](https://www.npmjs.org/package/dynamic-forest) data structure.
Usage
=====
Here is an example showing how to do connected component labelling. Assume we are given a graph with `VERTEX_COUNT` vertices and a list of edges stored in array represented by pairs of vertex indices:```javascript
//Import data structure
var UnionFind = require('union-find')var VERTEX_COUNT = 8
var edges = [
[0,1],
[1,2],
[2,3],
[5,6],
[7,1]
]//Link all the nodes together
var forest = new UnionFind(VERTEX_COUNT)
for(var i=0; i