Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ofw/ahocorasick
Thread safe Aho-Corasick string matching algorithm for golang
https://github.com/ofw/ahocorasick
Last synced: about 2 months ago
JSON representation
Thread safe Aho-Corasick string matching algorithm for golang
- Host: GitHub
- URL: https://github.com/ofw/ahocorasick
- Owner: ofw
- Created: 2018-03-28T17:51:29.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2018-03-28T17:51:38.000Z (almost 7 years ago)
- Last Synced: 2024-06-20T13:34:48.754Z (7 months ago)
- Language: Go
- Size: 6.84 KB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## β‘ Aho-Corasick Pattern Matching Algorithm β‘
Aho-Corasick string matching algorithm for golang.
This if a fork of original https://github.com/gansidui/ahocorasick library which is not updated since 2014.
Key improvements:
* Thread safety for multiple calls to `Match` method πͺοΈ
* Perfomance optimizations (about 5x speed and reduced allocations) π:
```
BenchmarkOriginal 1000000 1424 ns/op 64 B/op 4 allocs/op
BenchmarkOptimized 5000000 237 ns/op 35 B/op 2 allocs/op
```
* Fixed incorrect results with some test casesNow this package is even faster than https://github.com/cloudflare/ahocorasick:
```
BenchmarkOfw-4 5000000 318 ns/op 16 B/op 2 allocs/op
BenchmarkCloudflare-4 3000000 455 ns/op 104 B/op 4 allocs/op
```~~~ go
package mainimport (
"fmt"
"github.com/ofw/ahocorasick"
)func main() {
ac := ahocorasick.NewMatcher()dictionary := []string{"hello", "world", "δΈη", "google", "golang", "c++", "love"}
ac.Build(dictionary)
ret := ac.Match("helloδΈη, hello google, i love golang!!!")
for _, i := range ret {
fmt.Println(dictionary[i])
}
}~~~
## License
MIT