Use new unique append to check if unique states have been added to tempStates
This commit is contained in:
14
matching.go
14
matching.go
@@ -62,12 +62,16 @@ func findAllMatchesHelper(start *State, str string, indices []matchIndex, offset
|
||||
|
||||
zeroStates := make([]*State, 0)
|
||||
// Keep taking zero-states, until there are no more left to take
|
||||
// Objective: If any of our current states have transitions to 0-states, replace them with the 0-state. Do this until there are no more transitions to 0-states
|
||||
// Objective: If any of our current states have transitions to 0-states, replace them with the 0-state. Do this until there are no more transitions to 0-states, or there are no more unique 0-states to take.
|
||||
zeroStates, isZero := takeZeroState(currentStates)
|
||||
tempStates = append(tempStates, zeroStates...)
|
||||
num_appended := 0
|
||||
for isZero == true {
|
||||
zeroStates, isZero = takeZeroState(tempStates)
|
||||
tempStates = append(tempStates, zeroStates...)
|
||||
tempStates, num_appended = unique_append(tempStates, zeroStates...)
|
||||
if num_appended == 0 { // Break if we haven't appended any more unique values
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
currentStates = append(currentStates, tempStates...)
|
||||
@@ -106,9 +110,13 @@ func findAllMatchesHelper(start *State, str string, indices []matchIndex, offset
|
||||
// This is the exact same algorithm used inside the loop, so I should probably put it in a function.
|
||||
zeroStates, isZero := takeZeroState(currentStates)
|
||||
tempStates = append(tempStates, zeroStates...)
|
||||
num_appended := 0 // Number of unique states addded to tempStates
|
||||
for isZero == true {
|
||||
zeroStates, isZero = takeZeroState(tempStates)
|
||||
tempStates = append(tempStates, zeroStates...)
|
||||
tempStates, num_appended = unique_append(tempStates, zeroStates...)
|
||||
if num_appended == 0 { // Break if we haven't appended any more unique values
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
currentStates = append(currentStates, tempStates...)
|
||||
|
Reference in New Issue
Block a user