{"id":16920684,"url":"https://github.com/arriqaaq/art","last_synced_at":"2025-07-12T23:32:19.536Z","repository":{"id":38027116,"uuid":"469076167","full_name":"arriqaaq/art","owner":"arriqaaq","description":"An Adaptive Radix Tree (ART) implementation in Go","archived":false,"fork":false,"pushed_at":"2023-11-03T19:23:36.000Z","size":2826,"stargazers_count":81,"open_issues_count":0,"forks_count":10,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-02T04:54:03.502Z","etag":null,"topics":["adaptive-radix-tree","data-structures","go","golang","radix-tree"],"latest_commit_sha":null,"homepage":"https://aly.arriqaaq.com/art-building-a-prefix-search-trie-in-go/","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/arriqaaq.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":"2022-03-12T12:27:42.000Z","updated_at":"2025-03-09T08:35:21.000Z","dependencies_parsed_at":"2023-01-25T17:46:50.010Z","dependency_job_id":"1b191601-0ea4-4969-9550-25cf1930bec8","html_url":"https://github.com/arriqaaq/art","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/arriqaaq/art","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arriqaaq%2Fart","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arriqaaq%2Fart/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arriqaaq%2Fart/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arriqaaq%2Fart/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/arriqaaq","download_url":"https://codeload.github.com/arriqaaq/art/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arriqaaq%2Fart/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265067495,"owners_count":23706288,"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":["adaptive-radix-tree","data-structures","go","golang","radix-tree"],"created_at":"2024-10-13T19:49:09.447Z","updated_at":"2025-07-12T23:32:19.520Z","avatar_url":"https://github.com/arriqaaq.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"art\n====\nA simple implementation of Adaptive Radix Tree (ART) in Go. Created for use in personal projects like [FlashDB](https://github.com/arriqaaq/flashdb).\n\nAbout\n=====\n- An adaptive radix tree (trie) is useful for efficient indexing in main memory. \n- Its lookup performance surpasses highly tuned, read-only search trees, while supporting very efficient insertions and deletions as well. \n- Space efficient and solves the problem of excessive worst-case space consumption, which plagues most radix trees, by adaptively choosing compact and efficient data structures for internal nodes. \n- Maintains the data in sorted order, which enables additional operations like range scan and prefix lookup.\n\n\n# Usage\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\n\t\"github.com/arriqaaq/art\"\n)\n\nfunc main() {\n\ttree := art.NewTree()\n\n\t// Insert\n\ttree.Insert([]byte(\"hello\"), \"world\")\n\tvalue := tree.Search([]byte(\"hello\"))\n\tfmt.Println(\"value=\", value)\n\n\t// Delete\n\ttree.Insert([]byte(\"wonderful\"), \"life\")\n\ttree.Insert([]byte(\"foo\"), \"bar\")\n\tdeleted := tree.Delete([]byte(\"foo\"))\n\tfmt.Println(\"deleted=\", deleted)\n\n\t// Search\n\tvalue = tree.Search([]byte(\"hello\"))\n\tfmt.Println(\"value=\", value)\n\n\t// Traverse (with callback function)\n\ttree.Each(func(node *art.Node) {\n\t\tif node.IsLeaf() {\n\t\t\tfmt.Println(\"value=\", node.Value())\n\t\t}\n\t})\n\n\t// Iterator\n\tfor it := tree.Iterator(); it.HasNext(); {\n\t\tvalue := it.Next()\n\t\tif value.IsLeaf() {\n\t\t\tfmt.Println(\"value=\", value.Value())\n\t\t}\n\t}\n\n\t// Prefix Scan\n\ttree.Insert([]byte(\"api\"), \"bar\")\n\ttree.Insert([]byte(\"api.com\"), \"bar\")\n\ttree.Insert([]byte(\"api.com.xyz\"), \"bar\")\n\tleafFilter := func(n *art.Node) {\n\t\tif n.IsLeaf() {\n\t\t\tfmt.Println(\"value=\", string(n.Key()))\n\t\t}\n\t}\n\ttree.Scan([]byte(\"api\"), leafFilter)\n}\n```\n\n# Benchmarks\n\nBenchmarks are run by inserting a dictionary of 235886 words into each tree.\n\n```go\ngoos: darwin\ngoarch: amd64\npkg: github.com/arriqaaq/art\ncpu: Intel(R) Core(TM) i9-9980HK CPU @ 2.40GHz\n\n// ART tree\nBenchmarkWordsArtTreeInsert\nBenchmarkWordsArtTreeInsert-16   14\t  79622476 ns/op  46379858 B/op\t 1604123 allocs/op\nBenchmarkWordsArtTreeSearch\nBenchmarkWordsArtTreeSearch-16   43\t  28123512 ns/op         0 B/op\t       0 allocs/op\nBenchmarkUUIDsArtTreeInsert\nBenchmarkUUIDsArtTreeInsert-16   20\t  56691374 ns/op  20404504 B/op\t  602400 allocs/op\nBenchmarkUUIDsArtTreeSearch\nBenchmarkUUIDsArtTreeSearch-16   34\t  32183846 ns/op         0 B/op\t       0 allocs/op\n\n// Radix tree\nBenchmarkWordsRadixInsert\nBenchmarkWordsRadixInsert-16     12\t  96886770 ns/op  50057340 B/op\t 1856741 allocs/op\nBenchmarkWordsRadixSearch\nBenchmarkWordsRadixSearch-16     33\t  40109553 ns/op         0 B/op\t       0 allocs/op\n\n// Skiplist\nBenchmarkWordsSkiplistInsert\nBenchmarkWordsSkiplistInsert-16   4\t 271771239 ns/op  32366958 B/op\t 1494019 allocs/op\nBenchmarkWordsSkiplistSearch\nBenchmarkWordsSkiplistSearch-16   8\t 135836216 ns/op         0 B/op\t       0 allocs/op\n```\n\n# References\n\n- [The Adaptive Radix Tree: ARTful Indexing for Main-Memory Databases (Specification)](http://www-db.in.tum.de/~leis/papers/ART.pdf)\n- [Kelly Dunn implementation of the Adaptive Radix Tree](https://github.com/kellydunn/go-art)\n- [Beating hash tables with trees? The ART-ful radix trie](https://www.the-paper-trail.org/post/art-paper-notes/)\n- [Pavel Larkin implementation of ART](https://github.com/plar/go-adaptive-radix-tree)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farriqaaq%2Fart","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Farriqaaq%2Fart","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farriqaaq%2Fart/lists"}