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

Method match_in_pattern

strings/boyer_moore_search.py:36–55  ·  view source on GitHub ↗

Finds the index of char in pattern in reverse order. Parameters : char (chr): character to be searched Returns : i (int): index of char from last in pattern -1 (int): if char is not found in pattern >>> bms = BoyerMooreSearch(te

(self, char: str)

Source from the content-addressed store, hash-verified

34 self.textLen, self.patLen = len(text), len(pattern)
35
36 def match_in_pattern(self, char: str) -> int:
37 """
38 Finds the index of char in pattern in reverse order.
39
40 Parameters :
41 char (chr): character to be searched
42
43 Returns :
44 i (int): index of char from last in pattern
45 -1 (int): if char is not found in pattern
46
47 >>> bms = BoyerMooreSearch(text="ABAABA", pattern="AB")
48 >>> bms.match_in_pattern("B")
49 1
50 """
51
52 for i in range(self.patLen - 1, -1, -1):
53 if char == self.pattern[i]:
54 return i
55 return -1
56
57 def mismatch_in_text(self, current_pos: int) -> int:
58 """

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected