本文整理匯總了Golang中github.com/MobRulesGames/stringz/core.BoyerMoorePreprocess函數的典型用法代碼示例。如果您正苦於以下問題:Golang BoyerMoorePreprocess函數的具體用法?Golang BoyerMoorePreprocess怎麽用?Golang BoyerMoorePreprocess使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了BoyerMoorePreprocess函數的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: BenchmarkBoyerMoore5_100_100000
func BenchmarkBoyerMoore5_100_100000(b *testing.B) {
b.StopTimer()
p := makeTestString4(100, 4, 0)
t := makeTestString4(100000, 4, 1)
bmd := core.BoyerMoorePreprocess(p)
b.StartTimer()
var matches []int
for i := 0; i < b.N; i++ {
matches = matches[0:0]
core.BoyerMoore(bmd, t, &matches)
}
}
示例2: BenchmarkBoyerMooreReader5_100_100000
func BenchmarkBoyerMooreReader5_100_100000(b *testing.B) {
b.StopTimer()
p := makeTestString4(100, 4, 0)
t := makeTestString4(100000, 4, 1)
bmd := core.BoyerMoorePreprocess(p)
b.StartTimer()
var matches []int
buf := make([]byte, 5000)
for i := 0; i < b.N; i++ {
matches = matches[0:0]
b.StopTimer()
in := bytes.NewBuffer(t)
b.StartTimer()
core.BoyerMooreFromReader(bmd, in, buf, &matches)
}
}
示例3: BoyerMooreReaderSpec
func BoyerMooreReaderSpec(c gospec.Context) {
c.Specify("Basic test", func() {
var matches []int
buffer := make([]byte, 500)
p := []byte("a")
t := []byte("aaaaaaaaa")
bmd := core.BoyerMoorePreprocess(p)
matches = matches[0:0]
core.BoyerMooreFromReader(bmd, bytes.NewBuffer(t), buffer, &matches)
c.Expect(matches, ContainsExactly, idiotStringSearch(p, t))
p = []byte("aa")
t = []byte("aaaaaaaaaa")
core.BoyerMoorePreprocess(p)
bmd = core.BoyerMoorePreprocess(p)
matches = matches[0:0]
core.BoyerMooreFromReader(bmd, bytes.NewBuffer(t), buffer, &matches)
c.Expect(matches, ContainsExactly, idiotStringSearch(p, t))
p = []byte("aaaaaaaaaa")
t = []byte("aaaaaaaaaa")
core.BoyerMoorePreprocess(p)
bmd = core.BoyerMoorePreprocess(p)
matches = matches[0:0]
core.BoyerMooreFromReader(bmd, bytes.NewBuffer(t), buffer, &matches)
c.Expect(matches, ContainsExactly, idiotStringSearch(p, t))
p = []byte("aaaaaaaaaaaaaaaaaaaaa")
t = []byte("aaaaaaaaaa")
core.BoyerMoorePreprocess(p)
bmd = core.BoyerMoorePreprocess(p)
matches = matches[0:0]
core.BoyerMooreFromReader(bmd, bytes.NewBuffer(t), buffer, &matches)
c.Expect(matches, ContainsExactly, idiotStringSearch(p, t))
p = []byte("b")
t = []byte("aaaabaaaaa")
core.BoyerMoorePreprocess(p)
bmd = core.BoyerMoorePreprocess(p)
matches = matches[0:0]
core.BoyerMooreFromReader(bmd, bytes.NewBuffer(t), buffer, &matches)
c.Expect(matches, ContainsExactly, idiotStringSearch(p, t))
p = []byte("ba")
t = []byte("aaaabaaaaa")
core.BoyerMoorePreprocess(p)
bmd = core.BoyerMoorePreprocess(p)
matches = matches[0:0]
core.BoyerMooreFromReader(bmd, bytes.NewBuffer(t), buffer, &matches)
c.Expect(matches, ContainsExactly, idiotStringSearch(p, t))
p = []byte("aaaabaaaaa")
t = []byte("aaaabaaaaa")
core.BoyerMoorePreprocess(p)
bmd = core.BoyerMoorePreprocess(p)
matches = matches[0:0]
core.BoyerMooreFromReader(bmd, bytes.NewBuffer(t), buffer, &matches)
c.Expect(matches, ContainsExactly, idiotStringSearch(p, t))
p = []byte("aaaaaaaaaaaaaaaaabaaa")
t = []byte("aaaaaabaaa")
core.BoyerMoorePreprocess(p)
bmd = core.BoyerMoorePreprocess(p)
matches = matches[0:0]
core.BoyerMooreFromReader(bmd, bytes.NewBuffer(t), buffer, &matches)
c.Expect(matches, ContainsExactly, idiotStringSearch(p, t))
})
c.Specify("Comprehensive test 2^17", func() {
var matches []int
buffer := make([]byte, 15)
b := make([]byte, 17)
for augment(b, 2) {
p := b[0:5]
t := b[5:]
bmd := core.BoyerMoorePreprocess(p)
matches = matches[0:0]
core.BoyerMooreFromReader(bmd, bytes.NewBuffer(t), buffer, &matches)
c.Expect(matches, ContainsExactly, idiotStringSearch(p, t))
}
})
c.Specify("Comprehensive test 3^11", func() {
var matches []int
buffer := make([]byte, 15)
b := make([]byte, 11)
for augment(b, 3) {
p := b[0:4]
t := b[4:]
bmd := core.BoyerMoorePreprocess(p)
matches = matches[0:0]
core.BoyerMooreFromReader(bmd, bytes.NewBuffer(t), buffer, &matches)
c.Expect(matches, ContainsExactly, idiotStringSearch(p, t))
}
})
c.Specify("Random test", func() {
var matches []int
buffer := make([]byte, 15)
for i := 0; i < 10000; i += 2 {
p := makeTestString4(15, 7, i)
t := makeTestString4(1000, 7, i+1)
bmd := core.BoyerMoorePreprocess(p)
matches = matches[0:0]
core.BoyerMooreFromReader(bmd, bytes.NewBuffer(t), buffer, &matches)
c.Expect(matches, ContainsExactly, idiotStringSearch(p, t))
}
//.........這裏部分代碼省略.........
示例4: BoyerMooreSpec
func BoyerMooreSpec(c gospec.Context) {
c.Specify("Basic test", func() {
p := []byte("a")
t := []byte("aaaaaaaaaa")
var matches []int
core.BoyerMoore(core.BoyerMoorePreprocess(p), t, &matches)
c.Expect(matches, ContainsExactly, idiotStringSearch(p, t))
matches = matches[0:0]
p = []byte("aa")
t = []byte("aaaaaaaaaa")
core.BoyerMoore(core.BoyerMoorePreprocess(p), t, &matches)
c.Expect(matches, ContainsExactly, idiotStringSearch(p, t))
matches = matches[0:0]
p = []byte("aaaaaaaaaa")
t = []byte("aaaaaaaaaa")
core.BoyerMoore(core.BoyerMoorePreprocess(p), t, &matches)
c.Expect(matches, ContainsExactly, idiotStringSearch(p, t))
matches = matches[0:0]
p = []byte("aaaaaaaaaaaaaaaaaaaaa")
t = []byte("aaaaaaaaaa")
core.BoyerMoore(core.BoyerMoorePreprocess(p), t, &matches)
c.Expect(matches, ContainsExactly, idiotStringSearch(p, t))
matches = matches[0:0]
p = []byte("b")
t = []byte("aaaabaaaaa")
core.BoyerMoore(core.BoyerMoorePreprocess(p), t, &matches)
c.Expect(matches, ContainsExactly, idiotStringSearch(p, t))
matches = matches[0:0]
p = []byte("ba")
t = []byte("aaaabaaaaa")
core.BoyerMoore(core.BoyerMoorePreprocess(p), t, &matches)
c.Expect(matches, ContainsExactly, idiotStringSearch(p, t))
matches = matches[0:0]
p = []byte("aaaabaaaaa")
t = []byte("aaaabaaaaa")
core.BoyerMoore(core.BoyerMoorePreprocess(p), t, &matches)
c.Expect(matches, ContainsExactly, idiotStringSearch(p, t))
matches = matches[0:0]
p = []byte("aaaaaaaaaaaaaaaaabaaa")
t = []byte("aaaaaabaaa")
core.BoyerMoore(core.BoyerMoorePreprocess(p), t, &matches)
c.Expect(matches, ContainsExactly, idiotStringSearch(p, t))
matches = matches[0:0]
})
c.Specify("Comprehensive test 2^17", func() {
b := make([]byte, 17)
var matches []int
for augment(b, 2) {
p := b[0:5]
t := b[5:]
bmd := core.BoyerMoorePreprocess(p)
matches = matches[0:0]
core.BoyerMoore(bmd, t, &matches)
c.Expect(matches, ContainsExactly, idiotStringSearch(p, t))
}
})
c.Specify("Comprehensive test 3^11", func() {
b := make([]byte, 11)
var matches []int
for augment(b, 3) {
p := b[0:4]
t := b[4:]
bmd := core.BoyerMoorePreprocess(p)
matches = matches[0:0]
core.BoyerMoore(bmd, t, &matches)
c.Expect(matches, ContainsExactly, idiotStringSearch(p, t))
}
})
c.Specify("Random test", func() {
var matches []int
for i := 0; i < 10000; i += 2 {
p := makeTestString4(15, 7, i)
t := makeTestString4(1000, 7, i+1)
bmd := core.BoyerMoorePreprocess(p)
matches = matches[0:0]
core.BoyerMoore(bmd, t, &matches)
c.Expect(matches, ContainsExactly, idiotStringSearch(p, t))
}
})
}
示例5: Find
// Preprocesses p and returns a *StringFinder that can be used to quickly
// search for occurrences of p in other strings. Uses Boyer-Moore, which
// requires O(n) time to preprocess p, and O(n) space to store the result.
// Methods on StringFinder can be called concurrently from multiple
// go-routines.
func Find(p []byte) *StringFinder {
return &StringFinder{bmd: core.BoyerMoorePreprocess(p)}
}