{"id":38668762,"url":"https://github.com/cjgdev/aho_corasick","last_synced_at":"2026-01-17T09:52:40.808Z","repository":{"id":30507020,"uuid":"34061424","full_name":"cjgdev/aho_corasick","owner":"cjgdev","description":"A C++ implementation of the aho corasick pattern search algorithm","archived":false,"fork":false,"pushed_at":"2023-07-15T12:25:29.000Z","size":173,"stargazers_count":202,"open_issues_count":15,"forks_count":50,"subscribers_count":8,"default_branch":"master","last_synced_at":"2023-11-07T17:26:29.447Z","etag":null,"topics":["aho-corasick","c-plus-plus"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cjgdev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-04-16T14:42:36.000Z","updated_at":"2023-09-28T10:28:23.000Z","dependencies_parsed_at":"2022-09-01T12:02:26.327Z","dependency_job_id":null,"html_url":"https://github.com/cjgdev/aho_corasick","commit_stats":null,"previous_names":[],"tags_count":0,"template":null,"template_full_name":null,"purl":"pkg:github/cjgdev/aho_corasick","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cjgdev%2Faho_corasick","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cjgdev%2Faho_corasick/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cjgdev%2Faho_corasick/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cjgdev%2Faho_corasick/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cjgdev","download_url":"https://codeload.github.com/cjgdev/aho_corasick/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cjgdev%2Faho_corasick/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28505565,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-17T06:57:29.758Z","status":"ssl_error","status_checked_at":"2026-01-17T06:56:03.931Z","response_time":85,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["aho-corasick","c-plus-plus"],"created_at":"2026-01-17T09:52:40.683Z","updated_at":"2026-01-17T09:52:40.770Z","avatar_url":"https://github.com/cjgdev.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Aho-Corasick Implementation (C++)\n\nThis is a header only implementation of the aho-corasick pattern search algorithm invented by Alfred V. Aho and Margaret J. Corasick. It is a very efficient dictionary matching algorithm that can locate all search patterns against in input text simultaneously in O(n + m), with space complexity O(m) (where n is the length of the input text, and m is the combined length of the search patterns).\n\nTo compile the code, your compiler must minimally support the following features of the C++11 standard:\n- Range-based for loops.\n- std::unique_ptr.\n- auto.\n\nAdditionally, the benchmark makes use of chrono.\n\n## Usage\n\nThe following will create a narrow string trie (for wide string support use aho_corasick::wtrie), add a couple of patterns to the trie, and then search for them in the input text.\n\n```cpp\naho_corasick::trie trie;\ntrie.insert(\"hers\");\ntrie.insert(\"his\");\ntrie.insert(\"she\");\ntrie.insert(\"he\");\nauto result = trie.parse_text(\"ushers\");\n```\n\nIt is also possible to remove overlapping instances, although it should be noted that this won't lower the runtime complexity. The rules that govern conflict resolution are 1. longer matches are favoured over shorter matches, and 2. left-most matches are favoured over right-most matches.\n\n```cpp\naho_corasick::trie trie;\ntrie.remove_overlaps();\ntrie.insert(\"hot\");\ntrie.insert(\"hot chocolate\");\nauto result = trie.parse_text(\"hot chocolate\");\n```\n\nSometimes it is relevant to search an input text which features a mixed case, making it harder to find matches. In this instance, the trie can lowercase the input text to ease the matching process.\n\n```cpp\naho_corasick::trie trie;\ntrie.case_insensitive();\ntrie.insert(\"casing\");\nauto result = trie.parse_text(\"CaSiNg\");\n```\n\nFor some use-cases it is necessary to process both matching and non-matching text. In this case, you can use trie::tokenise.\n\n```cpp\naho_corasick::trie trie;\ntrie.remove_overlaps()\n    .only_whole_words()\n    .case_insensitive();\ntrie.insert(\"great question\");\ntrie.insert(\"forty-two\");\ntrie.insert(\"deep thought\");\nauto tokens = trie.tokenise(\"The Answer to the Great Question... Of Life, the Universe and Everything... Is... Forty-two, said Deep Thought, with infinite majesty and calm.\");\nstd::stringstream html;\nhtml \u003c\u003c \"\u003chtml\u003e\u003cbody\u003e\u003cp\u003e\";\nfor (const auto\u0026 token : tokens) {\n\tif (token.is_match()) html \u003c\u003c \"\u003ci\u003e\";\n\thtml \u003c\u003c token.get_fragment();\n\tif (token.is_match()) html \u003c\u003c \"\u003c/i\u003e\";\n}\nhtml \u003c\u003c \"\u003c/p\u003e\u003c/body\u003e\u003c/html\u003e\";\nstd::cout \u003c\u003c html.str();\n```\n\n## License\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n\n## Further Reading\n\n- [Wikipedia](https://en.wikipedia.org/wiki/Aho%E2%80%93Corasick_string_matching_algorithm)\n- [Whitepaper](ftp://163.13.200.222/assistant/bearhero/prog/%A8%E4%A5%A6/ac_bm.pdf)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcjgdev%2Faho_corasick","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcjgdev%2Faho_corasick","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcjgdev%2Faho_corasick/lists"}