{"id":13411686,"url":"https://github.com/plar/go-adaptive-radix-tree","last_synced_at":"2025-05-14T23:06:16.595Z","repository":{"id":43557787,"uuid":"55195161","full_name":"plar/go-adaptive-radix-tree","owner":"plar","description":"Adaptive Radix Trees implemented in Go","archived":false,"fork":false,"pushed_at":"2024-12-16T22:23:27.000Z","size":2989,"stargazers_count":387,"open_issues_count":0,"forks_count":57,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-05-10T11:27:24.311Z","etag":null,"topics":["go","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/plar.png","metadata":{"files":{"readme":"README.md","changelog":null,"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-04-01T01:40:40.000Z","updated_at":"2025-05-07T20:55:52.000Z","dependencies_parsed_at":"2024-06-18T12:35:55.184Z","dependency_job_id":"5c5a208f-ab61-4b3c-8182-f47edcb8112a","html_url":"https://github.com/plar/go-adaptive-radix-tree","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/plar%2Fgo-adaptive-radix-tree","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/plar%2Fgo-adaptive-radix-tree/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/plar%2Fgo-adaptive-radix-tree/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/plar%2Fgo-adaptive-radix-tree/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/plar","download_url":"https://codeload.github.com/plar/go-adaptive-radix-tree/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254243360,"owners_count":22038046,"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":["go","trie"],"created_at":"2024-07-30T20:01:15.779Z","updated_at":"2025-05-14T23:06:11.564Z","avatar_url":"https://github.com/plar.png","language":"Go","funding_links":[],"categories":["数据结构与算法","Data Structures","Data Structures and Algorithms","数据结构","Generators","Uncategorized","Data Integration Frameworks","Go","\u003cspan id=\"数据结构-data-structures\"\u003e数据结构 Data Structures\u003c/span\u003e","数据结构`go语言实现的数据结构与算法`"],"sub_categories":["文本分析","Advanced Console UIs","Standard CLI","Text Analysis","标准 CLI","\u003cspan id=\"高级控制台用户界面-advanced-console-uis\"\u003e高级控制台用户界面 Advanced Console UIs\u003c/span\u003e"],"readme":"An Adaptive Radix Tree Implementation in Go\n====\n\n[![Coverage Status](https://coveralls.io/repos/github/plar/go-adaptive-radix-tree/badge.svg?branch=master\u0026v=1)](https://coveralls.io/github/plar/go-adaptive-radix-tree?branch=master) [![Go Report Card](https://goreportcard.com/badge/github.com/plar/go-adaptive-radix-tree)](https://goreportcard.com/report/github.com/plar/go-adaptive-radix-tree) [![GoDoc](https://godoc.org/github.com/plar/go-adaptive-radix-tree?status.svg)](https://pkg.go.dev/github.com/plar/go-adaptive-radix-tree/v2)\n\nThis library provides a Go implementation of the Adaptive Radix Tree (ART).\n\nFeatures:\n* Lookup performance surpasses highly tuned alternatives\n* Support for highly efficient insertions and deletions\n* Space efficient\n* Performance is comparable to hash tables\n* Maintains the data in sorted order, which enables additional operations like range scan and prefix lookup\n\t\u003e Keys are sorted **lexicographically** based on their byte values.\n* `O(k)` search/insert/delete operations, where `k` is the length of the key\n* Minimum / Maximum value lookups\n* Ordered iteration\n* Prefix-based iteration\n* Reverse iteration support\n* Support for keys with null bytes, any byte array could be a key\n\n# Usage\n\n[The Go playground](https://go.dev/play/p/tBJa0d50eOp)\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\tart \"github.com/plar/go-adaptive-radix-tree/v2\"\n)\n\nfunc main() {\n\t// Initialize a new Adaptive Radix Tree\n\ttree := art.New()\n\n\t// Insert key-value pairs into the tree\n\ttree.Insert(art.Key(\"apple\"), \"A sweet red fruit\")\n\ttree.Insert(art.Key(\"banana\"), \"A long yellow fruit\")\n\ttree.Insert(art.Key(\"cherry\"), \"A small red fruit\")\n\ttree.Insert(art.Key(\"date\"), \"A sweet brown fruit\")\n\n\t// Search for a value by key\n\tif value, found := tree.Search(art.Key(\"banana\")); found {\n\t\tfmt.Println(\"Found:\", value)\n\t} else {\n\t\tfmt.Println(\"Key not found\")\n\t}\n\n\t// Iterate over the tree in ascending order\n\tfmt.Println(\"\\nAscending order iteration:\")\n\ttree.ForEach(func(node art.Node) bool {\n\t\tfmt.Printf(\"Key: %s, Value: %s\\n\", node.Key(), node.Value())\n\t\treturn true\n\t})\n\n\t// Iterate over the tree in descending order using reverse traversal\n\tfmt.Println(\"\\nDescending order iteration:\")\n\ttree.ForEach(func(node art.Node) bool {\n\t\tfmt.Printf(\"Key: %s, Value: %s\\n\", node.Key(), node.Value())\n\t\treturn true\n\t}, art.TraverseReverse)\n\n\t// Iterate over keys with a specific prefix\n\tfmt.Println(\"\\nIteration with prefix 'c':\")\n\ttree.ForEachPrefix(art.Key(\"c\"), func(node art.Node) bool {\n\t\tfmt.Printf(\"Key: %s, Value: %s\\n\", node.Key(), node.Value())\n\t\treturn true\n\t})\n}\n\n// Expected Output:\n// Found: A long yellow fruit\n//\n// Ascending order iteration:\n// Key: apple, Value: A sweet red fruit\n// Key: banana, Value: A long yellow fruit\n// Key: cherry, Value: A small red fruit\n// Key: date, Value: A sweet brown fruit\n//\n// Descending order iteration:\n// Key: date, Value: A sweet brown fruit\n// Key: cherry, Value: A small red fruit\n// Key: banana, Value: A long yellow fruit\n// Key: apple, Value: A sweet red fruit\n//\n// Iteration with prefix 'c':\n// Key: cherry, Value: A small red fruit\n```\n\n# Documentation\n\nCheck out the documentation on [pkg.go.dev/github.com/plar/go-adaptive-radix-tree/v2](https://pkg.go.dev/github.com/plar/go-adaptive-radix-tree/v2).\n\n# Migration from v1 to v2\n\n- update `import` statement\n\n``` \nfrom `art \"github.com/plar/go-adaptive-radix-tree\"`\n  to `art \"github.com/plar/go-adaptive-radix-tree/v2\"`\n```\n\n- update go module dependency\n\n```\n$ go get github.com/plar/go-adaptive-radix-tree/v2\n$ go mod tidy\n```\n\nIf you had implemented your own version of the `Tree` interface, then you need to update the following method to support `options`. These are the only changes in the interface.\n\n```\n\tForEachPrefix(keyPrefix Key, callback Callback, options ...int)\n```\n\n# Performance\n\n[plar/go-adaptive-radix-tree](https://github.com/plar/go-adaptive-radix-tree) outperforms [kellydunn/go-art](https://github.com/kellydunn/go-art) by avoiding memory allocations during search operations.\nIt also provides prefix based and reverse iteration over the tree.\n\nBenchmarks were performed on datasets extracted from different projects:\n- The \"Words\" dataset contains a list of 235,886 english words. [2]\n- The \"UUIDs\" dataset contains 100,000 uuids.                   [2]\n- The \"HSK Words\" dataset contains 4,995 words.                 [4]\n\n|**go-adaptive-radix-tree**| #  | Average time      |Bytes per operation|Allocs per operation |\n|:-------------------------|---:|------------------:|------------------:|--------------------:|\n|       Tree Insert Words  |  9 | 117,888,698 ns/op |  37,942,744  B/op | 1,214,541 allocs/op |\n|       Tree Search Words  | 26 |  44,555,608 ns/op |            0 B/op |         0 allocs/op |\n|       Tree Insert UUIDs  | 18 |  59,360,135 ns/op |   18,375,723 B/op |   485,057 allocs/op |\n|       Tree Search UUIDs  | 54 |  21,265,931 ns/op |            0 B/op |         0 allocs/op |\n|**go-art**                |    |                   |                   |                     |\n|       Tree Insert Words  |  5 | 272,047,975 ns/op |   81,628,987 B/op | 2,547,316 allocs/op |\n|       Tree Search Words  | 10 | 129,011,177 ns/op |   13,272,278 B/op | 1,659,033 allocs/op |\n|       Tree Insert UUIDs  | 10 | 140,309,246 ns/op |   33,678,160 B/op |   874,561 allocs/op |\n|       Tree Search UUIDs  | 20 |  82,120,943 ns/op |    3,883,131 B/op |   485,391 allocs/op |\n\nTo see more benchmarks just run\n\n```\n$ ./make qa/benchmarks\n```\n\n# References\n\n[1] [The Adaptive Radix Tree: ARTful Indexing for Main-Memory Databases (Specification)](http://www-db.in.tum.de/~leis/papers/ART.pdf)\n\n[2] [C99 implementation of the Adaptive Radix Tree](https://github.com/armon/libart)\n\n[3] [Another Adaptive Radix Tree implementation in Go](https://github.com/kellydunn/go-art)\n\n[4] [HSK Words](http://hskhsk.pythonanywhere.com/hskwords). HSK(Hanyu Shuiping Kaoshi) - Standardized test of Standard Mandarin Chinese proficiency.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fplar%2Fgo-adaptive-radix-tree","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fplar%2Fgo-adaptive-radix-tree","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fplar%2Fgo-adaptive-radix-tree/lists"}