Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/cubicdaiya/bms
Boyer-Moore search algorithm in Go
https://github.com/cubicdaiya/bms
algorithm
Last synced: 19 days ago
JSON representation
Boyer-Moore search algorithm in Go
- Host: GitHub
- URL: https://github.com/cubicdaiya/bms
- Owner: cubicdaiya
- License: mit
- Created: 2014-01-17T11:54:55.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2022-04-06T12:02:24.000Z (over 2 years ago)
- Last Synced: 2024-06-21T15:45:36.479Z (5 months ago)
- Topics: algorithm
- Language: Go
- Homepage:
- Size: 7.81 KB
- Stars: 14
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: COPYING
Awesome Lists containing this project
README
# bms
Boyer-Moore search algorithm in Go.
# How To
## bms.Search
`bms.Search` searches a needle in a haystack and returns count of needle.
```go
haystack := "bokkobokkkobokkkkobokkobokkkobokkkko"
needle := "bokko"// search needle in haystack
c := bms.Search(haystack, needle) // c is 2
```## bms.SearchBySkipTable
`bms.SearchBySkipTable` is basically same as `bms.Search`. But This is efficient when same needle is used many times.
`bms.Search` builds a skip-table every time it is called. On the other hand, `bms.SearchBySkipTable` requires a skip-table as an argument.
So it avoids an overhead of building a skip-table when same needle is used many times.
```go
haystack := "bokkobokkkobokkkkobokkobokkkobokkkko"
needle := "bokko"// build skip-table
table := bms.BuildSkipTable(needle)// search needle in haystack by skip-table
c := bms.SearchBySkipTable(haystack, needle, table) // c is 2
```