



'''simple docstring'''
import logging
import os
from logging import (
    CRITICAL,  # NOQA
    DEBUG,  # NOQA
    ERROR,  # NOQA
    FATAL,  # NOQA
    INFO,  # NOQA
    NOTSET,  # NOQA
    WARN,  # NOQA
    WARNING,  # NOQA
)
from typing import Optional

from tqdm import auto as tqdm_lib


snake_case_					:      Optional[int]    			=    {
    'debug': logging.DEBUG,
    'info': logging.INFO,
    'warning': logging.WARNING,
    'error': logging.ERROR,
    'critical': logging.CRITICAL,
}

snake_case_					:      List[str]    			=    logging.WARNING






def A__       (	):
						_UpperCamelCase   :						Union[str, Any]												=  os.getenv('DATASETS_VERBOSITY'    ,    _snake_case				)
						if env_level_str:
												if env_level_str in log_levels:
																		return log_levels[env_level_str]
												else:
																		logging.getLogger().warning(
																		    f'Unknown option DATASETS_VERBOSITY={env_level_str}, '
																		    f'has to be one of: { ", ".join(log_levels.keys()				) }'				)
						return _default_log_level






def A__       (	):
						return __name__.split('.'				)[0]






def A__       (	):
						return logging.getLogger(_get_library_name()				)






def A__       (	):
						_UpperCamelCase   :						Union[str, Any]												=  _get_library_root_logger()
						library_root_logger.setLevel(_get_default_logging_level()				)






def A__       (	):
						_UpperCamelCase   :						Dict												=  _get_library_root_logger()
						library_root_logger.setLevel(logging.NOTSET				)






def A__       (	UpperCAmelCase_ = None				):


						if name is None:
												_UpperCamelCase   :						str												=  _get_library_name()
						return logging.getLogger(_snake_case				)






def A__       (	):
						return _get_library_root_logger().getEffectiveLevel()






def A__       (	UpperCAmelCase_				):
						_get_library_root_logger().setLevel(_snake_case				)






def A__       (	):
						return set_verbosity(_snake_case				)






def A__       (	):
						return set_verbosity(_snake_case				)






def A__       (	):
						return set_verbosity(_snake_case				)






def A__       (	):
						return set_verbosity(_snake_case				)






def A__       (	):
						_UpperCamelCase   :						Any												=  False






def A__       (	):
						_UpperCamelCase   :						List[str]												=  True


# Configure the library root logger at the module level (singleton-like)
_configure_library_root_logger()






class 				lowercase__      :





	def __init__(					self   :							int					,*lowerCamelCase__   :							str					,**lowerCamelCase__   :							Union[str, Any]					):  # pylint: disable=unused-argument







							'''simple docstring'''
							_UpperCamelCase   :						Tuple												=  args[0] if args else None





	def __iter__(					self   :							Optional[int]					):







							'''simple docstring'''
							return iter(self._iterator					)





	def __getattr__(					self   :							Tuple					,lowerCamelCase__   :							str					):







							'''simple docstring'''

							def empty_fn(*lowerCamelCase__   :							List[str]					,**lowerCamelCase__   :							List[str]					):  # pylint: disable=unused-argument
													return

							return empty_fn





	def __enter__(					self   :							List[str]					):







							'''simple docstring'''
							return self





	def __exit__(					self   :							Optional[int]					,lowerCamelCase__   :							Any					,lowerCamelCase__   :							Dict					,lowerCamelCase__   :							Any					):







							'''simple docstring'''
							return
snake_case_					:      Optional[Any]    			=    True






class 				lowercase__      :





	def __call__(					self   :							Optional[Any]					,*lowerCamelCase__   :							Tuple					,lowerCamelCase__   :							Union[str, Any]=False					,**lowerCamelCase__   :							Optional[Any]					):







							'''simple docstring'''
							if _tqdm_active and not disable:
													return tqdm_lib.tqdm(*UpperCAmelCase_					,**UpperCAmelCase_					)
							else:
													return EmptyTqdm(*UpperCAmelCase_					,**UpperCAmelCase_					)





	def       UpperCamelCase_    (					self   :							Tuple					,*lowerCamelCase__   :							Union[str, Any]					,**lowerCamelCase__   :							Optional[int]					):







							'''simple docstring'''
							_UpperCamelCase   :						Optional[Any]												=  None
							if _tqdm_active:
													return tqdm_lib.tqdm.set_lock(*UpperCAmelCase_					,**UpperCAmelCase_					)





	def       UpperCamelCase_    (					self   :							Optional[Any]					):







							'''simple docstring'''
							if _tqdm_active:
													return tqdm_lib.tqdm.get_lock()
snake_case_					:      List[Any]    			=    _tqdm_cls()






def A__       (	):
						global _tqdm_active
						return bool(_tqdm_active				)






def A__       (	):
						global _tqdm_active
						_UpperCamelCase   :						List[str]												=  True






def A__       (	):
						global _tqdm_active
						_UpperCamelCase   :						str												=  False







'''simple docstring'''





SCREAMING_SNAKE_CASE__          =  256
# Modulus to hash a string
SCREAMING_SNAKE_CASE__          =  100_0003




def 							lowerCamelCase	(					_snake_case	:    str  ,_snake_case	:    str							):





    '''simple docstring'''


    lowercase__									=    len(_snake_case							)
    lowercase__									=    len(_snake_case							)
    if p_len > t_len:
        return False

    lowercase__									=    0
    lowercase__									=    0
    lowercase__									=    1

    # Calculating the hash of pattern and substring of text
    for i in range(_snake_case							):
        lowercase__									=    (ord(pattern[i]							) + p_hash * alphabet_size) % modulus
        lowercase__									=    (ord(text[i]							) + text_hash * alphabet_size) % modulus
        if i == p_len - 1:
            continue
        lowercase__									=    (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
        lowercase__									=    (
            (text_hash - ord(text[i]							) * modulus_power) * alphabet_size
            + ord(text[i + p_len]							)
        ) % modulus
    return False




def 							lowerCamelCase	(					):





    '''simple docstring'''


    lowercase__									=    "abc1abc12"
    lowercase__									=    "alskfjaldsabc1abc1abc12k23adsfabcabc"
    lowercase__									=    "alskfjaldsk23adsfabcabc"
    assert rabin_karp(_snake_case  ,_snake_case							) and not rabin_karp(_snake_case  ,_snake_case							)

    # Test 2)
    lowercase__									=    "ABABX"
    lowercase__									=    "ABABZABABYABABX"
    assert rabin_karp(_snake_case  ,_snake_case							)

    # Test 3)
    lowercase__									=    "AAAB"
    lowercase__									=    "ABAAAAAB"
    assert rabin_karp(_snake_case  ,_snake_case							)

    # Test 4)
    lowercase__									=    "abcdabcy"
    lowercase__									=    "abcxabcdabxabcdabcdabcy"
    assert rabin_karp(_snake_case  ,_snake_case							)

    # Test 5)
    lowercase__									=    "Lü"
    lowercase__									=    "Lüsai"
    assert rabin_karp(_snake_case  ,_snake_case							)
    lowercase__									=    "Lue"
    assert not rabin_karp(_snake_case  ,_snake_case							)
    print("Success."							)


if __name__ == "__main__":
 test_rabin_karp()




