Skip to content

Commit

Permalink
changed equality check of states
Browse files Browse the repository at this point in the history
  • Loading branch information
ikawaha committed Nov 24, 2014
1 parent 89207d5 commit b8c07e0
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions si/mast.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,12 @@ func commonPrefixLen(a, b string) int {
return i
}

func buildMast(input PairSlice) (m *mast) {
func buildMast(input PairSlice) (m *mast) { //XXX TODO private
sort.Sort(input)

//fmt.Println("sorted---") //XXX
const initialMastSize = 1024
m = new(mast)
dic := make(map[uint][]*state)
m.states = make([]*state, 0, initialMastSize)
m.finalStates = make([]*state, 0, initialMastSize)

Expand All @@ -53,29 +54,25 @@ func buildMast(input PairSlice) (m *mast) {
}
prev := ""
for _, pair := range input {
//fmt.Println(pair) //XXX
in, out := pair.In, pair.Out
prefixLen := commonPrefixLen(in, prev)
candidate := m.finalStates
for i := len(prev); i > prefixLen; i-- {
var s *state
detected := false
if candidate != nil {
for _, c := range candidate {
if cs, ok := dic[buf[i].hcode]; ok {
for _, c := range cs {
if c.eq(buf[i]) {
buf[i].renew()
s = c
candidate = c.Prev
detected = true
break
}
}
}
if !detected {
candidate = nil
if s == nil {
s = &state{}
*s = *buf[i]
buf[i].renew()
m.addState(s)
dic[s.hcode] = append(dic[s.hcode], s)
}
buf[i-1].setTransition(prev[i-1], s)
s.setInvTransition()
Expand Down

0 comments on commit b8c07e0

Please sign in to comment.