github.com/egonelbre/exp@v0.0.0-20240430123955-ed1d3aa93911/chem/element/matcher.go (about) 1 package element 2 3 const maxlen = 64 4 5 type Matcher struct { 6 srclen byte 7 src [maxlen]byte 8 trace [maxlen]Element 9 10 count int 11 } 12 13 func (m *Matcher) Init(word string) { 14 copy(m.src[:], []byte(word)) 15 copy(m.src[len(word):len(word)+5], []byte{0, 0, 0, 0, 0}) 16 m.srclen = byte(len(word)) 17 m.count = 0 18 } 19 20 func (m *Matcher) emit(tracelen byte) { 21 m.count++ 22 } 23 24 func (m *Matcher) Run() { m.acceptElement(0, 0) } 25 26 func (m *Matcher) accepted(e Element, p, t byte) { 27 m.trace[t] = e 28 if p < m.srclen { 29 m.acceptElement(p, t+1) 30 } else if p == m.srclen { 31 m.emit(t) 32 } 33 }