


from collections.abc import Callable




class A  :






      def __init__(					self						:     List[Any]			,   lowercase_						:     Callable | None = None )					->						None:
             """simple docstring"""




             _lowerCamelCase       :		list		=[]
             # Stores indexes of each item for supporting updates and deletion.
             _lowerCamelCase       :		dict		={}
             # Stores current size of heap.
             _lowerCamelCase       :		int		=0
             # Stores function used to evaluate the score of an item on which basis ordering
             # will be done.
             _lowerCamelCase       :		List[str]		=key or (lambda lowercase_ : x)






      def        lowerCamelCase       (					self						:     Tuple			,   lowercase_						:     int )					->						int | None:
             """simple docstring"""




             return int((i - 1) / 2 ) if i > 0 else None






      def        lowerCamelCase       (					self						:     str			,   lowercase_						:     int )					->						int | None:
             """simple docstring"""




             _lowerCamelCase       :		Any		=int(2 * i + 1 )
             return left if 0 < left < self.size else None






      def        lowerCamelCase       (					self						:     Optional[int]			,   lowercase_						:     int )					->						int | None:
             """simple docstring"""




             _lowerCamelCase       :		Tuple		=int(2 * i + 2 )
             return right if 0 < right < self.size else None






      def        lowerCamelCase       (					self						:     Tuple			,   lowercase_						:     int			,   lowercase_						:     int )					->						None:
             """simple docstring"""




             _lowerCamelCase	,     _lowerCamelCase       :		Union[str, Any]		=(
                 self.pos_map[self.arr[j][0]],
                 self.pos_map[self.arr[i][0]],
             )
             # Then swap the items in the list.
             _lowerCamelCase	,     _lowerCamelCase       :		List[str]		=self.arr[j], self.arr[i]






      def        lowerCamelCase       (					self						:     Optional[int]			,   lowercase_						:     int			,   lowercase_						:     int )					->						bool:
             """simple docstring"""




             return self.arr[i][1] < self.arr[j][1]






      def        lowerCamelCase       (					self						:     str			,   lowercase_						:     int )					->						int:
             """simple docstring"""




             _lowerCamelCase       :		List[str]		=self._left(lowercase_ )
             _lowerCamelCase       :		Optional[int]		=self._right(lowercase_ )
             _lowerCamelCase       :		List[Any]		=i

             if left is not None and not self._cmp(lowercase_			,   lowercase_ ):
                    _lowerCamelCase       :		str		=left
             if right is not None and not self._cmp(lowercase_			,   lowercase_ ):
                    _lowerCamelCase       :		List[str]		=right

             return valid_parent






      def        lowerCamelCase       (					self						:     Union[str, Any]			,   lowercase_						:     int )					->						None:
             """simple docstring"""




             _lowerCamelCase       :		Optional[Any]		=self._parent(lowercase_ )
             while parent is not None and not self._cmp(lowercase_			,   lowercase_ ):
                    self._swap(lowercase_			,   lowercase_ )
                    _lowerCamelCase	,     _lowerCamelCase       :		Tuple		=parent, self._parent(lowercase_ )






      def        lowerCamelCase       (					self						:     int			,   lowercase_						:     int )					->						None:
             """simple docstring"""




             _lowerCamelCase       :		List[str]		=self._get_valid_parent(lowercase_ )
             while valid_parent != index:
                    self._swap(lowercase_			,   lowercase_ )
                    _lowerCamelCase	,     _lowerCamelCase       :		List[str]		=valid_parent, self._get_valid_parent(lowercase_ )






      def        lowerCamelCase       (					self						:     Optional[int]			,   lowercase_						:     int			,   lowercase_						:     int )					->						None:
             """simple docstring"""




             if item not in self.pos_map:
                    return
             _lowerCamelCase       :		int		=self.pos_map[item]
             _lowerCamelCase       :		Dict		=[item, self.key(lowercase_ )]
             # Make sure heap is right in both up and down direction.
             # Ideally only one of them will make any change.
             self._heapify_up(lowercase_ )
             self._heapify_down(lowercase_ )






      def        lowerCamelCase       (					self						:     Optional[int]			,   lowercase_						:     int )					->						None:
             """simple docstring"""




             if item not in self.pos_map:
                    return
             _lowerCamelCase       :		Optional[Any]		=self.pos_map[item]
             del self.pos_map[item]
             _lowerCamelCase       :		Dict		=self.arr[self.size - 1]
             _lowerCamelCase       :		int		=index
             self.size -= 1
             # Make sure heap is right in both up and down direction. Ideally only one
             # of them will make any change- so no performance loss in calling both.
             if self.size > index:
                    self._heapify_up(lowercase_ )
                    self._heapify_down(lowercase_ )






      def        lowerCamelCase       (					self						:     List[Any]			,   lowercase_						:     int			,   lowercase_						:     int )					->						None:
             """simple docstring"""




             _lowerCamelCase       :		Optional[Any]		=len(self.arr )
             if arr_len == self.size:
                    self.arr.append([item, self.key(lowercase_ )] )
             else:
                    _lowerCamelCase       :		Optional[int]		=[item, self.key(lowercase_ )]
             _lowerCamelCase       :		Dict		=self.size
             self.size += 1
             self._heapify_up(self.size - 1 )






      def        lowerCamelCase       (					self						:     Tuple )					->						tuple | None:
             """simple docstring"""




             return self.arr[0] if self.size else None






      def        lowerCamelCase       (					self						:     Optional[Any] )					->						tuple | None:
             """simple docstring"""




             _lowerCamelCase       :		int		=self.get_top()
             if top_item_tuple:
                    self.delete_item(top_item_tuple[0] )
             return top_item_tuple




def 	a_      (    ):
       '''simple docstring'''







if __name__ == "__main__":
 import doctest

 doctest.testmod()






import os
import sys
import unittest


lowerCamelCase											=       os.path.abspath(os.path.dirname(os.path.dirname(os.path.dirname(__file__))))
sys.path.append(os.path.join(git_repo_path, 'utils'))

import check_dummies  # noqa: E402
from check_dummies import create_dummy_files, create_dummy_object, find_backend, read_init  # noqa: E402


# Align TRANSFORMERS_PATH in check_dummies with the current path
lowerCamelCase											=       os.path.join(git_repo_path, 'src', 'transformers')

lowerCamelCase											=       '\n{0} = None\n'

lowerCamelCase											=       '\nclass {0}(metaclass=DummyObject):\n    _backends = {1}\n\n    def __init__(self, *args, **kwargs):\n        requires_backends(self, {1})\n'


lowerCamelCase											=       '\ndef {0}(*args, **kwargs):\n    requires_backends({0}, {1})\n'




class A  (   unittest.TestCase     ):






      def        lowerCamelCase       (					self						:     Tuple )					->						Union[str, Any]:
             """simple docstring"""




             _lowerCamelCase       :		int		=find_backend('    _import_structure["models.albert"].append("AlbertTokenizerFast")' )
             self.assertIsNone(lowercase_ )

             _lowerCamelCase       :		List[str]		=find_backend('    if not is_tokenizers_available():' )
             self.assertEqual(lowercase_			,   'tokenizers' )

             _lowerCamelCase       :		List[Any]		=find_backend('    if not is_tensorflow_text_available():' )
             self.assertEqual(lowercase_			,   'tensorflow_text' )

             _lowerCamelCase       :		int		=find_backend('    if not (is_sentencepiece_available() and is_tokenizers_available()):' )
             self.assertEqual(lowercase_			,   'sentencepiece_and_tokenizers' )

             _lowerCamelCase       :		Dict		=find_backend(
                 '    if not (is_sentencepiece_available() and is_tensorflow_text_available()):' )
             self.assertEqual(lowercase_			,   'sentencepiece_and_tensorflow_text' )

             _lowerCamelCase       :		List[Any]		=find_backend(
                 '    if not (is_sentencepiece_available() and is_tokenizers_available() and is_vision_available()):' )
             self.assertEqual(lowercase_			,   'sentencepiece_and_tokenizers_and_vision' )






      def        lowerCamelCase       (					self						:     Optional[Any] )					->						List[str]:
             """simple docstring"""




             _lowerCamelCase       :		Union[str, Any]		=read_init()
             # We don't assert on the exact list of keys to allow for smooth grow of backend-specific objects
             self.assertIn('torch'			,   lowercase_ )
             self.assertIn('tensorflow_text'			,   lowercase_ )
             self.assertIn('sentencepiece_and_tokenizers'			,   lowercase_ )

             # Likewise, we can't assert on the exact content of a key
             self.assertIn('BertModel'			,   objects['torch'] )
             self.assertIn('TFBertModel'			,   objects['tf'] )
             self.assertIn('FlaxBertModel'			,   objects['flax'] )
             self.assertIn('BertModel'			,   objects['torch'] )
             self.assertIn('TFBertTokenizer'			,   objects['tensorflow_text'] )
             self.assertIn('convert_slow_tokenizer'			,   objects['sentencepiece_and_tokenizers'] )






      def        lowerCamelCase       (					self						:     int )					->						Optional[Any]:
             """simple docstring"""




             _lowerCamelCase       :		Optional[Any]		=create_dummy_object('CONSTANT'			,   '\'torch\'' )
             self.assertEqual(lowercase_			,   '\nCONSTANT = None\n' )

             _lowerCamelCase       :		Dict		=create_dummy_object('function'			,   '\'torch\'' )
             self.assertEqual(
                 lowercase_			,   '\ndef function(*args, **kwargs):\n    requires_backends(function, \'torch\')\n' )

             _lowerCamelCase       :		Union[str, Any]		='\nclass FakeClass(metaclass=DummyObject):\n    _backends = \'torch\'\n\n    def __init__(self, *args, **kwargs):\n        requires_backends(self, \'torch\')\n'
             _lowerCamelCase       :		Tuple		=create_dummy_object('FakeClass'			,   '\'torch\'' )
             self.assertEqual(lowercase_			,   lowercase_ )






      def        lowerCamelCase       (					self						:     List[Any] )					->						Dict:
             """simple docstring"""




             _lowerCamelCase       :		Dict		='# This file is autogenerated by the command `make fix-copies`, do not edit.\nfrom ..utils import DummyObject, requires_backends\n\n\nCONSTANT = None\n\n\ndef function(*args, **kwargs):\n    requires_backends(function, ["torch"])\n\n\nclass FakeClass(metaclass=DummyObject):\n    _backends = ["torch"]\n\n    def __init__(self, *args, **kwargs):\n        requires_backends(self, ["torch"])\n'
             _lowerCamelCase       :		Optional[int]		=create_dummy_files({'torch': ['CONSTANT', 'function', 'FakeClass']} )
             self.assertEqual(dummy_files['torch']			,   lowercase_ )


