Boyer-Moore search algorithm in Go
Go
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
.travis.yml
COPYING
README.md
bms.go
bms_test.go

README.md

bms

Build Status

Boyer-Moore search algorithm in Go.

How To

bms.Search

bms.Search searches a needle in a haystack and returns count of needle.

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.

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