From fe5c94b4df273a47e80ca98b8012236573d5db37 Mon Sep 17 00:00:00 2001 From: Aadhavan Srinivasan Date: Mon, 28 Oct 2024 09:40:41 -0400 Subject: [PATCH] Use new unique append to check if unique states have been added to tempStates --- matching.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/matching.go b/matching.go index 52e8b04..613d005 100644 --- a/matching.go +++ b/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...)