{"id":29626325,"url":"https://github.com/stackmystack/rougenoir","last_synced_at":"2026-07-13T14:32:03.306Z","repository":{"id":304373014,"uuid":"1018597727","full_name":"stackmystack/rougenoir","owner":"stackmystack","description":"A red-black tree and set with callbacks","archived":false,"fork":false,"pushed_at":"2025-11-16T10:56:12.000Z","size":224,"stargazers_count":22,"open_issues_count":0,"forks_count":3,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-11-16T12:12:09.176Z","etag":null,"topics":["red-black","red-black-binary-tree","red-black-tree","red-black-trees","set","tree"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/stackmystack.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"docs/contributing.md","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,"zenodo":null,"notice":null,"maintainers":null,"copyright":"COPYRIGHT","agents":null,"dco":null,"cla":null}},"created_at":"2025-07-12T15:55:12.000Z","updated_at":"2025-11-16T10:56:15.000Z","dependencies_parsed_at":"2025-09-09T19:37:00.463Z","dependency_job_id":"4f8493ac-a4cd-4abe-a910-5d047432a524","html_url":"https://github.com/stackmystack/rougenoir","commit_stats":null,"previous_names":["stackmystack/rougenoir"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/stackmystack/rougenoir","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stackmystack%2Frougenoir","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stackmystack%2Frougenoir/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stackmystack%2Frougenoir/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stackmystack%2Frougenoir/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stackmystack","download_url":"https://codeload.github.com/stackmystack/rougenoir/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stackmystack%2Frougenoir/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":35426085,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-07-13T02:00:06.543Z","response_time":119,"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":["red-black","red-black-binary-tree","red-black-tree","red-black-trees","set","tree"],"created_at":"2025-07-21T07:05:49.308Z","updated_at":"2026-07-13T14:32:03.286Z","avatar_url":"https://github.com/stackmystack.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# rougenoir\n\n[![Crates.io](https://img.shields.io/crates/v/rougenoir.svg)](https://crates.io/crates/rougenoir)\n[![Documentation](https://docs.rs/rougenoir/badge.svg)](https://docs.rs/rougenoir)\n[![CI](https://github.com/stackmystack/rougenoir/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/stackmystack/rougenoir/actions/workflows/ci.yml)\n[![License: GPL v2](https://img.shields.io/badge/License-GPL_v2-blue.svg)](https://www.gnu.org/licenses/old-licenses/gpl-2.0.en.html)\n\nA Rust clone of linux' red-black trees.\n\nThe name of this library is French for redblack.\n\n## Motivation\n\nI wanted a red-black tree with callbacks and I couldn't find any I could hack to\nmy needs. I eventually stumbled upon the linux kernel's implementation and I\nthought it would be an opportunity to play with `unsafe` rust … and so I did.\n\n## Features\n\n- Collections with an API close to that of [`std::collections`](https://doc.rust-lang.org/std/collections).\n  - [`CachedTree`](https://docs.rs/rougenoir/latest/rougenoir/struct.CachedTree.html), a `Tree` where the leftmost entry is cached.\n  - [`Set`](https://docs.rs/rougenoir/latest/rougenoir/struct.Set.html).\n  - [`Tree`](https://docs.rs/rougenoir/latest/rougenoir/struct.Tree.html).\n- Low-level API to build your own trees.\n  - All the algorithms and data structures implemented exactly like the linux' version, but it's not an intrusive data-structure.\n  - Notification on tree modification, aka [Augmentation](#augmentation).\n  - See the [`IntervalTree` example](examples/interval_tree.rs).\n- Checked with [`miri`](https://github.com/rust-lang/miri).\n\n## Usage\n\nAdd this to your `Cargo.toml`:\n\n```toml\n[dependencies]\nrougenoir = \"0.1.0\"\n```\n\n### Example\n\n```rust\nuse rougenoir::Tree;\n\nfn main() {\n    let mut tree = Tree::new();\n\n    tree.insert(1, \"one\".to_string());\n    tree.insert(2, \"two\".to_string());\n    tree.insert(3, \"three\".to_string());\n\n    if let Some(value) = tree.get(\u00262) {\n        println!(\"Found: {}\", value);\n    }\n\n    for (key, value) in tree.iter() {\n        println!(\"{}: {}\", key, value);\n    }\n\n    tree.remove(\u00261);\n}\n```\n\n## Augmentation\n\n`rougenoir` supports tree augmentation, allowing you to maintain additional information about subtrees.\n\n```rust\nstruct SizeAugmentation\u003cK, V\u003e {\n    _phantom: std::marker::PhantomData\u003c(K, V)\u003e,\n}\n\nimpl\u003cK, V\u003e TreeCallbacks for SizeAugmentation\u003cK, V\u003e {\n    type Key = K;\n    type Value = V;\n\n    fn propagate(\u0026self, node: Option\u003c\u0026mut Node\u003cK, V\u003e\u003e, stop: Option\u003c\u0026mut Node\u003cK, V\u003e\u003e) {\n        // Listen to a propagation event.\n    }\n\n    fn copy(\u0026self, old: \u0026mut Node\u003cK, V\u003e, new: \u0026mut Node\u003cK, V\u003e) {\n        // Listen to a copy event.\n    }\n\n    fn rotate(\u0026self, old: \u0026mut Node\u003cK, V\u003e, new: \u0026mut Node\u003cK, V\u003e) {\n        // Listen to a rotate event.\n    }\n}\n```\n\n## Benchmarks\n\nYou can run the benchmarks with `just bench` or `cargo bench` and check on your local machine.\n\nI ran them on an old Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz and on an M1 Max,\nand in both cases I noticed that rougenoir can outperform\n[`std::collections::BTreeMap`](https://doc.rust-lang.org/std/collections/struct.BTreeMap.html)\nfor small trees (~ \u003c 4k), but it's a microbenchmark so take it with a kilo of\nsalt.\n\nI think that this can be significantly and reliably improved once a custom\nallocator can be used.\n\n## Nice to Have\n\n- Custom allocator.\n  - Currently it's leaking boxes.\n  - I'm thinking of [`hashbrown`](https://github.com/rust-lang/hashbrown).\n  - And of course benchmarks would make more sense.\n- Concurrency.\n  - AFAICT the kernel's implementation allows for lock-free concurrency.\n  - I'm not a linux expert, so I might be wrong.\n  - If it's the case, then adding barriers here might do it?\n- Intrusive rewrite.\n  - I don't want to dismiss the idea, and patches are welcome, but it's not my priority. I'm already satisfied with this implementation.\n\nSee [TODO.md](docs/TODO.md).\n\n## Contributing\n\nSee [docs/Contributing.md](docs/contributing.md).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstackmystack%2Frougenoir","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstackmystack%2Frougenoir","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstackmystack%2Frougenoir/lists"}