'''simple docstring'''


import pytest

from datasets.parallel import ParallelBackendConfig, parallel_backend
from datasets.utils.py_utils import map_nested

from .utils import require_dill_gt_0_3_2, require_joblibspark, require_not_windows


def  _lowerCamelCase   (				lowerCamelCase_ :							Any       ):  # picklable for multiprocessing



     """simple docstring"""





     return i + 1


@require_dill_gt_0_3_2
@require_joblibspark
@require_not_windows
def  _lowerCamelCase   (				):



     """simple docstring"""





     with parallel_backend('spark'       ):
          assert ParallelBackendConfig.backend_name == "spark"

     UpperCAmelCase_							:       int       =				[1, 2, 3]
     with pytest.raises(lowerCamelCase_       ):
          with parallel_backend('unsupported backend'       ):
               map_nested(lowerCamelCase_     ,					lowerCamelCase_     ,					num_proc=2       )

     with pytest.raises(lowerCamelCase_       ):
          with parallel_backend('unsupported backend'       ):
               map_nested(lowerCamelCase_     ,					lowerCamelCase_     ,					num_proc=-1       )





@require_dill_gt_0_3_2
@require_joblibspark
@require_not_windows
@pytest.mark.parametrize('num_proc'     ,					[2, -1]       )
def  _lowerCamelCase   (				lowerCamelCase_ :							Dict       ):



     """simple docstring"""





     UpperCAmelCase_							:       int       =				[1, 2]
     UpperCAmelCase_							:       Optional[int]       =				{'a': 1, 'b': 2}
     UpperCAmelCase_							:       Tuple       =				{'a': [1, 2], 'b': [3, 4]}
     UpperCAmelCase_							:       List[Any]       =				{'a': {'1': 1}, 'b': 2}
     UpperCAmelCase_							:       List[str]       =				{'a': 1, 'b': 2, 'c': 3, 'd': 4}
     UpperCAmelCase_							:       Tuple       =				[2, 3]
     UpperCAmelCase_							:       Tuple       =				{'a': 2, 'b': 3}
     UpperCAmelCase_							:       Optional[int]       =				{'a': [2, 3], 'b': [4, 5]}
     UpperCAmelCase_							:       Any       =				{'a': {'1': 2}, 'b': 3}
     UpperCAmelCase_							:       Any       =				{'a': 2, 'b': 3, 'c': 4, 'd': 5}

     with parallel_backend('spark'       ):
          assert map_nested(lowerCamelCase_     ,					lowerCamelCase_     ,					num_proc=lowerCamelCase_       ) == expected_map_nested_sa
          assert map_nested(lowerCamelCase_     ,					lowerCamelCase_     ,					num_proc=lowerCamelCase_       ) == expected_map_nested_sa
          assert map_nested(lowerCamelCase_     ,					lowerCamelCase_     ,					num_proc=lowerCamelCase_       ) == expected_map_nested_sa
          assert map_nested(lowerCamelCase_     ,					lowerCamelCase_     ,					num_proc=lowerCamelCase_       ) == expected_map_nested_sa
          assert map_nested(lowerCamelCase_     ,					lowerCamelCase_     ,					num_proc=lowerCamelCase_       ) == expected_map_nested_sa







'''simple docstring'''


def  _lowerCamelCase   (				lowerCamelCase_ :							str       ):



     """simple docstring"""





     UpperCAmelCase_							:       Optional[int]       =				[0] * len(lowerCamelCase_       )

     for i in range(1     ,					len(lowerCamelCase_       )       ):
          # use last results for better performance - dynamic programming
          UpperCAmelCase_							:       List[Any]       =				prefix_result[i - 1]
          while j > 0 and input_string[i] != input_string[j]:
               UpperCAmelCase_							:       str       =				prefix_result[j - 1]

          if input_string[i] == input_string[j]:
               j += 1
          UpperCAmelCase_							:       Any       =				j

     return prefix_result


def  _lowerCamelCase   (				lowerCamelCase_ :							str       ):



     """simple docstring"""





     return max(prefix_function(lowerCamelCase_       )       )


if __name__ == "__main__":
 import doctest

 doctest.testmod()






