...
1
2
3
4
5 package colltab
6
7
8 type testWeighter map[string][]Elem
9
10 func (t testWeighter) Start(int, []byte) int { return 0 }
11 func (t testWeighter) StartString(int, string) int { return 0 }
12 func (t testWeighter) Domain() []string { return nil }
13 func (t testWeighter) Top() uint32 { return 0 }
14
15
16 const maxContractBytes = 10
17
18 func (t testWeighter) AppendNext(buf []Elem, s []byte) ([]Elem, int) {
19 n := len(s)
20 if n > maxContractBytes {
21 n = maxContractBytes
22 }
23 for i := n; i > 0; i-- {
24 if e, ok := t[string(s[:i])]; ok {
25 return append(buf, e...), i
26 }
27 }
28 panic("incomplete testWeighter: could not find " + string(s))
29 }
30
31 func (t testWeighter) AppendNextString(buf []Elem, s string) ([]Elem, int) {
32 n := len(s)
33 if n > maxContractBytes {
34 n = maxContractBytes
35 }
36 for i := n; i > 0; i-- {
37 if e, ok := t[s[:i]]; ok {
38 return append(buf, e...), i
39 }
40 }
41 panic("incomplete testWeighter: could not find " + s)
42 }
43
View as plain text