{"id":42798908,"url":"https://github.com/porfirion/trie","last_synced_at":"2026-01-30T02:17:01.202Z","repository":{"id":57572745,"uuid":"346791570","full_name":"porfirion/trie","owner":"porfirion","description":"Efficient generic radix tree (trie) implementation in go","archived":false,"fork":false,"pushed_at":"2023-06-02T21:42:46.000Z","size":60,"stargazers_count":20,"open_issues_count":0,"forks_count":5,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-06-19T01:58:47.995Z","etag":null,"topics":["efficient","generic","generics","golang","patricia-tree","prefix","prefix-tree","prefix-tree-library","radix-tree","radix-trie","trie","typed","zero-dependency"],"latest_commit_sha":null,"homepage":"https://pkg.go.dev/github.com/porfirion/trie","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/porfirion.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":"2021-03-11T17:58:48.000Z","updated_at":"2024-05-23T20:49:04.000Z","dependencies_parsed_at":"2024-06-19T01:36:28.262Z","dependency_job_id":"2c91e41c-f551-4993-8e7e-c8b75cced571","html_url":"https://github.com/porfirion/trie","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/porfirion/trie","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/porfirion%2Ftrie","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/porfirion%2Ftrie/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/porfirion%2Ftrie/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/porfirion%2Ftrie/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/porfirion","download_url":"https://codeload.github.com/porfirion/trie/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/porfirion%2Ftrie/sbom","scorecard":{"id":741297,"data":{"date":"2025-08-11","repo":{"name":"github.com/porfirion/trie","commit":"243ff2b197edabcbd366d30ee5b4e52980000c25"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3,"checks":[{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Code-Review","score":0,"reason":"Found 0/12 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 3 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}}]},"last_synced_at":"2025-08-22T17:32:37.287Z","repository_id":57572745,"created_at":"2025-08-22T17:32:37.287Z","updated_at":"2025-08-22T17:32:37.287Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28896019,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-29T21:06:44.224Z","status":"online","status_checked_at":"2026-01-30T02:00:06.810Z","response_time":66,"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":["efficient","generic","generics","golang","patricia-tree","prefix","prefix-tree","prefix-tree-library","radix-tree","radix-trie","trie","typed","zero-dependency"],"created_at":"2026-01-30T02:17:00.669Z","updated_at":"2026-01-30T02:17:01.196Z","avatar_url":"https://github.com/porfirion.png","language":"Go","readme":"# Trie - compact and efficient generic radix tree (Patricia trie) implementation in go\n\nEfficient generic implementation with zero allocation for read operations (Get and Search) and 1 or 2 allocations per Put operation\n\n[![Go Reference](https://pkg.go.dev/badge/github.com/porfirion/trie.svg)](https://pkg.go.dev/github.com/porfirion/trie)\n[![Go Report Card](https://goreportcard.com/badge/github.com/porfirion/trie)](https://goreportcard.com/report/github.com/porfirion/trie)\n[![Coverage Status](https://coveralls.io/repos/github/porfirion/trie/badge.svg?branch=master)](https://coveralls.io/github/porfirion/trie?branch=master)\n\n## Installation\n\n    go get github.com/porfirion/trie\n\n## Usage\n\n```go\ntr := \u0026trie.Trie[int]\ntr.PutString(\"hello\", 1) // same as tr.Put([]byte(\"hello\"), 1)\n// OR\ntr := trie.BuildFromMap(map[string]int{ \n\t\"hello\": 1 \n})\n\nv, ok := tr.GetByString(\"hello\")\nfmt.Println(v)\n```\n\nTrie can be used in different ways:\n\n1. Primarily I created it for searching emojis :smile: in text (in Telegram messages). There are about 3,3k emojis \n   in current standard (https://www.unicode.org/emoji/charts-13.0/emoji-counts.html) and checking them one by one \n   is very costly. For this purpose I added export package: you can generate source code for trie with all available \n   emojis and compile it in your program.  \n\n2. You can use it as map, where key is a slice of arbitrary bytes (`map[[]byte]interface{}` which is not possible \n   in language because slices are not comparable and can't be used as keys).\n\n3. You can use this trie to check for any string prefixes (possibly storing some payload for each prefix). See example below.\n\n4. You can build some http router using this Trie. For this purpose I added `SubTrie(mask []byte)` method that returns \n   sub trie with all entries, prefixed by specified mask, and `GetAll(mask []byte)` that returns all entries containing \n   specified mask. See example below.\n\nAlso, this implementation supports zero-length prefix (`[]byte{}` or `nil`). Value associated with this prefix can be \nused as fallback when no other entries found. Or it can serve as universal prefix for all entries.\n\nNote: Trie stores pointers to values inside, but if your values are really large (structures or arrays) - consider \nusing pointers as type parameter: Trie[*MyStruct]. It will prevent copying of large structures when getting result of Get. \n\n## Examples\n\nSearch prefixes:\n```go\npackage main\n\nimport (\n    \"fmt\"\n    \"strings\"\n    \"github.com/porfirion/trie\"\n)\n\n// Also can be created with\n//    prefixes := \u0026trie.Trie{}\n//    prefixes.PutString(\"one\", 1)\n//    prefixes.PutString(\"two\", 2)\n//    prefixes.PutString(\"three\", 3)\n//    prefixes.PutString(\"\", 0)\n//\nvar prefixes = trie.BuildFromMap[int](map[string]interface{}{\n    \"one\":   1,\n    \"two\":   2,\n    \"three\": 3,\n    \"\":      0,\n})\n\nfunc Example() {\n    var inputs = []string{\n        \"twoApple\",\n        \"oneBanana\",\n        \"Carrot\",\n    }\n\n    for _, inp := range inputs {\n        if val, prefixLen, ok := prefixes.SearchPrefixInString(inp); ok {\n            fmt.Println(strings.Repeat(inp[prefixLen:], val.(int)))\n        }\n    }\n\n    // Output:\n    //AppleApple\n    //Banana\n}\n```\n\nUse as router:\n```go\npackage main\n\nimport (\n    \"fmt\"\n    \"github.com/porfirion/trie\"\n)\n\nvar routes = trie.BuildFromMap(map[string]interface{}{\n    \"\":                \"root\", // as universal prefix\n    \"/api/user\":       \"user\",\n    \"/api/user/list\":  \"usersList\",\n    \"/api/group\":      \"group\",\n    \"/api/group/list\": \"groupsList\",\n    \"/api/articles/\":  \"articles\",\n})\n\nfunc Example_routing() {\n    var inputs = []string{\n        \"/api/user/list\",\n        \"/api/user/li\",\n        \"/api/group\",\n        \"/api/unknown\",\n    }\n\n    for _, inp := range inputs {\n        exact, ok := routes.GetByString(inp)\n        route := routes.GetAllByString(inp)\n        if ok {\n            fmt.Printf(\"%-17s:\\thandler %-10s\\t(route %v)\\n\", inp, exact, route)\n        } else {\n            fmt.Printf(\"%-17s:\\thandler not found\\t(route %v)\\n\", inp, route)\n        }\n    }\n\n    // Output:\n    // /api/user/list   :\thandler usersList \t(route [root user usersList])\n    // /api/user/li     :\thandler not found\t(route [root user])\n    // /api/group       :\thandler group     \t(route [root group])\n    // /api/unknown     :\thandler not found\t(route [root])\n}\n```\n\n## Notes\n\nI didn't implement `Delete`/`Remove` operation as I assumed only checking for predefined list of prefixes. I you find it useful and really need it - please, open issue, I'll add it.","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fporfirion%2Ftrie","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fporfirion%2Ftrie","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fporfirion%2Ftrie/lists"}