{"id":16126746,"url":"https://github.com/mikolalysenko/union-find","last_synced_at":"2025-03-16T09:31:56.642Z","repository":{"id":6345121,"uuid":"7581363","full_name":"mikolalysenko/union-find","owner":"mikolalysenko","description":"A basic union-find data structure for node.js","archived":false,"fork":false,"pushed_at":"2017-11-26T16:48:26.000Z","size":255,"stargazers_count":26,"open_issues_count":0,"forks_count":9,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-03-04T15:42:02.174Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mikolalysenko.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-01-12T22:25:56.000Z","updated_at":"2023-04-17T18:27:42.000Z","dependencies_parsed_at":"2022-09-01T06:32:24.250Z","dependency_job_id":null,"html_url":"https://github.com/mikolalysenko/union-find","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mikolalysenko%2Funion-find","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mikolalysenko%2Funion-find/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mikolalysenko%2Funion-find/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mikolalysenko%2Funion-find/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mikolalysenko","download_url":"https://codeload.github.com/mikolalysenko/union-find/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243713193,"owners_count":20335562,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-09T21:40:11.236Z","updated_at":"2025-03-16T09:31:56.345Z","avatar_url":"https://github.com/mikolalysenko.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"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\u003cedges.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\u003cVERTEX_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","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmikolalysenko%2Funion-find","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmikolalysenko%2Funion-find","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmikolalysenko%2Funion-find/lists"}