{"id":23037431,"url":"https://github.com/tinloaf/ygg","last_synced_at":"2025-08-14T18:31:57.983Z","repository":{"id":52014194,"uuid":"97053226","full_name":"tinloaf/ygg","owner":"tinloaf","description":"An intrusive C++17 implementation of a Red-Black-Tree, a Weight Balanced Tree, a Dynamic Segment Tree and much more!","archived":false,"fork":false,"pushed_at":"2023-06-05T14:06:29.000Z","size":1759,"stargazers_count":123,"open_issues_count":3,"forks_count":19,"subscribers_count":13,"default_branch":"master","last_synced_at":"2024-12-08T20:16:59.519Z","etag":null,"topics":["cpp14","data-structure","interval-map","interval-set","interval-tree","red-black-tree","search-trees","segment-tree","weight-balanced-tree","zip-tree"],"latest_commit_sha":null,"homepage":"https://tinloaf.github.io/ygg/","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/tinloaf.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-07-12T21:24:50.000Z","updated_at":"2024-11-04T22:45:55.000Z","dependencies_parsed_at":"2022-08-19T21:50:56.981Z","dependency_job_id":null,"html_url":"https://github.com/tinloaf/ygg","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tinloaf%2Fygg","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tinloaf%2Fygg/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tinloaf%2Fygg/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tinloaf%2Fygg/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tinloaf","download_url":"https://codeload.github.com/tinloaf/ygg/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":229853743,"owners_count":18134661,"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":["cpp14","data-structure","interval-map","interval-set","interval-tree","red-black-tree","search-trees","segment-tree","weight-balanced-tree","zip-tree"],"created_at":"2024-12-15T17:34:44.341Z","updated_at":"2024-12-15T17:34:44.893Z","avatar_url":"https://github.com/tinloaf.png","language":"C++","funding_links":[],"categories":["C++"],"sub_categories":[],"readme":"[![Build Status](https://travis-ci.org/tinloaf/ygg.svg?branch=master)](https://travis-ci.org/tinloaf/ygg) [![Coverage Status](https://coveralls.io/repos/github/tinloaf/ygg/badge.svg?branch=master)](https://coveralls.io/github/tinloaf/ygg?branch=master)\n\nThis is Ygg (short for [Yggdrasil](https://en.wikipedia.org/wiki/Yggdrasil)), a C++17\nimplementation of several intrusive data structures:\n\n* several balanced binary search trees:\n  * a red-black Tree\n  * a Zip Tree\n  * a weight balanced tree (aka BB[α]-tree)\n* an Interval Tree\n* a Doubly-Linked List\n* a Dynamic Segment Tree (which is something between a segment tree and an interval map)\n  * ... based on a Red-Black Tree\n  * ... based on a Zip Tree\n\nIf you need a Red-Black-Tree, a Zip Tree, a Segment Tree or an Interval Tree in your C++\napplication, and for some reason the existing implementations (like std::set or\nboost::instrusive::rbtree) are not suited for you, Ygg may be the answer. Also, I do not know of any\nother implementation of the \"Dynamic Segment Tree\" (if you know something similar, please let me\nknow!)\n\nSee the list of features below for why Ygg is awesome!\n\nIf you're not sure whether one of these data structures is the right data structure for your \napplication, check out the [datastructure overview](https://tinloaf.github.io/ygg/datastructuresoverview.html) in the [Documentation](https://tinloaf.github.io/ygg/).\n\n**Warning**: This is still in development. Therefore, things could break. Also, the API\nmight change. If you found an example where one of the data structures does not behave as \nexpected, please let me know.\n\nFeatures\n========\n\n* It's intrusive! Like the containers in boost::intrusive, Ygg follows a 'bring your own data structure' approach. Depending on your use case, this can save a lot of time by avoiding memory allocation and copying stuff around.\n* You can be notified when stuff happens. Want to do something to the tree nodes every time a tree rotation happens? Need to know whenever two nodes swap places in the tree? Look no further. Ygg will call methods specified by you on several occasions. In fact, that's how the Interval Tree (the augmented tree version from Cormen et al.) is implemented.\n* It's pretty fast. Doing benchmarks correctly is pretty difficult. However, performance should not be too far away from boost::intrusive::rbtree. Comparing against std::set is unfair - std::set loses because it needs to do memory allocation.\n\nInstallation\n============\n\nIt's a header-only library. (Yes I know, there are .cpp files. I like to keep declaration and definition separated, even if everything's actually a header.) Just make sure everything in the src folder is in your include path, and you're set.\n\nNote that Ygg relies heavily on C++17 features. Thus, your compiler must fully support C++17 and must be set to compile using the C++17 standard. I currently test compilation with GCC 7.0, Clang 7 and XCode 11, so those should be fine.\n\nDocumentation\n=============\n\nThere's a short usage example below which is probably enough if you just want to use the \nRed-Black-Tree. \n\nThe [Documentation](https://tinloaf.github.io/ygg/) contains an overview over how the different \ndatastructures behave as well as more in-depth examples as well as an API documentation.\n\nUsage Example\n=============\n\nThis creates a Node class for you (which just holds an int-to-std::string mapping, pretty boring) and sets up an Red-Black-Tree on top of it:\n\n```cpp\n#include \"ygg.hpp\"\n\nusing namespace ygg;\n\n// The tree options\nusing MyTreeOptions = TreeOptions\u003cTreeFlags::MULTIPLE\u003e;\n\n// The node class\nclass Node : public RBTreeNodeBase\u003cNode, MyTreeOptions\u003e {\npublic:\n  int key;\n  std::string value;\n\n  // need to implement this s.t. we can use the default std::less as comparator\n  bool operator\u003c(const Node \u0026 other) const {\n    return this-\u003ekey \u003c other.key;\n  }\n}\n\n// Configure the RBTree based on Node and the default NodeTraits\nusing MyTree = RBTree\u003cNode, RBDefaultNodeTraits, MyTreeOptions\u003e;\n```\n\nNow, let's add some elements, iterate and query:\n\n```cpp\n// We need this s.t. we can query by key value (i.e, an int) directly\nbool operator\u003c(const Node \u0026 lhs, int rhs) {\n  return lhs.key \u003c rhs;\n}\nbool operator\u003c(int lhs, const Node \u0026 rhs) {\n  return lhs \u003c rhs.key;\n}\n\nint main(int argc, char **argv) {\n  MyTree t;\n\n  // Storage for the actual nodes.\n  // WARNING: using STL containers here can backfire badly. See documentation for details.\n  Node nodes[5];\n\n  // Initialize the nodes with some values\n  for (size_t i = 0 ; i \u003c 5 ; ++i) {\n    nodes[i].key = i;\n    nodes[i].value = std::string(\"The key is \") + std::to_string(i);\n  }\n\n  // Insert them\n  for (size_t i = 0 ; i \u003c 5 ; ++i) {\n    t.insert(nodes[i]);\n  }\n\n  // What was the string for i = 3 again?\n  auto it = t.find(3); // Note we're using a int to query here, not a Node\n  assert(it != t.end());\n  std::string retrieved_value = it-\u003evalue; // *it is the Node\n\n  // Okay, we don't need that Node anymore.\n  t.remove(*it);\n\n  // Iterate all the nodes!\n  for (const auto \u0026 n : t) {\n    std::cout \u003c\u003c \"A node: \" \u003c\u003c n.value \u003c\u003c \"\\n\";\n  }\n}\n```\n\nLicense\n=======\n\nThis software is licensed under the MIT license. See LICENSE.txt for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftinloaf%2Fygg","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftinloaf%2Fygg","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftinloaf%2Fygg/lists"}