{"id":18494844,"url":"https://github.com/gbrlsnchs/radix","last_synced_at":"2025-08-12T22:37:15.502Z","repository":{"id":57493179,"uuid":"113355415","full_name":"gbrlsnchs/radix","owner":"gbrlsnchs","description":"Golang radix tree implementation","archived":false,"fork":false,"pushed_at":"2019-03-11T13:47:49.000Z","size":61,"stargazers_count":35,"open_issues_count":3,"forks_count":5,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-08-11T07:00:14.591Z","etag":null,"topics":["go","golang","patricia-tree","patricia-trie","radix","radix-tree","trie"],"latest_commit_sha":null,"homepage":"","language":"Go","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/gbrlsnchs.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}},"created_at":"2017-12-06T18:55:40.000Z","updated_at":"2024-04-06T21:24:29.000Z","dependencies_parsed_at":"2022-08-28T13:40:11.716Z","dependency_job_id":null,"html_url":"https://github.com/gbrlsnchs/radix","commit_stats":null,"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"purl":"pkg:github/gbrlsnchs/radix","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gbrlsnchs%2Fradix","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gbrlsnchs%2Fradix/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gbrlsnchs%2Fradix/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gbrlsnchs%2Fradix/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gbrlsnchs","download_url":"https://codeload.github.com/gbrlsnchs/radix/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gbrlsnchs%2Fradix/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270148108,"owners_count":24535693,"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-08-12T02:00:09.011Z","response_time":80,"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":["go","golang","patricia-tree","patricia-trie","radix","radix-tree","trie"],"created_at":"2024-11-06T13:22:25.646Z","updated_at":"2025-08-12T22:37:15.439Z","avatar_url":"https://github.com/gbrlsnchs.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# radix (Radix tree implementation in Go)\n\n[![Build Status](https://travis-ci.org/gbrlsnchs/radix.svg?branch=master)](https://travis-ci.org/gbrlsnchs/radix)\n[![Sourcegraph](https://sourcegraph.com/github.com/gbrlsnchs/radix/-/badge.svg)](https://sourcegraph.com/github.com/gbrlsnchs/radix?badge)\n[![GoDoc](https://godoc.org/github.com/gbrlsnchs/radix?status.svg)](https://godoc.org/github.com/gbrlsnchs/radix)\n[![Minimal Version](https://img.shields.io/badge/minimal%20version-go1.10%2B-5272b4.svg)](https://golang.org/doc/go1.10)\n\n## About\nThis package is an implementation of a [radix tree](https://en.wikipedia.org/wiki/Radix_tree) in [Go](https://golang.org) (or Golang).  \n\nSearching for static values in the tree doesn't allocate memory on the heap, what makes it pretty fast.  \nIt can also sort nodes by priority, therefore traversing nodes that hold more non-nil values first.\n\n## Usage\nFull documentation [here](https://godoc.org/github.com/gbrlsnchs/radix).  \n\n### Installing\n#### Go 1.10\n`vgo get -u github.com/gbrlsnchs/radix`\n#### Go 1.11\n`go get -u github.com/gbrlsnchs/radix`\n\n### Importing\n```go\nimport (\n\t// ...\n\n\t\"github.com/gbrlsnchs/radix\"\n)\n```\n\n### Building [this example from Wikipedia](https://upload.wikimedia.org/wikipedia/commons/a/ae/Patricia_trie.svg)\n```go\ntr := radix.New(radix.Tdebug)\ntr.Add(\"romane\", 1)\ntr.Add(\"romanus\", 2)\ntr.Add(\"romulus\", 3)\ntr.Add(\"rubens\", 4)\ntr.Add(\"ruber\", 5)\ntr.Add(\"rubicon\", 6)\ntr.Add(\"rubicundus\", 7)\ntr.Sort(radix.PrioritySort) // optional step\nfmt.Println(tr)\n```\n\n#### The code above will print this\n```\n. (14 nodes)\n└── 7↑ r → \u003cnil\u003e\n    ├── 4↑ ub → \u003cnil\u003e\n    │   ├── 2↑ ic → \u003cnil\u003e\n    │   │   ├── 1↑ undus 🍂 → 7\n    │   │   └── 1↑ on 🍂 → 6\n    │   └── 2↑ e → \u003cnil\u003e\n    │       ├── 1↑ r 🍂 → 5\n    │       └── 1↑ ns 🍂 → 4\n    └── 3↑ om → \u003cnil\u003e\n        ├── 2↑ an → \u003cnil\u003e\n        │   ├── 1↑ us 🍂 → 2\n        │   └── 1↑ e 🍂 → 1\n        └── 1↑ ulus 🍂 → 3\n```\n\n### Retrieving a value from the tree\n```go\nn, _ := tr.Get(\"rubicon\") // zero-allocation search\nfmt.Println(n.Value)      // prints \"6\"\n```\n\n### Building a dynamic tree\nA dynamic tree is a tree that can match labels based on a placeholder and a demiliter (e.g. an HTTP router that accepts dynamic routes).  \nNote that this only works with prefix trees, not binary ones.\n\n```go\ntr := radix.New(0) // passing 0 means passing no flags\ntr.Add(\"/dynamic/path/@id\", 1)\ntr.Add(\"/dynamic/path/@id/subpath/@name\", 2)\ntr.Add(\"/static/path\", 3)\ntr.SetBoundaries('@', '/')\n\nvar (\n\tn *radix.Node\n\tp map[string]string\n)\nn, p = tr.Get(\"/dynamic/path/123\")\nfmt.Println(n.Value) // prints \"1\"\nfmt.Println(p[\"id\"]) // prints \"123\"\n\nn, p = tr.Get(\"/dynamic/path/456/subpath/foobar\")\nfmt.Println(n.Value)   // prints \"2\"\nfmt.Println(p[\"id\"])   // prints \"456\"\nfmt.Println(p[\"name\"]) // prints \"foobar\"\n\nn, _ = tr.Get(\"/static/path\") // p would be nil\nfmt.Println(n.Value)          // prints \"3\"\n```\n\n### Building a binary tree\n```go\ntr := radix.New(radix.Tdebug | radix.Tbinary)\ntr.Add(\"deck\", 1)\ntr.Add(\"did\", 2)\ntr.Add(\"doe\", 3)\ntr.Add(\"dog\", 4)\ntr.Add(\"doge\", 5)\ntr.Add(\"dogs\", 6)\n```\n\n#### The code above will print this\n```\n. (71 nodes)\n01100100011001010110001101101011 🍂 → 1\n011001000110100101100100 🍂 → 2\n011001000110111101100101 🍂 → 3\n011001000110111101100111 → 4\n01100100011011110110011101100101 🍂 → 5\n01100100011011110110011101110011 🍂 → 6\n```\n\n## Contributing\n### How to help\n- For bugs and opinions, please [open an issue](https://github.com/gbrlsnchs/radix/issues/new)\n- For pushing changes, please [open a pull request](https://github.com/gbrlsnchs/radix/compare)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgbrlsnchs%2Fradix","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgbrlsnchs%2Fradix","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgbrlsnchs%2Fradix/lists"}