{"id":13571160,"url":"https://github.com/hashicorp/go-immutable-radix","last_synced_at":"2025-05-10T03:36:59.179Z","repository":{"id":33047100,"uuid":"36683065","full_name":"hashicorp/go-immutable-radix","owner":"hashicorp","description":"An immutable radix tree implementation in Golang","archived":false,"fork":false,"pushed_at":"2025-04-17T06:59:03.000Z","size":874,"stargazers_count":1038,"open_issues_count":15,"forks_count":78,"subscribers_count":291,"default_branch":"master","last_synced_at":"2025-05-03T07:37:28.540Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hashicorp.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":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2015-06-01T19:17:46.000Z","updated_at":"2025-05-02T17:27:47.000Z","dependencies_parsed_at":"2024-05-20T05:25:53.837Z","dependency_job_id":"2855e1ba-2a5d-4b25-8641-1557a0f61e8b","html_url":"https://github.com/hashicorp/go-immutable-radix","commit_stats":{"total_commits":88,"total_committers":20,"mean_commits":4.4,"dds":0.6931818181818181,"last_synced_commit":"e803b7ee3afe3fd7911a3e3da242eae1eda865e3"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hashicorp%2Fgo-immutable-radix","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hashicorp%2Fgo-immutable-radix/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hashicorp%2Fgo-immutable-radix/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hashicorp%2Fgo-immutable-radix/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hashicorp","download_url":"https://codeload.github.com/hashicorp/go-immutable-radix/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252963693,"owners_count":21832551,"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":[],"created_at":"2024-08-01T14:00:59.360Z","updated_at":"2025-05-07T22:26:37.205Z","avatar_url":"https://github.com/hashicorp.png","language":"Go","funding_links":[],"categories":["开源类库","Go"],"sub_categories":["数据结构"],"readme":"go-immutable-radix [![Run CI Tests](https://github.com/hashicorp/go-immutable-radix/actions/workflows/ci.yaml/badge.svg)](https://github.com/hashicorp/go-immutable-radix/actions/workflows/ci.yaml)\n=========\n\nProvides the `iradix` package that implements an immutable [radix tree](http://en.wikipedia.org/wiki/Radix_tree).\nThe package only provides a single `Tree` implementation, optimized for sparse nodes.\n\nAs a radix tree, it provides the following:\n * O(k) operations. In many cases, this can be faster than a hash table since\n   the hash function is an O(k) operation, and hash tables have very poor cache locality.\n * Minimum / Maximum value lookups\n * Ordered iteration\n\nA tree supports using a transaction to batch multiple updates (insert, delete)\nin a more efficient manner than performing each operation one at a time.\n\nFor a mutable variant, see [go-radix](https://github.com/armon/go-radix).\n\nV2\n==\n\nThe v2 of go-immutable-radix introduces generics to improve compile-time type\nsafety for users of the package. The module name for v2 is\n`github.com/hashicorp/go-immutable-radix/v2`.\n\nDocumentation\n=============\n\nThe full documentation is available on [Godoc](http://godoc.org/github.com/hashicorp/go-immutable-radix).\n\nExample\n=======\n\nBelow is a simple example of usage\n\n```go\n// Create a tree\nr := iradix.New[int]()\nr, _, _ = r.Insert([]byte(\"foo\"), 1)\nr, _, _ = r.Insert([]byte(\"bar\"), 2)\nr, _, _ = r.Insert([]byte(\"foobar\"), 2)\n\n// Find the longest prefix match\nm, _, _ := r.Root().LongestPrefix([]byte(\"foozip\"))\nif string(m) != \"foo\" {\n    panic(\"should be foo\")\n}\n```\n\nHere is an example of performing a range scan of the keys.\n\n```go\n// Create a tree\nr := iradix.New[int]()\nr, _, _ = r.Insert([]byte(\"001\"), 1)\nr, _, _ = r.Insert([]byte(\"002\"), 2)\nr, _, _ = r.Insert([]byte(\"005\"), 5)\nr, _, _ = r.Insert([]byte(\"010\"), 10)\nr, _, _ = r.Insert([]byte(\"100\"), 10)\n\n// Range scan over the keys that sort lexicographically between [003, 050)\nit := r.Root().Iterator()\nit.SeekLowerBound([]byte(\"003\"))\nfor key, _, ok := it.Next(); ok; key, _, ok = it.Next() {\n  if string(key) \u003e= \"050\" {\n      break\n  }\n  fmt.Println(string(key))\n}\n// Output:\n//  005\n//  010\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhashicorp%2Fgo-immutable-radix","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhashicorp%2Fgo-immutable-radix","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhashicorp%2Fgo-immutable-radix/lists"}