{"name":"union-find","version":"0.0.3","description":"A union-find data structure for maintaining disjoint sets.","main":"index.js","repository":{"type":"git","url":"git://github.com/mikolalysenko/union-find.git"},"keywords":["union","find","link","disjoint","set","connected","component","graph"],"author":{"name":"Mikola Lysenko"},"license":"MIT","gitHead":"8fbd75feecd9d7154f4c2ff21754f483ad07ccab","_id":"union-find@0.0.3","dist":{"shasum":"c103cbe156050e88dd3c35b32b4d8049be622c74","tarball":"http://registry-npm.ywwl.com/union-find/download/union-find-0.0.3.tgz","integrity":"sha512-cPrg5bpK5BzhMI5HRg0AlEd7b26wVmHiH0LDhIe2S82TUKMcYWBavFIE3em6T4jlKcaj3dmiG67O8CK4QpUYuQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIG0FAwpTPxsg6m1/L1fLzQLjtN1q3U7Tw3moxKqarkTWAiEAiKkCF7g6NHt+ELVBMAKVwhcEjewIJm6pTaVhe7KYJi0="}],"size":1478,"noattachment":false,"key":"/union-find/-/union-find-0.0.3.tgz"},"_npmVersion":"1.1.70","_npmUser":{"name":"mikolalysenko","email":"mikolalysenko@gmail.com"},"maintainers":[{"name":"mikolalysenko","email":"mikolalysenko@gmail.com"}],"directories":{},"readme":"union-find\n==========\n\nA basic union-find data structure for node.js.  For more information, see wikipdia:\n\n[Disjoint Set Datastructures](http://en.wikipedia.org/wiki/Disjoint-set_data_structure)\n\nUnion 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.\n\nUsage\n=====\nHere 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:\n\n```javascript\n//Import data structure\nvar UnionFind = require('union-find')\n\nvar VERTEX_COUNT = 8\nvar edges = [\n    [0,1],\n    [1,2],\n    [2,3],\n    [5,6],\n    [7,1]\n]\n\n//Link all the nodes together\nvar forest = new UnionFind(VERTEX_COUNT)\nfor(var i=0; i<edges.length; ++i) {\n  forest.link(edges[i][0], edges[i][1])\n}\n\n//Label components\nvar labels = new Array(VERTEX_COUNT)\nfor(var i=0; i<VERTEX_COUNT; ++i) {\n  labels[i] = forest.find(i)\n}\n```\n\nInstallation\n============\n\n```\nnpm install union-find\n```\n\n# API\n\n```javascript\nvar UnionFind = require('union-find')\n```\n\n## Constructor\n\n### `var forest = new UnionFind(numVertices)`\nCreates a new union-find data structure.\n\n* `numVertices` is the number of vertices in the graph\n\n**Returns** A new union-find data structure\n\n## Methods\n\n### `forest.length`\nReturns the number of vertices in the forest\n\n### `forest.makeSet()`\nCreates a new vertex\n\n**Returns** An integer id for the new vertex\n\n### `forest.find(v)`\nReturns an identifier representing the connected component of any given vertex\n\n**Returns** An integer id representing the connected component of `v`\n\n### `forest.link(s, t)`\nLinks a pair of connected components together\n\n* `s` and `t` are both vertices\n    \nCredits\n=======\n(c) 2013-2014 Mikola Lysenko.  MIT License","publish_time":1358737844950,"_cnpm_publish_time":1358737844950,"dist-tags":{"latest":"1.0.2"}}