"""simple docstring"""





_UpperCamelCase   :						List[Any]      =    2_56
# Modulus to hash a string
_UpperCamelCase   :						List[Any]      =    1_00_00_03





def 				a_     (      _lowerCAmelCase  : str   , _lowerCAmelCase  : str     ):





       '''simple docstring'''

       lowercase__			:		List[Any]       =	len(_lowerCAmelCase     )
       lowercase__			:		Dict       =	len(_lowerCAmelCase     )
       if p_len > t_len:
              return False

       lowercase__			:		Tuple       =	0
       lowercase__			:		Dict       =	0
       lowercase__			:		int       =	1

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





def 				a_     (      ):





       '''simple docstring'''

       lowercase__			:		Optional[Any]       =	'abc1abc12'
       lowercase__			:		Dict       =	'alskfjaldsabc1abc1abc12k23adsfabcabc'
       lowercase__			:		Optional[Any]       =	'alskfjaldsk23adsfabcabc'
       assert rabin_karp(_lowerCAmelCase   , _lowerCAmelCase     ) and not rabin_karp(_lowerCAmelCase   , _lowerCAmelCase     )

       # Test 2)
       lowercase__			:		List[str]       =	'ABABX'
       lowercase__			:		Optional[Any]       =	'ABABZABABYABABX'
       assert rabin_karp(_lowerCAmelCase   , _lowerCAmelCase     )

       # Test 3)
       lowercase__			:		Union[str, Any]       =	'AAAB'
       lowercase__			:		Optional[Any]       =	'ABAAAAAB'
       assert rabin_karp(_lowerCAmelCase   , _lowerCAmelCase     )

       # Test 4)
       lowercase__			:		Tuple       =	'abcdabcy'
       lowercase__			:		List[str]       =	'abcxabcdabxabcdabcdabcy'
       assert rabin_karp(_lowerCAmelCase   , _lowerCAmelCase     )

       # Test 5)
       lowercase__			:		int       =	'Lü'
       lowercase__			:		List[str]       =	'Lüsai'
       assert rabin_karp(_lowerCAmelCase   , _lowerCAmelCase     )
       lowercase__			:		Dict       =	'Lue'
       assert not rabin_karp(_lowerCAmelCase   , _lowerCAmelCase     )
       print('Success.'     )


if __name__ == "__main__":
       test_rabin_karp()









from abc import ABC, abstractmethod
from typing import Optional, Union

from .. import Dataset, DatasetDict, Features, IterableDataset, IterableDatasetDict, NamedSplit
from ..utils.typing import NestedDataStructureLike, PathLike
class     a    ( lowercase__   ):



      """simple docstring"""


      def __init__(      self					:			Any		,      __lowercase					:			Optional[NestedDataStructureLike[PathLike]] = None		,      __lowercase					:			Optional[NamedSplit] = None		,      __lowercase					:			Optional[Features] = None		,      __lowercase					:			str = None		,      __lowercase					:			bool = False		,      __lowercase					:			bool = False		,      __lowercase					:			Optional[int] = None		,      **__lowercase					:			List[str]		,      )							->      Tuple:
        __UpperCAmelCase							:	Any           =  path_or_paths
        __UpperCAmelCase							:	Dict           =  split if split or isinstance(__lowercase		,      __lowercase					) else """train"""
        __UpperCAmelCase							:	Optional[int]           =  features
        __UpperCAmelCase							:	str           =  cache_dir
        __UpperCAmelCase							:	str           =  keep_in_memory
        __UpperCAmelCase							:	Optional[int]           =  streaming
        __UpperCAmelCase							:	Dict           =  num_proc
        __UpperCAmelCase							:	Tuple           =  kwargs




      @abstractmethod
      def 	UpperCAmelCase      (      self					:			List[Any]					)							->      Union[Dataset, DatasetDict, IterableDataset, IterableDatasetDict]:
        pass


class     a    ( lowercase__   ):



      """simple docstring"""


      def __init__(      self					:			List[str]		,      __lowercase					:			Optional[Features] = None		,      __lowercase					:			str = None		,      __lowercase					:			bool = False		,      __lowercase					:			bool = False		,      __lowercase					:			Optional[int] = None		,      **__lowercase					:			Optional[Any]		,      )							->      Optional[int]:
        __UpperCAmelCase							:	Optional[Any]           =  features
        __UpperCAmelCase							:	str           =  cache_dir
        __UpperCAmelCase							:	Optional[int]           =  keep_in_memory
        __UpperCAmelCase							:	Dict           =  streaming
        __UpperCAmelCase							:	Optional[Any]           =  num_proc
        __UpperCAmelCase							:	Union[str, Any]           =  kwargs




      @abstractmethod
      def 	UpperCAmelCase      (      self					:			List[str]					)							->      Union[Dataset, IterableDataset]:
        pass


