{"id":13439105,"url":"https://github.com/billyevans/tst","last_synced_at":"2025-03-20T07:31:59.709Z","repository":{"id":27742123,"uuid":"31229947","full_name":"billyevans/tst","owner":"billyevans","description":"Ternary search tree collection in rust","archived":false,"fork":false,"pushed_at":"2022-12-13T06:04:40.000Z","size":997,"stargazers_count":23,"open_issues_count":0,"forks_count":4,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-10-28T01:11:52.142Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"LineageOS/android_device_huawei_kiwi","license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/billyevans.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}},"created_at":"2015-02-23T21:10:11.000Z","updated_at":"2024-01-11T07:52:51.000Z","dependencies_parsed_at":"2023-01-14T07:23:57.998Z","dependency_job_id":null,"html_url":"https://github.com/billyevans/tst","commit_stats":null,"previous_names":[],"tags_count":22,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/billyevans%2Ftst","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/billyevans%2Ftst/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/billyevans%2Ftst/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/billyevans%2Ftst/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/billyevans","download_url":"https://codeload.github.com/billyevans/tst/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244570844,"owners_count":20474132,"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-07-31T03:01:11.181Z","updated_at":"2025-03-20T07:31:54.699Z","avatar_url":"https://github.com/billyevans.png","language":"Rust","readme":"# tst\n\n[![Build Status](https://travis-ci.org/billyevans/tst.svg?branch=master)](https://travis-ci.org/billyevans/tst)\n[![Coverage Status](https://coveralls.io/repos/billyevans/tst/badge.svg?branch=master)](https://coveralls.io/r/billyevans/tst?branch=master)\n[![crates.io](http://meritbadge.herokuapp.com/tst)](https://crates.io/crates/tst)\n[![API](https://docs.rs/tst/badge.svg)](https://docs.rs/tst/)\n\nTernary search tree collection in rust with similar API to std::collections as it possible.\n\nTernary search tree is a type of trie (sometimes called a prefix tree) where nodes are arranged in a manner similar to a binary search tree, but with up to three children rather than the binary tree's limit of two. Like other prefix trees, a ternary search tree can be used as an associative map structure with the ability for incremental string search. However, ternary search trees are more space efficient compared to standard prefix trees, at the cost of speed. Common applications for ternary search trees include spell-checking and auto-completion.\nTSTMap and TSTSet structures for map and set like usage.\n\nDocumentation is available at http://billyevans.github.io/tst/tst\n\nIt has special methods:\n- wildcard_iter/wildcard_iter_mut - get iterator by wildcard\n- prefix_iter/prefix_iter_mut - get iterator by prefix\n- longest_prefix - get longest prefix\n\n## Usage\n\nAdd this to your `Cargo.toml`:\n\n```toml\n[dependencies]\ntst = \"0.10.*\"\n```\n\n## Quick Start\n```rust\n#[macro_use]\nextern crate tst;\nuse tst::TSTMap;\n\nlet m = tstmap! {\n    \"first\" =\u003e  1,\n    \"second\" =\u003e 2,\n    \"firstthird\" =\u003e 3,\n    \"firstsecond\" =\u003e 12,\n    \"xirst\" =\u003e -13,\n};\n\n// iterate\nfor (key, value) in m.iter() {\n    println!(\"{}: {}\", key, value);\n}\nassert_eq!(Some(\u00261), m.get(\"first\"));\nassert_eq!(5, m.len());\n\n// calculating longest prefix\nassert_eq!(\"firstsecond\", m.longest_prefix(\"firstsecondthird\"));\n\n// get values with common prefix\nfor (key, value) in m.prefix_iter(\"first\") {\n    println!(\"{}: {}\", key, value);\n}\n\n// get sum by wildcard iterator\nassert_eq!(-12, m.wildcard_iter(\".irst\").fold(0, |sum, (_, val)| sum + val));\n```\n\n### Iterating over keys with wildcard\n```rust\n#[macro_use]\nextern crate tst;\nuse tst::TSTMap;\n\nlet m = tstmap! {\n    \"ac\" =\u003e 1,\n    \"bd\" =\u003e 2,\n    \"cc\" =\u003e 3,\n};\n\nfor (k, v) in m.wildcard_iter(\".c\") {\n    println!(\"{} -\u003e {}\", k, v);\n}\n```\n\n### Itereting over keys with common prefix\n```rust\n#[macro_use]\nextern crate tst;\nuse tst::TSTMap;\n\nlet m = tstmap! {\n    \"abc\" =\u003e 1,\n    \"abcd\" =\u003e 1,\n    \"abce\" =\u003e 1,\n    \"abca\" =\u003e 1,\n    \"zxd\" =\u003e 1,\n    \"add\" =\u003e 1,\n    \"abcdef\" =\u003e 1,\n};\n\nfor (key, value) in m.prefix_iter(\"abc\") {\n    println!(\"{}: {}\", key, value);\n}\n\n```\n\n### Search for longest prefix in the tree\n```rust\n#[macro_use]\nextern crate tst;\nuse tst::TSTMap;\n\nlet m = tstmap! {\n    \"abc\" =\u003e 1,\n    \"abcd\" =\u003e 1,\n    \"abce\" =\u003e 1,\n    \"abca\" =\u003e 1,\n    \"zxd\" =\u003e 1,\n    \"add\" =\u003e 1,\n    \"abcdef\" =\u003e 1,\n};\n\nassert_eq!(\"abcd\", m.longest_prefix(\"abcde\"));\n```\n\n### Implementation details\n\nhttps://en.wikipedia.org/wiki/Ternary_search_tree\n\n# License\n\nTST is distributed under the terms of the MIT license. \n\nSee [LICENSE-MIT](LICENSE-MIT), and [COPYRIGHT](COPYRIGHT) for details.\n","funding_links":[],"categories":["Libraries","库 Libraries","库"],"sub_categories":["Data structures","数据结构 Data structures","数据结构"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbillyevans%2Ftst","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbillyevans%2Ftst","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbillyevans%2Ftst/lists"}