MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / mismatch_in_text

Method mismatch_in_text

strings/boyer_moore_search.py:57–77  ·  view source on GitHub ↗

Find the index of mis-matched character in text when compared with pattern from last. Parameters : current_pos (int): current index position of text Returns : i (int): index of mismatched char from last in text -1 (int): if there

(self, current_pos: int)

Source from the content-addressed store, hash-verified

55 return -1
56
57 def mismatch_in_text(self, current_pos: int) -> int:
58 """
59 Find the index of mis-matched character in text when compared with pattern
60 from last.
61
62 Parameters :
63 current_pos (int): current index position of text
64
65 Returns :
66 i (int): index of mismatched char from last in text
67 -1 (int): if there is no mismatch between pattern and text block
68
69 >>> bms = BoyerMooreSearch(text="ABAABA", pattern="AB")
70 >>> bms.mismatch_in_text(2)
71 3
72 """
73
74 for i in range(self.patLen - 1, -1, -1):
75 if self.pattern[i] != self.text[current_pos + i]:
76 return current_pos + i
77 return -1
78
79 def bad_character_heuristic(self) -> list[int]:
80 """

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected