{"id":20528911,"url":"https://github.com/liavbarsheshet/union-find","last_synced_at":"2026-02-23T01:32:02.906Z","repository":{"id":104350312,"uuid":"582113994","full_name":"liavbarsheshet/union-find","owner":"liavbarsheshet","description":"Generic Union Find Based on up root tree written in c++.","archived":false,"fork":false,"pushed_at":"2023-01-01T08:38:29.000Z","size":17,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-07T10:26:59.644Z","etag":null,"topics":["cpp","data-structures","union-find","unionfind"],"latest_commit_sha":null,"homepage":"","language":"C++","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/liavbarsheshet.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-12-25T18:26:29.000Z","updated_at":"2023-04-26T15:12:15.000Z","dependencies_parsed_at":null,"dependency_job_id":"0a6574da-c971-4573-ad64-f9eaf5752446","html_url":"https://github.com/liavbarsheshet/union-find","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/liavbarsheshet/union-find","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/liavbarsheshet%2Funion-find","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/liavbarsheshet%2Funion-find/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/liavbarsheshet%2Funion-find/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/liavbarsheshet%2Funion-find/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/liavbarsheshet","download_url":"https://codeload.github.com/liavbarsheshet/union-find/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/liavbarsheshet%2Funion-find/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29734468,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-22T20:09:16.275Z","status":"ssl_error","status_checked_at":"2026-02-22T20:09:13.750Z","response_time":110,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["cpp","data-structures","union-find","unionfind"],"created_at":"2024-11-15T23:27:58.609Z","updated_at":"2026-02-23T01:32:02.876Z","avatar_url":"https://github.com/liavbarsheshet.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# C++ Union Find\n\nGeneric Union Find Based on up root tree written in c++.\n\n---\n\n## Declaration\n\nSupports \u003e= c++11:\n\n```c++\n#include \"union-find.hpp\"\n\nauto uf = UNION::UnionFind\u003cDATA\u003e();\n```\n\n## Template\n\n```c++\n/**\n * Class: Represents the entire UNION FIND.\n * @tparam DATA - The type/class of the data.\n */\ntemplate\u003ctypename DATA\u003e\nclass UNION::UnionFind {...}\n```\n\n## Enums\n\n```c++\n// Represents the data structure policy.\ntypedef enum {\nU_NONE, U_OPTIMIZE, U_SENSITIVE_ORDER, U_BOTH\n} POLICY;\n```\n\n## UNION::Member\n```c++\n/**\n * Constructor: Creates a node with a value.\n * @param value - T value.\n */\nMember(T value) : {...}\n\n/**\n * Copy Constructor: Creates a node from another.\n * @param member - Another node\n */\nMember(const Member\u003cT\u003e \u0026member){...}\n```\n\n## UNION::SetData\n\n```c++\n/**\n * Constructor: Creates an initial data.\n * @param id - Sets id.\n */\nSetData(size_t id) {...};\n\n/**\n * Copy Constructor: Creates set data from another.\n * @param data - Another set data reference.\n */\nSetData(const SetData \u0026data) {...}\n\n/**\n * Joins between two SetData\n * @param data - Another set of data.\n */\nvoid Join(const SetData \u0026data) {...}\n```\n\n## UNION::UpNode ~ Item\n\n```c++\n/**\n * Constructor: Creates a new UpNode (Item)\n * @param id - Item id.\n * @param data - Item data.\n */\nexplicit UpNode(size_t id, DATA *data) {...}\n\n/**\n * Copy Constructor: Creates a UpNode (Item) from another\n * @param nod - Another UpNode.\n */\nUpNode(const UpNode \u0026nod) {...}\n\n/**\n * Destructor.\n */\n~UpNode() {...}\n\n/**\n * Gets the id of this item.\n * @return {size_t} This item id.\n */\nsize_t GetID() const {...}\n\n/**\n * Gets the data of this item.\n * @return {DATA} This item data.\n */\nDATA GetData() const {...}\n\n/**\n * Gets the info of this item.\n * @return {UNION::SetData} This item info.\n */\nUNION::SetData GetInfo() const {..}\n\nfriend std::ostream \u0026operator\u003c\u003c(std::ostream \u0026os, const UpNode \u0026node) {...}\n```\n\n## UNION::UnionFind\n```c++\n/**\n * Constructor: Creates an empty Union Find DS.\n * @note Worst-Time Complexity: O(1).\n * @note Worst-Space Complexity: O(1).\n */\nexplicit UnionFind(UNION::POLICY policy = U_NONE) {...}\n\n/**\n * Copy Constructor: Creates UF from another\n * @note Worst-Time Complexity: O(n).\n * @note Worst-Space Complexity: O(n).\n * @param uf A reference to another UF.\n */\nUnionFind(const UnionFind\u003cDATA\u003e \u0026uf) {...}\n    \n/**\n * Destructor.\n */\n~UnionFind() {...}\n\n/**\n * Make a new set and gives unique id to it.\n * @note Worst-Time Complexity: O(1).\n * @note Worst-Space Complexity: O(1).\n * @param data - The data that the item will have.\n * @return {size_t} Returns the new id.\n */\nsize_t MakeSet(DATA *data = NULL) {...};\n\n/**\n * Find a set with a given set id.\n * @note Worst-Time Complexity: O(1).\n * @note Worst-Space Complexity: O(1).\n * @param id - The id of the set.\n * @return {UNION::UpNode\u003cDATA\u003e} Return the set node.\n */\nUNION::UpNode\u003cDATA\u003e GetSet(size_t id) const {...}\n\n/**\n * Gets the total sets that are in the UF.\n * @note It will return the number of sets not the number of items.\n * @note Worst-Time Complexity: O(1).\n * @note Worst-Space Complexity: O(1).\n * @return {size_t} Total amount of sets.\n */\nsize_t GetSetsAmount() const {...}\n\n/**\n * Gets the total items that are in the UF.\n * @note It will return the number of items not the number of sets.\n * @note Worst-Time Complexity: O(1).\n * @note Worst-Space Complexity: O(1).\n * @return {size_t} Total amount of items.\n */\nsize_t GetItemsAmount() const {...}\n\n\n/**\n * Gets a set with a given item id.\n * @note Worst-Time Complexity: O(n).\n * @note Amortized-Time with Join O(log(n)) or O(log*(n)) [IF POLICY == U_OPTIMIZE || U_BOTH].\n * @note Worst-Space Complexity: O(|path|).\n * @param id - The id of the item that belongs to a set.\n * @return {UNION::UpNode\u003cDATA\u003e} Return the set node.\n */\nUNION::UpNode\u003cDATA\u003e FindSet(size_t id) {...}\n\n/**\n * Gets an item with a given item id.\n * @param id - The id of an item.\n * @return {UNION::UpNode\u003cDATA\u003e} Return the item node.\n */\nUNION::UpNode\u003cDATA\u003e GetItem(size_t id) const {...}\n\n/**\n * Joins two sets into one set while following the rule of join small set under big set.\n * @note If policy is set to U_U_SENSITIVE_ORDER || U_BOTH, it will save the given arguments order.\n * @note Worst-Time Complexity: O(1).\n * @note Worst-Space Complexity: O(1).\n * @param p - First set id.\n * @param q - Second set id.\n */\nvoid Join(size_t p, size_t q) {...}\n\n/**\n * Checks whether a set is exists.\n * @note Worst-Time Complexity: O(1).\n * @note Worst-Space Complexity: O(1).\n * @param set_id - An id of a known set.\n * @returns {bool} True if exits o.w False.\n */\nbool SetExists(size_t set_id) const {...}\n\n/**\n * Checks whether an item is exists.\n * @note Worst-Time Complexity: O(1).\n * @note Worst-Space Complexity: O(1).\n * @param item_id - An id of a known set.\n * @returns {bool} True if exits o.w False.\n */\nbool ItemExists(size_t item_id) const {...}\n\n/**\n * Removes an entire set and his members(items) from UF.\n * @note Worst-Time Complexity: O(|members|).\n * @note Worst-Space Complexity: O(1).\n * @param set_id - An id of a known set.\n */\nvoid RemoveSet(size_t set_id) {...}\n\n/**\n * Prints the entire data structure\n * @param os - std ostream.\n * @param uf - the union find data structure.\n * @return {std::ostream} Returns ostream for chaining.\n */\nfriend std::ostream \u0026operator\u003c\u003c(std::ostream \u0026os, const UnionFind\u003cDATA\u003e \u0026uf) {...}\n```\n\n## Author\n\n[Liav Barsheshet, LBDevelopments](https://github.com/liavbarsheshet)\n\n## License\n\n[MIT](LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fliavbarsheshet%2Funion-find","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fliavbarsheshet%2Funion-find","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fliavbarsheshet%2Funion-find/lists"}