public int SearchChars(char[] text, int textStart, int textEnd, char[] pattern, CharIntMap processed) { char firstChar = pattern[0]; int secondChar = 1; char middleChar = pattern[pattern.Length / 2]; char lastChar = pattern[pattern.Length - 1]; int j = textStart; while (j <= text.Length - pattern.Length) { char c = text[j + (pattern.Length - 1)]; if ( // right most character of the pattern and the window are compared lastChar == c && // left most character of the pattern and the window are compared firstChar == text[j] && // the middle character of both pattern and the window are compared middleChar == text[j + pattern.Length / 2]) { while (secondChar < pattern.Length - 1 && pattern[secondChar] == text[j + secondChar]) { secondChar++; } if (secondChar == pattern.Length - 1) return j; } j += processed.Get(c); } return -1; }
public int SearchChars(char[] text, int textStart, int textEnd, char[] pattern, CharIntMap processed) { //CharIntMap b = processed; int d, j, pos, last; pos = textStart; while (pos <= textEnd - pattern.Length) { j = pattern.Length - 1; last = pattern.Length; d = -1; while (d != 0) { d &= processed.Get(text[pos + j]); if (d != 0) { if (j == 0) { return pos; } last = j; } --j; d <<= 1; } pos += last; } return -1; }
public int SearchChars(char[] text, int textStart, int textEnd, char[] pattern, CharIntMap processed) { CharIntMap td1 = processed; int p; for (int i = textStart; i <= textEnd - pattern.Length; i += p) { p = 0; int j; for (j = pattern.Length - 1; j >= 0; j--) { if (text[i + j] != pattern[j]) { p = j - td1.Get(text[i + j]); if (p < 1) p = 1; break; } } if (p == 0) { return i; } } return -1; }
public int SearchChars(char[] text, int textStart, int textEnd, char[] pattern, CharIntMap processed) { var bmBc = processed; int m = pattern.Length; int n = textEnd; if (textExtended == null) { shift = bmBc.Get(pattern[m - 1]); bmBc.Set(pattern[m - 1], 0); textExtended = new char[n + m]; Array.Copy(text, textExtended, n); int len = n; for (int i = 0; i < m; i++) textExtended[len + i] = pattern[m - 1]; } else { textStart = _resume; } // searching int j = textStart; int k = 0; while (j < n) { k = bmBc.Get(textExtended[j + m - 1]); while (k != 0) { j += k; k = bmBc.Get(textExtended[j + m - 1]); j += k; k = bmBc.Get(textExtended[j + m - 1]); j += k; k = bmBc.Get(textExtended[j + m - 1]); } if (Compare(textExtended, j, pattern) && j + m - 1 < n) { int i = j; j += shift; _resume = j; return i; } j += shift; } return -1; }
public int SearchChars(char[] text, int textStart, int textEnd, char[] pattern, CharIntMap processed) { CharIntMap map = processed; int skip = 0; bool isMatch; for (int i = textStart; i <= textEnd - pattern.Length; i = skip) { skip = i + pattern.Length - 1; isMatch = true; for (int j = pattern.Length - 1; j >= 0; j--) { if (text[i + j] != pattern[j]) { skip -= map.Get(text[skip]); isMatch = false; break; } } if (isMatch) return i; } return -1; }