{"id":18264561,"url":"https://github.com/modeltc/general-sam","last_synced_at":"2025-09-10T14:47:00.308Z","repository":{"id":199984279,"uuid":"704448010","full_name":"ModelTC/general-sam","owner":"ModelTC","description":"A general suffix automaton implementation in Rust with Python bindings","archived":false,"fork":false,"pushed_at":"2025-06-09T02:57:46.000Z","size":180,"stargazers_count":7,"open_issues_count":1,"forks_count":0,"subscribers_count":6,"default_branch":"main","last_synced_at":"2025-06-09T03:30:18.644Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ModelTC.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE-APACHE","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,"zenodo":null}},"created_at":"2023-10-13T09:25:13.000Z","updated_at":"2025-06-09T02:55:06.000Z","dependencies_parsed_at":"2023-11-22T06:30:57.068Z","dependency_job_id":"503cfb89-472a-4c91-86b2-7d21b3812dd0","html_url":"https://github.com/ModelTC/general-sam","commit_stats":null,"previous_names":["modeltc/general-sam"],"tags_count":17,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ModelTC%2Fgeneral-sam","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ModelTC%2Fgeneral-sam/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ModelTC%2Fgeneral-sam/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ModelTC%2Fgeneral-sam/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ModelTC","download_url":"https://codeload.github.com/ModelTC/general-sam/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ModelTC%2Fgeneral-sam/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":258874940,"owners_count":22771236,"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-11-05T11:15:07.121Z","updated_at":"2025-07-02T03:04:52.952Z","avatar_url":"https://github.com/ModelTC.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# general-sam\n\n[![Crates.io](https://img.shields.io/crates/v/general-sam.svg)](https://crates.io/crates/general-sam)\n[![Docs.rs](https://img.shields.io/docsrs/general-sam.svg)](https://docs.rs/general-sam)\n[![License](https://img.shields.io/badge/license-MIT%2FApache--2.0-informational.svg)](#license)\n[![Build status](https://github.com/ModelTC/general-sam/actions/workflows/ci.yml/badge.svg)](https://github.com/ModelTC/general-sam/actions)\n\nA general suffix automaton implementation in Rust.\n\nPython bindings and some utilities are also available.\nPlease check out [`general-sam-py`](https://github.com/ModelTC/general-sam-py).\n\n```mermaid\nflowchart LR\n  init((ε))\n  a((a))\n  b((b))\n  ab((ab))\n  bc(((bc)))\n  abc((abc))\n  abcb((abcb))\n  abcbc(((abcbc)))\n\n  init -- a --\u003e a\n  init -- b --\u003e b\n  a -- b --\u003e ab\n  b -- c --\u003e bc\n  init -- c --\u003e bc\n  ab -- c --\u003e abc\n  bc -- b --\u003e abcb\n  abc -- b --\u003e abcb\n  abcb -- c --\u003e abcbc\n```\n\n\u003e The suffix automaton of abcbc.\n\n## Examples\n\n```rust\nuse general_sam::{GeneralSam, BTreeTransTable};\n\nlet sam = GeneralSam::\u003cBTreeTransTable\u003c_\u003e\u003e::from_bytes(\"abcbc\");\n\n// \"cbc\" is a suffix of \"abcbc\"\nassert!(sam.get_root_state().feed_bytes(\"cbc\").is_accepting());\n\n// \"bcb\" is not a suffix of \"abcbc\"\nassert!(!sam.get_root_state().feed_bytes(\"bcb\").is_accepting());\n```\n\n```rust\nuse general_sam::{GeneralSam, BTreeTransTable};\n\nlet sam = GeneralSam::\u003cBTreeTransTable\u003c_\u003e\u003e::from_chars(\"abcbc\");\n\nlet mut state = sam.get_root_state();\n\n// \"b\" is not a suffix but at least a substring of \"abcbc\"\nstate.feed_chars(\"b\");\nassert!(!state.is_accepting());\n\n// \"bc\" is a suffix of \"abcbc\"\nstate.feed_chars(\"c\");\nassert!(state.is_accepting());\n\n// \"bcbc\" is a suffix of \"abcbc\"\nstate.feed_chars(\"bc\");\nassert!(state.is_accepting());\n\n// \"bcbcbc\" is not a substring, much less a suffix of \"abcbc\"\nstate.feed_chars(\"bc\");\nassert!(!state.is_accepting() \u0026\u0026 state.is_nil());\n```\n\n```rust\n# #[cfg(feature = \"trie\")] {\nuse general_sam::{GeneralSam, Trie, BTreeTransTable};\n\nlet mut trie = Trie::\u003cBTreeTransTable\u003c_\u003e\u003e::default();\ntrie.insert(\"hello\".chars());\ntrie.insert(\"Chielo\".chars());\n\nlet sam = GeneralSam::\u003cBTreeTransTable\u003c_\u003e\u003e::from_trie(trie.get_root_state());\n\nassert!(sam.get_root_state().feed_chars(\"lo\").is_accepting());\nassert!(sam.get_root_state().feed_chars(\"ello\").is_accepting());\nassert!(sam.get_root_state().feed_chars(\"elo\").is_accepting());\n\nassert!(!sam.get_root_state().feed_chars(\"el\").is_accepting());\nassert!(!sam.get_root_state().feed_chars(\"el\").is_nil());\n\nassert!(!sam.get_root_state().feed_chars(\"bye\").is_accepting());\nassert!(sam.get_root_state().feed_chars(\"bye\").is_nil());\n# }\n```\n\n## References\n\n- [Mehryar Mohri, Pedro Moreno, Eugene Weinstein.\n  General suffix automaton construction algorithm and space bounds.][paper]\n- 刘研绎《后缀自动机在字典树上的拓展》\n- [广义后缀自动机 - OI Wiki][general-sam-oi-wiki]\n\n[paper]: https://doi.org/10.1016/j.tcs.2009.03.034\n[general-sam-oi-wiki]: https://oi-wiki.org/string/general-sam/\n\n## License\n\n- \u0026copy; 2023 Chielo Newctle \\\u003c[ChieloNewctle@gmail.com](mailto:ChieloNewctle@gmail.com)\\\u003e\n- \u0026copy; 2023 ModelTC Team\n\nThis project is licensed under either of\n\n- [Apache License, Version 2.0](https://www.apache.org/licenses/LICENSE-2.0) ([`LICENSE-APACHE`](LICENSE-APACHE))\n- [MIT license](https://opensource.org/licenses/MIT) ([`LICENSE-MIT`](LICENSE-MIT))\n\nat your option.\n\nThe [SPDX](https://spdx.dev) license identifier for this project is `MIT OR Apache-2.0`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmodeltc%2Fgeneral-sam","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmodeltc%2Fgeneral-sam","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmodeltc%2Fgeneral-sam/lists"}