iohub / ahocorasick

A fast and memory efficient implementation of aho-corasick algorithm based on double-array trie (cedar), supports visualizing structure via graphviz.
GNU General Public License v2.0
115 stars 20 forks source link

MItem's Freq property is always 0 #2

Closed mateuszjurewicz closed 6 years ago

mateuszjurewicz commented 6 years ago

Hi,

When you look at https://godoc.org/github.com/iohub/Ahocorasick#MItem the MItem should have a Freq property, which one would assume is the frequency of occurrence, but when you look at the code here:

https://github.com/iohub/Ahocorasick/blob/master/acmatcher.go

it actually only ever takes the default 0 value for undefined ints:

func (m *Matcher) mItemOf(seq []byte, offset, id int) []MItem {
    req := []MItem{}
    for e := &m.output[id]; e != nil; e = e.Link {
        nval := m.da.vals[e.vKey]
        len := nval.len
        val := nval.Value
        if len == 0 {
            continue
        }
        bs := seq[offset-len+1 : offset+1]
        req = append(req, MItem{Key: bs, Value: val})
    }
    return req
}

I could be wrong, I am new to Go, but it seems misleading.

Cheers! M

iohub commented 6 years ago

Thanks for yours feedback, you are right. MItem's Freq property is always 0, and the propery is never used by my toy implementation. I am also new to Go, this is just a simple demo for learning, but I am trying to improve the quality in my spare time, sorry for this misleading and i'll fix them. thank you for your reminding.