{"id":13482316,"url":"https://github.com/luislavena/radix","last_synced_at":"2026-03-03T03:06:18.179Z","repository":{"id":53578138,"uuid":"50311237","full_name":"luislavena/radix","owner":"luislavena","description":"Radix Tree implementation for Crystal","archived":false,"fork":false,"pushed_at":"2024-06-02T15:21:52.000Z","size":96,"stargazers_count":103,"open_issues_count":3,"forks_count":14,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-03-24T17:51:55.134Z","etag":null,"topics":["crystal","radix-tree"],"latest_commit_sha":null,"homepage":null,"language":"Crystal","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/luislavena.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,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-01-24T22:22:32.000Z","updated_at":"2025-02-16T14:51:05.000Z","dependencies_parsed_at":"2024-10-26T21:17:18.543Z","dependency_job_id":"4244b58a-187d-436c-9d95-b0741fbe22f9","html_url":"https://github.com/luislavena/radix","commit_stats":null,"previous_names":[],"tags_count":17,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luislavena%2Fradix","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luislavena%2Fradix/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luislavena%2Fradix/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luislavena%2Fradix/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/luislavena","download_url":"https://codeload.github.com/luislavena/radix/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248287958,"owners_count":21078816,"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":["crystal","radix-tree"],"created_at":"2024-07-31T17:01:00.820Z","updated_at":"2026-03-03T03:06:13.158Z","avatar_url":"https://github.com/luislavena.png","language":"Crystal","funding_links":[],"categories":["Algorithms and Data structures"],"sub_categories":[],"readme":"# Radix Tree\n\n[Radix tree](https://en.wikipedia.org/wiki/Radix_tree) implementation for\nCrystal language\n\n[![CI](https://github.com/luislavena/radix/workflows/CI/badge.svg)](https://github.com/luislavena/radix/actions)\n[![Latest Release](https://img.shields.io/github/release/luislavena/radix.svg)](https://github.com/luislavena/radix/releases)\n\n## Installation\n\nAdd this to your application's `shard.yml`:\n\n```yaml\ndependencies:\n  radix:\n    github: luislavena/radix\n```\n\n## Usage\n\n### Building Trees\n\nYou can associate a *payload* with each path added to the tree:\n\n```crystal\nrequire \"radix\"\n\ntree = Radix::Tree(Symbol).new\ntree.add \"/products\", :products\ntree.add \"/products/featured\", :featured\n\nresult = tree.find \"/products/featured\"\n\nif result.found?\n  puts result.payload # =\u003e :featured\nend\n```\n\nThe types allowed for payload are defined on Tree definition:\n\n```crystal\ntree = Radix::Tree(Symbol).new\n\n# Good, since Symbol is allowed as payload\ntree.add \"/\", :root\n\n# Compilation error, Int32 is not allowed\ntree.add \"/meaning-of-life\", 42\n```\n\nCan combine multiple types if needed:\n\n```crystal\ntree = Radix::Tree(Int32 | String | Symbol).new\n\ntree.add \"/\", :root\ntree.add \"/meaning-of-life\", 42\ntree.add \"/hello\", \"world\"\n```\n\n### Lookup and placeholders\n\nYou can also extract values from placeholders (as named segments or globbing):\n\n```crystal\ntree.add \"/products/:id\", :product\n\nresult = tree.find \"/products/1234\"\n\nif result.found?\n  puts result.params[\"id\"]? # =\u003e \"1234\"\nend\n```\n\nPlease see `Radix::Tree#add` documentation for more usage examples.\n\n## Caveats\n\nPretty much all Radix implementations have their limitations and this project\nis no exception.\n\nWhen designing and adding *paths* to a Tree, please consider that two different\nnamed parameters cannot share the same level:\n\n```crystal\ntree.add \"/\", :root\ntree.add \"/:post\", :post\ntree.add \"/:category/:post\", :category_post # =\u003e Radix::Tree::SharedKeyError\n```\n\nThis is because different named parameters at the same level will result in\nincorrect `params` when lookup is performed, and sometimes the value for\n`post` or `category` parameters will not be stored as expected.\n\nTo avoid this issue, usage of explicit keys that differentiate each path is\nrecommended.\n\nFor example, following a good SEO practice will be consider `/:post` as\nabsolute permalink for the post and have a list of categories which links to\nthe permalinks of the posts under that category:\n\n```crystal\ntree.add \"/\", :root\ntree.add \"/:post\", :post                    # this is post permalink\ntree.add \"/categories\", :categories         # list of categories\ntree.add \"/categories/:category\", :category # listing of posts under each category\n```\n\n## Implementation\n\nThis project has been inspired and adapted from\n[julienschmidt/httprouter](https://github.com/julienschmidt/httprouter) and\n[spriet2000/vertx-http-router](https://github.com/spriet2000/vertx-http-router)\nGo and Java implementations, respectively.\n\nChanges to logic and optimizations have been made to take advantage of\nCrystal's features.\n\n## Contributing\n\n1. Fork it ( https://github.com/luislavena/radix/fork )\n2. Create your feature branch (`git checkout -b my-new-feature`)\n3. Commit your changes (`git commit -am 'Add some feature'`)\n4. Push to the branch (`git push origin my-new-feature`)\n5. Create a new Pull Request\n\n## Contributors\n\n- [Luis Lavena](https://github.com/luislavena) - creator, maintainer\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fluislavena%2Fradix","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fluislavena%2Fradix","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fluislavena%2Fradix/lists"}