{"id":32287836,"url":"https://github.com/mopriestt/red_black_tree_collection","last_synced_at":"2025-10-23T02:19:06.064Z","repository":{"id":201229373,"uuid":"693520818","full_name":"Mopriestt/red_black_tree_collection","owner":"Mopriestt","description":"This Dart library offers high performance Red-Black Tree based Set and Map data structures that provide ordered collections with efficient search, insertion, and deletion operations.","archived":false,"fork":false,"pushed_at":"2025-01-28T02:11:14.000Z","size":82,"stargazers_count":35,"open_issues_count":1,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-04T17:51:37.847Z","etag":null,"topics":["dart","data-structures","red-black-tree"],"latest_commit_sha":null,"homepage":"","language":"Dart","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Mopriestt.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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}},"created_at":"2023-09-19T07:36:13.000Z","updated_at":"2025-08-15T08:45:51.000Z","dependencies_parsed_at":null,"dependency_job_id":"8c1cff39-7d6b-461b-a4b1-d637d2744643","html_url":"https://github.com/Mopriestt/red_black_tree_collection","commit_stats":null,"previous_names":["mopriestt/red_black_tree_collection"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Mopriestt/red_black_tree_collection","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mopriestt%2Fred_black_tree_collection","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mopriestt%2Fred_black_tree_collection/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mopriestt%2Fred_black_tree_collection/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mopriestt%2Fred_black_tree_collection/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Mopriestt","download_url":"https://codeload.github.com/Mopriestt/red_black_tree_collection/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mopriestt%2Fred_black_tree_collection/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":280546869,"owners_count":26348810,"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","status":"online","status_checked_at":"2025-10-23T02:00:06.710Z","response_time":142,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["dart","data-structures","red-black-tree"],"created_at":"2025-10-23T02:19:02.108Z","updated_at":"2025-10-23T02:19:06.055Z","avatar_url":"https://github.com/Mopriestt.png","language":"Dart","funding_links":[],"categories":[],"sub_categories":[],"readme":"This Dart library offers high performance Red-Black Tree based Set and Map data structures that provide ordered collections with efficient search, insertion, and deletion operations.\n\n## Features\n\n**Adaptability**: Offers all standard Map and Set functionalities as defined in Dart's interface. Plug and Play!\n\n**Ordering**: The Red-Black Tree Set and Map maintain a balanced structure, ensuring that elements are ordered efficiently within the collection.\n\n**Performance**: Approximately 110% performance improvement compared to Dart's `SplayTreeMap` and `SplayTreeSet` in terms of search, insertion, and deletion.\n\n**Additional Functionality**: This library provides efficient implementation of binary searching on keys:\n - `firstAfter` and `lastBefore` on RBTreeSet.\n - `firstKeyAfter` and `lastKeyBefore` on RBTreeMap.\n\n**Test Coverage**: This library is well unit tested and integration tested.\n\n## Basic Usage\n\n### RBTreeMap\n\n```dart\n    final treeMap = RBTreeMap\u003cString, int\u003e(\n      // Example of custom comparator\n      // Use case insensitive string compare.\n          (a, b) =\u003e a.toLowerCase().compareTo(b.toLowerCase()),\n    );\n\n    // add\n    treeMap['john'] = 30;\n    treeMap['BoB'] = 20;\n    treeMap['Kevin'] = 31;\n    \n    // remove\n    print(treeMap['BoB']); // 20\n    treeMap.remove('BoB');\n    print(treeMap['BoB']); // null\n    \n    // add from other map\n    treeMap.addAll(const {'alice': 18, 'Charles': 70});\n    \n    // to pre-sorted list\n    print(treeMap.keys.toList()); // [alice, Charles, john, Kevin]\n    print(treeMap.values.toList()); // [18, 70, 30, 31]\n\n    // [MapEntry(alice: 18), MapEntry(Charles: 70), MapEntry(john: 30), MapEntry(Kevin: 31)]\n    print(treeMap.entrys.toList());\n    \n    // binary search key\n    print(treeMap.firstKeyAfter('Alice')); // 'Charles'\n    print(treeMap.lastKeyBefore('Nobody')); // 'Kevin'\n    \n    for (MapEntry\u003cString, int\u003e entry in treeMap.entries) {\n      // Iterate through all (key, value) pair in key sorted order.\n    }\n    \n    // Initialize from built in Map.\n    final newMap = RBTreeMap.of(\u003cString, String\u003e{'a' : 'A', 'b' : 'B'});\n```\n\n### RBTreeSet\n\n```dart\n    final treeSet = RBTreeSet\u003cint\u003e();\n    // alternative constructor\n    // final treeSet = RBTreeSet.from([10, 20, 30, 7, 1, 3, 5]);\n  \n    // add\n    treeSet.add(5);\n    treeSet.addAll([10, 20, 30, 7, 1, 3]);\n\n    // lookup\n    print(treeSet.contains(3)); // true\n    print(treeSet.contains(100)); // false;\n    print(treeSet.lookup(30)); // 30\n    print(treeSet.lookup(45.0)); // null\n\n    // binary search element\n    print(treeSet.firstAfter(15)); // 20\n    print(treeSet.lastBefore(10)); // 7\n\n    // remove\n    treeSet.removeAll([1, 7, 30]);\n\n    // to pre-sorted list\n    print(treeSet.toList()); // [3, 5, 10, 20]\n\n    for (int element in treeSet) {\n      // Iterate through all elements in sorted order.\n    }\n\n    // Initialize from built in Set.\n    final newSet = RBTreeSet.of(\u003cString\u003e{'a', 'b', 'c'});\n```\n\nFor advanced usage, please refer to API doc.\n\n## Performance Benchmarking\n\nBenchmarking is done with same data set doing same operations on `RBTreeSet` and `SplayTreeSet` separately.\n\nCode to reproduce the performance metrics can be found [here](https://github.com/Mopriestt/red_black_tree_collection/blob/master/test/benchmark.dart).\n\n#### Single Set Test\n\n| Test case                                         | SplayTreeSet | RBTreeSet | Improvement |\n|:--------------------------------------------------|:------------:|:---------:|:-----------:|\n| 1 million insert + 1 million find                 |    4324ms    |  2009ms   |   ~115.2%   |\n| 1 million insert + 2 million mixed remove/find    |    7215ms    |  3704ms   |   ~94.7%    |\n\n#### Multiple Set Test\n\n|                     Test case                      | SplayTreeSet | RBTreeSet | Improvement |\n|:--------------------------------------------------:|:------------:|:---------:|:-----------:|\n| 1000 individual sets with 5k insert + 5k find each |    3756ms    |  2039ms   |   ~84.2%    |\n\n## Misc\n\n### [Source Code](https://github.com/Mopriestt/red_black_tree_collection/tree/master/lib) and [pub.dev Link](https://pub.dev/packages/red_black_tree_collection)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmopriestt%2Fred_black_tree_collection","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmopriestt%2Fred_black_tree_collection","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmopriestt%2Fred_black_tree_collection/lists"}