



"""simple docstring"""






_lowercase			:			Dict										=						2_5_6
# Modulus to hash a string
_lowercase			:			Union[str, Any]										=						1_0_0_0_0_0_3






def 					snake_case__       (		__lowerCamelCase    :   str							,		__lowerCamelCase    :   str     ):
			"""simple docstring"""
			lowerCamelCase__		:		List[str]		     =len(lowerCAmelCase__     )
			lowerCamelCase__		:		List[str]		     =len(lowerCAmelCase__     )
			if p_len > t_len:
						return False

			lowerCamelCase__		:		List[Any]		     =0
			lowerCamelCase__		:		str		     =0
			lowerCamelCase__		:		Optional[Any]		     =1

			# Calculating the hash of pattern and substring of text
			for i in range(lowerCAmelCase__     ):
						lowerCamelCase__		:		Optional[int]		     =(ord(pattern[i]     ) + p_hash * alphabet_size) % modulus
						lowerCamelCase__		:		List[Any]		     =(ord(text[i]     ) + text_hash * alphabet_size) % modulus
						if i == p_len - 1:
									continue
						lowerCamelCase__		:		Tuple		     =(modulus_power * alphabet_size) % modulus

			for i in range(0							,		t_len - p_len + 1     ):
						if text_hash == p_hash and text[i : i + p_len] == pattern:
									return True
						if i == t_len - p_len:
									continue
						# Calculate the https://en.wikipedia.org/wiki/Rolling_hash
						lowerCamelCase__		:		str		     =(
						    (text_hash - ord(text[i]     ) * modulus_power) * alphabet_size
						    + ord(text[i + p_len]     )
						) % modulus
			return False






def 					snake_case__       (		):
			"""simple docstring"""
			lowerCamelCase__		:		List[Any]		     ='''abc1abc12'''
			lowerCamelCase__		:		Optional[Any]		     ='''alskfjaldsabc1abc1abc12k23adsfabcabc'''
			lowerCamelCase__		:		Dict		     ='''alskfjaldsk23adsfabcabc'''
			assert rabin_karp(lowerCAmelCase__							,		lowerCAmelCase__     ) and not rabin_karp(lowerCAmelCase__							,		lowerCAmelCase__     )

			# Test 2)
			lowerCamelCase__		:		str		     ='''ABABX'''
			lowerCamelCase__		:		List[Any]		     ='''ABABZABABYABABX'''
			assert rabin_karp(lowerCAmelCase__							,		lowerCAmelCase__     )

			# Test 3)
			lowerCamelCase__		:		Optional[int]		     ='''AAAB'''
			lowerCamelCase__		:		Optional[int]		     ='''ABAAAAAB'''
			assert rabin_karp(lowerCAmelCase__							,		lowerCAmelCase__     )

			# Test 4)
			lowerCamelCase__		:		Any		     ='''abcdabcy'''
			lowerCamelCase__		:		List[Any]		     ='''abcxabcdabxabcdabcdabcy'''
			assert rabin_karp(lowerCAmelCase__							,		lowerCAmelCase__     )

			# Test 5)
			lowerCamelCase__		:		Union[str, Any]		     ='''Lü'''
			lowerCamelCase__		:		int		     ='''Lüsai'''
			assert rabin_karp(lowerCAmelCase__							,		lowerCAmelCase__     )
			lowerCamelCase__		:		List[str]		     ='''Lue'''
			assert not rabin_karp(lowerCAmelCase__							,		lowerCAmelCase__     )
			print('''Success.'''     )


if __name__ == "__main__":
				test_rabin_karp()









"""simple docstring"""






from ..utils import DummyObject, requires_backends

class 	__SCREAMING_SNAKE_CASE     (				metaclass=lowerCAmelCase_       ):


					'''simple docstring'''





					_a             =							['torch', 'torchsde']



					def __init__(	self							:  Union[str, Any],  *lowerCamelCase							:  str,  **lowerCamelCase							:  int					)-> Tuple:
								requires_backends(self,  ['''torch''', '''torchsde''']					)



					@classmethod
					def 		snake_case	(	cls							:  List[str],  *lowerCamelCase							:  Optional[Any],  **lowerCamelCase							:  Dict					)-> str:
								requires_backends(cls,  ['''torch''', '''torchsde''']					)




					@classmethod
					def 		snake_case	(	cls							:  Tuple,  *lowerCamelCase							:  Dict,  **lowerCamelCase							:  Tuple					)-> List[str]:
								requires_backends(cls,  ['''torch''', '''torchsde''']					)




