Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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

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
```