You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
//If a character matches in the linear-sequenced analysis of needle, we will check the next char of it
if (haystack.charAt(pos) == needle.charAt(needlePos)) {
needlePos++;
if (needlePos == NL) returnret;
}
else {
//If there are any other positions where I can backtrack to...
if (vectorPos > 0) {
vectorPos--;
pos = vector[vectorPos]; //This position is alreay checked, line 36 will move us to the next character
ret = pos; //ret is the start of what we believe is the substring needle in haystack
needlePos = 1; //Since position 0 of needle is already checked
}
else {
pos = auxPos; //We go back to the forgotten position from which we started backtracking (see line 37)
ret = pos+1; //auxPos is actually an already checked position (we backtrack when comparison between strings breaks), so the position we may return will be the next one. If we get to this portion of code, it means that there are no already-visited chars thay may start the substring needle, only new characters from haystack
if (needlePos != 0) needlePos = 0;
}
}
pos++; // <-- line 36, we always move the position of haystack
auxPos = pos; // <-- line 37, since we may backtrack in the future, we need to store the forgotten value of position (auxPos), so we don't repeat steps and go back to it