Use new unique append to check if unique states have been added to tempStates

master
Aadhavan Srinivasan 2 months ago
parent 3984c54080
commit fe5c94b4df

@ -62,12 +62,16 @@ func findAllMatchesHelper(start *State, str string, indices []matchIndex, offset
zeroStates := make([]*State, 0) zeroStates := make([]*State, 0)
// Keep taking zero-states, until there are no more left to take // 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) zeroStates, isZero := takeZeroState(currentStates)
tempStates = append(tempStates, zeroStates...) tempStates = append(tempStates, zeroStates...)
num_appended := 0
for isZero == true { for isZero == true {
zeroStates, isZero = takeZeroState(tempStates) 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...) 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. // This is the exact same algorithm used inside the loop, so I should probably put it in a function.
zeroStates, isZero := takeZeroState(currentStates) zeroStates, isZero := takeZeroState(currentStates)
tempStates = append(tempStates, zeroStates...) tempStates = append(tempStates, zeroStates...)
num_appended := 0 // Number of unique states addded to tempStates
for isZero == true { for isZero == true {
zeroStates, isZero = takeZeroState(tempStates) 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...) currentStates = append(currentStates, tempStates...)

Loading…
Cancel
Save