{"id":23788723,"url":"https://github.com/suppierk/union-find","last_synced_at":"2025-06-28T10:36:02.481Z","repository":{"id":235505712,"uuid":"790793034","full_name":"SuppieRK/union-find","owner":"SuppieRK","description":"Hash Set with Union Find capabilities","archived":false,"fork":false,"pushed_at":"2025-06-24T01:19:45.000Z","size":109,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-06-24T02:27:50.086Z","etag":null,"topics":["hash-set","union-find"],"latest_commit_sha":null,"homepage":"","language":"Java","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/SuppieRK.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":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2024-04-23T14:38:14.000Z","updated_at":"2025-06-24T01:19:48.000Z","dependencies_parsed_at":"2024-07-13T01:26:40.318Z","dependency_job_id":"8a692c95-f2da-4aed-9141-df666d3d3f28","html_url":"https://github.com/SuppieRK/union-find","commit_stats":null,"previous_names":["suppierk/union-find"],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/SuppieRK/union-find","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SuppieRK%2Funion-find","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SuppieRK%2Funion-find/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SuppieRK%2Funion-find/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SuppieRK%2Funion-find/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SuppieRK","download_url":"https://codeload.github.com/SuppieRK/union-find/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SuppieRK%2Funion-find/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262417714,"owners_count":23307911,"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":["hash-set","union-find"],"created_at":"2025-01-01T16:48:01.310Z","updated_at":"2025-06-28T10:36:02.457Z","avatar_url":"https://github.com/SuppieRK.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Hash Set with Union Find capabilities\n\nThis dependency-less library serves for one simple purpose: provide an implementation of a data structure with Union-Find algorithm capabilities.\n\n[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2FSuppieRK%2Funion-find.svg?type=shield\u0026issueType=license)](https://app.fossa.com/projects/git%2Bgithub.com%2FSuppieRK%2Funion-find?ref=badge_shield\u0026issueType=license)\n\n[![SonarCloud](https://sonarcloud.io/images/project_badges/sonarcloud-orange.svg)](https://sonarcloud.io/summary/overall?id=SuppieRK_union-find)\n\n## Where can this be useful?\n\nUnion-Find algorithm is a good fit for tasks which require to:\n- Join elements together to form a union.\n- See if two elements belong to the same set.\n\nSome of the practical applications are:\n- Games (Go, Hex).\n- Dynamic connectivity problems (Kruskal's minimum spanning tree algorithm, graph cycle detection).\n- Image processing (segment an image based on its pixel qualities).\n- Social network analysis (finding clusters / communities in social networks).\n\n## How to use\n\n```java\npublic class Example {\n  public static void main(String[] args) {\n    HashUnionFindSet\u003cCharacter, String\u003e hufs =\n        // Note the function - it defines initial disjoint set for the value\n        // Function itself cannot be null, as well as its return value\n        new HashUnionFindSet\u003c\u003e(s -\u003e Character.toLowerCase(s.charAt(0)));\n\n    // Let's define our fruits\n    final String apple = \"Apple\";\n    final String banana = \"Banana\";\n    final String apricot = \"Apricot\";\n    final String blueberry = \"Blueberry\";\n\n    // The first two fruits will be in different sets\n    hufs.add(apple);\n    hufs.add(banana);\n    System.out.printf(\n        \"Are %s and %s connected? - %s%n\", \n        apple, banana, hufs.connected(apple, banana));\n\n    // Apricot will join the same set as Apple\n    hufs.add(apricot);\n    System.out.printf(\n        \"Are %s and %s connected? - %s%n\", \n        apple, apricot, hufs.connected(apple, apricot));\n\n    // Let's check our state\n    System.out.println();\n    System.out.printf(\n        \"There are %s disjoint sets%n\", \n        hufs.numberOfSets());\n    System.out.printf(\n        \"%s and %s belong to the set '%s' of size %s%n\",\n        apple, apricot, hufs.find(apple), hufs.elementSetSize(apple));\n    System.out.printf(\n        \"%s belongs to the set '%s' of size %s%n\",\n        banana, hufs.find(banana), hufs.elementSetSize(banana));\n\n    // Let's join our sets\n    hufs.union(apple, banana);\n\n    // And check our state again\n    System.out.println();\n    System.out.printf(\n        \"After union there is %s disjoint set%n\", \n        hufs.numberOfSets());\n    System.out.printf(\n        \"%s and %s belong to the set '%s' of size %s%n\",\n        apple, apricot, hufs.find(apple), hufs.elementSetSize(apple));\n    System.out.printf(\n        \"And %s belongs to the same set '%s' of size %s now%n\",\n        banana, hufs.find(banana), hufs.elementSetSize(banana));\n    System.out.printf(\n        \"Is the set under letter 'b' still present? - %s%n\", \n        hufs.hasRepresentative('b'));\n\n    // Let's throw in another fruit\n    hufs.add(blueberry);\n\n    // And check our state for the last time\n    System.out.println();\n    System.out.printf(\n        \"There are %s disjoint sets now%n\", \n        hufs.numberOfSets());\n    System.out.printf(\n        \"%s, %s and %s still belong to the set '%s' of size %s%n\",\n        apple, apricot, banana, hufs.find(apple), hufs.elementSetSize(apple));\n    System.out.printf(\n        \"But %s belongs to the set '%s' of size %s%n\",\n        blueberry, hufs.find(blueberry), hufs.elementSetSize(blueberry));\n  }\n}\n```\n\nwhich will produce the following output:\n\n```\nAre Apple and Banana connected? - false\nAre Apple and Apricot connected? - true\n\nThere are 2 disjoint sets\nApple and Apricot belong to the set 'a' of size 2\nBanana belongs to the set 'b' of size 1\n\nAfter union there is 1 disjoint set\nApple and Apricot belong to the set 'a' of size 3\nAnd Banana belongs to the same set 'a' of size 3 now\nIs the set under letter 'b' still present? - false\n\nThere are 2 disjoint sets now\nApple, Apricot and Banana still belong to the set 'a' of size 3\nBut Blueberry belongs to the set 'b' of size 1\n```\n\n## How to add\n\n- Maven\n```xml\n\u003cdependency\u003e\n    \u003cgroupId\u003eio.github.suppierk\u003c/groupId\u003e\n    \u003cartifactId\u003eunion-find\u003c/artifactId\u003e\n    \u003cversion\u003e1.1.0\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\n- Gradle\n```groovy\nimplementation 'io.github.suppierk:union-find:1.1.0'\n```\n\n## Useful reading\n\n- [Union−Find Applications | Welcome to Algorithms | edX Series](https://youtu.be/OMxd43qB6Bg?si=ZnWuIOWQPMLafTwh)\n- [Union-Find with Constant Time Deletions](https://www.cs.princeton.edu/courses/archive/fall05/cos528/handouts/Union-Find%20with%20Constant%20Time%20Deletions.pdf)\n- [Union-Find with deletions](http://www.aladdin.cs.cmu.edu/papers/pdfs/y2003/uniof.pdf)\n- [A simple and efficient Union-Find-Delete algorithm](https://www.sciencedirect.com/science/article/pii/S030439751000616X?ref=pdf_download\u0026fr=RR-9\u0026rr=86db096b1f70152a)\n\n## Inspired by\n\n- [JGraphT implementation](https://github.com/jgrapht/jgrapht/blob/master/jgrapht-core/src/main/java/org/jgrapht/alg/util/UnionFind.java)\n- [Partition implementation](https://github.com/gstamatelat/partition/blob/master/src/main/java/gr/james/partition/UnionFindPartition.java)\n\n## FOSSA report\n\n[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2FSuppieRK%2Funion-find.svg?type=large\u0026issueType=license)](https://app.fossa.com/projects/git%2Bgithub.com%2FSuppieRK%2Funion-find?ref=badge_large\u0026issueType=license)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsuppierk%2Funion-find","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsuppierk%2Funion-find","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsuppierk%2Funion-find/lists"}