{"id":21682335,"url":"https://github.com/beevik/prefixtree","last_synced_at":"2025-08-22T01:33:03.632Z","repository":{"id":27090398,"uuid":"30557462","full_name":"beevik/prefixtree","owner":"beevik","description":"A prefix tree (trie) implementation in go","archived":false,"fork":false,"pushed_at":"2024-07-13T03:03:35.000Z","size":70,"stargazers_count":34,"open_issues_count":0,"forks_count":8,"subscribers_count":4,"default_branch":"v2","last_synced_at":"2024-11-25T15:54:01.721Z","etag":null,"topics":["data-structures","prefix","prefix-tree","prefix-trie","trie"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/beevik.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":"2015-02-09T20:42:57.000Z","updated_at":"2024-08-30T19:59:07.000Z","dependencies_parsed_at":"2024-06-19T00:12:38.708Z","dependency_job_id":"db14378e-d722-4bb1-aa5d-ab7f89a255dd","html_url":"https://github.com/beevik/prefixtree","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beevik%2Fprefixtree","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beevik%2Fprefixtree/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beevik%2Fprefixtree/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/beevik%2Fprefixtree/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/beevik","download_url":"https://codeload.github.com/beevik/prefixtree/tar.gz/refs/heads/v2","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230547682,"owners_count":18243227,"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":["data-structures","prefix","prefix-tree","prefix-trie","trie"],"created_at":"2024-11-25T15:35:42.934Z","updated_at":"2024-12-20T07:07:27.727Z","avatar_url":"https://github.com/beevik.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![GoDoc](https://godoc.org/github.com/beevik/prefixtree/v2?status.svg)](https://godoc.org/github.com/beevik/prefixtree/v2)\n[![Go](https://github.com/beevik/prefixtree/actions/workflows/go.yml/badge.svg)](https://github.com/beevik/prefixtree/actions/workflows/go.yml)\n\nprefixtree\n==========\n\nThe prefixtree package implements a simple prefix trie data structure.\nThe tree enables rapid searching for strings that uniquely match a given\nprefix. The implementation allows the user to associate data with each\nstring, so it can act as a sort of flexible key-value store where\nsearches succeed with the shortest unambiguous key prefix.\n\nThis is version 2 of the package, which you can retrieve using `go get`:\n\n```sh\ngo get github.com/beevik/prefixtree/v2\n```\n\n### Example: Building a prefix tree\n\nThe following code adds strings and associated data (in this case an integer)\nto a prefix tree.\n\n```go\ntree := prefixtree.New[int]()\n\ntree.Add(\"apple\", 10)\ntree.Add(\"orange\", 20)\ntree.Add(\"apple pie\", 30)\ntree.Add(\"lemon\", 40)\ntree.Add(\"lemon meringue pie\", 50)\n```\n\n### Example: Searching the prefix tree\n\nThe following code searches the prefix tree generated by the\nprevious example and outputs the results.\n\n```go\nfmt.Printf(\"%-18s %-8s %s\\n\", \"prefix\", \"value\", \"error\")\nfmt.Printf(\"%-18s %-8s %s\\n\", \"------\", \"-----\", \"-----\")\n\nfor _, prefix := range []string{\n    \"a\",\n    \"appl\",\n    \"apple\",\n    \"apple p\",\n    \"apple pie\",\n    \"apple pies\",\n    \"o\",\n    \"oran\",\n    \"orange\",\n    \"oranges\",\n    \"l\",\n    \"lemo\",\n    \"lemon\",\n    \"lemon m\",\n    \"lemon meringue\",\n    \"pear\",\n} {\n    value, err := tree.FindValue(prefix)\n    fmt.Printf(\"%-18s %-8v %v\\n\", prefix, value, err)\n}\n```\n\nOutput:\n```\nprefix             value    error\n------             -----    -----\na                  0        prefixtree: prefix ambiguous\nappl               0        prefixtree: prefix ambiguous\napple              10       \u003cnil\u003e\napple p            30       \u003cnil\u003e\napple pie          30       \u003cnil\u003e\napple pies         0        prefixtree: prefix not found\no                  20       \u003cnil\u003e\noran               20       \u003cnil\u003e\norange             20       \u003cnil\u003e\noranges            0        prefixtree: prefix not found\nl                  0        prefixtree: prefix ambiguous\nlemo               0        prefixtree: prefix ambiguous\nlemon              40       \u003cnil\u003e\nlemon m            50       \u003cnil\u003e\nlemon meringue     50       \u003cnil\u003e\npear               0        prefixtree: prefix not found\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbeevik%2Fprefixtree","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbeevik%2Fprefixtree","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbeevik%2Fprefixtree/lists"}