{"id":23758895,"url":"https://github.com/nawatts/disjoint","last_synced_at":"2025-09-05T04:34:35.781Z","repository":{"id":10125298,"uuid":"64562303","full_name":"nawatts/disjoint","owner":"nawatts","description":"Implementation of a disjoint set","archived":false,"fork":false,"pushed_at":"2022-12-30T21:01:17.000Z","size":836,"stargazers_count":3,"open_issues_count":12,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-12-02T04:44:00.559Z","etag":null,"topics":["data-structures","disjoint-sets"],"latest_commit_sha":null,"homepage":"http://nawatts.github.io/disjoint","language":"TypeScript","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/nawatts.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":"2016-07-30T20:11:37.000Z","updated_at":"2023-06-10T07:18:58.000Z","dependencies_parsed_at":"2023-01-13T15:45:31.840Z","dependency_job_id":null,"html_url":"https://github.com/nawatts/disjoint","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nawatts%2Fdisjoint","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nawatts%2Fdisjoint/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nawatts%2Fdisjoint/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nawatts%2Fdisjoint/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nawatts","download_url":"https://codeload.github.com/nawatts/disjoint/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":232024696,"owners_count":18461967,"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":["data-structures","disjoint-sets"],"created_at":"2024-12-31T19:56:00.230Z","updated_at":"2024-12-31T19:56:00.893Z","avatar_url":"https://github.com/nawatts.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# disjoint\n\nImplementation of a [disjoint set](https://en.wikipedia.org/wiki/Disjoint-set_data_structure).\n\nSupports tracking arbitrary information about each subset and updating it as new links are added.\n\n[![npm version](https://img.shields.io/npm/v/disjoint.svg)](https://www.npmjs.com/package/disjoint)\n\n```JavaScript\n// Example: 6 elements connected with weighted edges\n// Edge weights are in parentheses\n// Track maximum edge weight in each subset\n//\n//    0 -(2)- 1       2\n//    |               |\n//   (4)             (3)\n//    |               |\n//    3 -(1)- 4       5\n//\n\nconst { DisjointSet } = require('disjoint');\n\nconst set = new DisjointSet(\n  6, // Size of disjoint set\n  function(s1, s2, edge) {\n    // Reducer for updating subset properties when two subsets are joined.\n    // s1: properties of one subset\n    // s2: properties of the other subset\n    // edge: edge properties, from third argument to union\n    return {\n      maxWeight: Math.max(s1.maxWeight, s2.maxWeight, edge.weight)\n    }\n  },\n  { maxWeight: 0 } // Initial value for subset properties.\n);\n\n// Join elements\nset.union(0, 1, { weight: 2 });\nset.union(2, 5, { weight: 3 });\nset.union(3, 4, { weight: 1 });\nset.union(3, 0, { weight: 4 });\n\n// Test if elements are connected\nset.isConnected(0, 4); // true\nset.isConnected(1, 2); // false\n\n// Number of subsets\nset.numSubsets(); // 2\n\n// List of all subsets\nset.subsets(); // [ [0, 1, 3, 4], [2, 5] ]\n\n// Subset containing a specific element\nset.subset(2) // [2, 5]\n\n// Properties of subset containing a specific element\nset.subsetProps(1) // { maxWeight: 4 }\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnawatts%2Fdisjoint","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnawatts%2Fdisjoint","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnawatts%2Fdisjoint/lists"}