



"""simple docstring"""




import os
import pickle
import unittest

from transformers import AutoTokenizer
from transformers.models.bert.tokenization_bert import BertTokenizer
from transformers.models.bert_japanese.tokenization_bert_japanese import (
    VOCAB_FILES_NAMES,
    BertJapaneseTokenizer,
    CharacterTokenizer,
    JumanppTokenizer,
    MecabTokenizer,
    SudachiTokenizer,
    WordpieceTokenizer,
)
from transformers.testing_utils import custom_tokenizers, require_jumanpp, require_sudachi

from ...test_tokenization_common import TokenizerTesterMixin






@custom_tokenizers
class      UpperCAmelCase_  (    SCREAMING_SNAKE_CASE_	,      unittest.TestCase						):
      __SCREAMING_SNAKE_CASE						:       Optional[Any]								=			BertJapaneseTokenizer
      __SCREAMING_SNAKE_CASE						:       Any								=			False
      __SCREAMING_SNAKE_CASE						:       List[str]								=			True



      def 						snake_case_ (					self					:     List[str]						):
           super().setUp()

           _UpperCAmelCase      :     List[str]        =   [
               '[UNK]',
               '[CLS]',
               '[SEP]',
               'こんにちは',
               'こん',
               'にちは',
               'ばんは',
               '##こん',
               '##にちは',
               '##ばんは',
               '世界',
               '##世界',
               '、',
               '##、',
               '。',
               '##。',
           ]

           _UpperCAmelCase      :     str        =   os.path.join(self.tmpdirname					,     VOCAB_FILES_NAMES["vocab_file"]						)
           with open(self.vocab_file					,     "w"					,     encoding="utf-8"						) as vocab_writer:
                vocab_writer.write("".join([x + "\n" for x in vocab_tokens]						)						)



      def 						snake_case_ (					self					:     List[str]					,     A					:     Union[str, Any]						):
           _UpperCAmelCase      :     Dict        =   'こんにちは、世界。 \nこんばんは、世界。'
           _UpperCAmelCase      :     Tuple        =   'こんにちは 、 世界 。 こんばんは 、 世界 。'
           return input_text, output_text



      def 						snake_case_ (					self					:     List[str]					,     A					:     List[Any]						):
           _UpperCAmelCase      :     Dict        =   self.get_input_output_texts(__a						)
           _UpperCAmelCase      :     List[str]        =   tokenizer.encode(__a					,     add_special_tokens=__a						)
           _UpperCAmelCase      :     int        =   tokenizer.decode(__a					,     clean_up_tokenization_spaces=__a						)
           return text, ids



      def 						snake_case_ (					self					:     Union[str, Any]						):
           pass  # TODO add if relevant



      def 						snake_case_ (					self					:     Union[str, Any]						):
           pass  # TODO add if relevant



      def 						snake_case_ (					self					:     str						):
           pass  # TODO add if relevant



      def 						snake_case_ (					self					:     Optional[Any]						):
           _UpperCAmelCase      :     str        =   self.tokenizer_class(self.vocab_file						)

           _UpperCAmelCase      :     Tuple        =   tokenizer.tokenize("こんにちは、世界。\nこんばんは、世界。"						)
           self.assertListEqual(__a					,     ["こんにちは", "、", "世界", "。", "こん", "##ばんは", "、", "世界", "。"]						)
           self.assertListEqual(tokenizer.convert_tokens_to_ids(__a						)					,     [3, 1_2, 1_0, 1_4, 4, 9, 1_2, 1_0, 1_4]						)



      def 						snake_case_ (					self					:     Union[str, Any]						):
           _UpperCAmelCase      :     int        =   self.tokenizer_class(self.vocab_file					,     word_tokenizer_type="mecab"						)
           self.assertIsNotNone(__a						)

           _UpperCAmelCase      :     Optional[Any]        =   'こんにちは、世界。\nこんばんは、世界。'
           _UpperCAmelCase      :     List[str]        =   tokenizer.tokenize(__a						)
           self.assertListEqual(__a					,     ["こんにちは", "、", "世界", "。", "こん", "##ばんは", "、", "世界", "。"]						)
           self.assertListEqual(tokenizer.convert_tokens_to_ids(__a						)					,     [3, 1_2, 1_0, 1_4, 4, 9, 1_2, 1_0, 1_4]						)

           _UpperCAmelCase      :     List[Any]        =   os.path.join(self.tmpdirname					,     "tokenizer.bin"						)
           with open(__a					,     "wb"						) as handle:
                pickle.dump(__a					,     __a						)

           with open(__a					,     "rb"						) as handle:
                _UpperCAmelCase      :     Any        =   pickle.load(__a						)

           _UpperCAmelCase      :     Dict        =   tokenizer_new.tokenize(__a						)

           self.assertListEqual(__a					,     __a						)



      def 						snake_case_ (					self					:     Optional[int]						):
           _UpperCAmelCase      :     List[Any]        =   MecabTokenizer(mecab_dic="ipadic"						)

           self.assertListEqual(
               tokenizer.tokenize(" \tｱｯﾌﾟﾙストアでiPhone８ が  \n 発売された　。  "						)					,     ["アップルストア", "で", "iPhone", "8", "が", "発売", "さ", "れ", "た", "。"]					,     )



      def 						snake_case_ (					self					:     Optional[Any]						):
           try:
                _UpperCAmelCase      :     int        =   MecabTokenizer(mecab_dic="unidic_lite"						)
           except ModuleNotFoundError:
                return

           self.assertListEqual(
               tokenizer.tokenize(" \tｱｯﾌﾟﾙストアでiPhone８ が  \n 発売された　。  "						)					,     ["アップル", "ストア", "で", "iPhone", "8", "が", "発売", "さ", "れ", "た", "。"]					,     )



      def 						snake_case_ (					self					:     List[Any]						):
           try:
                _UpperCAmelCase      :     Dict        =   MecabTokenizer(mecab_dic="unidic"						)
           except ModuleNotFoundError:
                return

           self.assertListEqual(
               tokenizer.tokenize(" \tｱｯﾌﾟﾙストアでiPhone８ が  \n 発売された　。  "						)					,     ["アップル", "ストア", "で", "iPhone", "8", "が", "発売", "さ", "れ", "た", "。"]					,     )



      def 						snake_case_ (					self					:     int						):
           _UpperCAmelCase      :     Any        =   MecabTokenizer(do_lower_case=__a					,     mecab_dic="ipadic"						)

           self.assertListEqual(
               tokenizer.tokenize(" \tｱｯﾌﾟﾙストアでiPhone８ が  \n 発売された　。  "						)					,     ["アップルストア", "で", "iphone", "8", "が", "発売", "さ", "れ", "た", "。"]					,     )



      def 						snake_case_ (					self					:     Tuple						):
           try:
                _UpperCAmelCase      :     Union[str, Any]        =   MecabTokenizer(
                    do_lower_case=__a					,     normalize_text=__a					,     mecab_option="-d /usr/local/lib/mecab/dic/jumandic"						)
           except RuntimeError:
                # if dict doesn't exist in the system, previous code raises this error.
                return

           self.assertListEqual(
               tokenizer.tokenize(" \tｱｯﾌﾟﾙストアでiPhone８ が  \n 発売された　。  "						)					,     ["ｱｯﾌﾟﾙストア", "で", "iPhone", "８", "が", "発売", "さ", "れた", "\u3000", "。"]					,     )



      def 						snake_case_ (					self					:     Dict						):
           _UpperCAmelCase      :     str        =   MecabTokenizer(normalize_text=__a					,     mecab_dic="ipadic"						)

           self.assertListEqual(
               tokenizer.tokenize(" \tｱｯﾌﾟﾙストアでiPhone８ が  \n 発売された　。  "						)					,     ["ｱｯﾌﾟﾙストア", "で", "iPhone", "８", "が", "発売", "さ", "れ", "た", "　", "。"]					,     )



      @require_sudachi
      def 						snake_case_ (					self					:     List[str]						):
           _UpperCAmelCase      :     Optional[Any]        =   self.tokenizer_class(self.vocab_file					,     word_tokenizer_type="sudachi"						)
           self.assertIsNotNone(__a						)

           _UpperCAmelCase      :     Union[str, Any]        =   'こんにちは、世界。\nこんばんは、世界。'
           _UpperCAmelCase      :     Optional[Any]        =   tokenizer.tokenize(__a						)
           self.assertListEqual(__a					,     ["こんにちは", "、", "世界", "。", "こん", "##ばんは", "、", "世界", "。"]						)
           self.assertListEqual(tokenizer.convert_tokens_to_ids(__a						)					,     [3, 1_2, 1_0, 1_4, 4, 9, 1_2, 1_0, 1_4]						)

           _UpperCAmelCase      :     List[str]        =   os.path.join(self.tmpdirname					,     "tokenizer.bin"						)
           with open(__a					,     "wb"						) as handle:
                pickle.dump(__a					,     __a						)

           with open(__a					,     "rb"						) as handle:
                _UpperCAmelCase      :     List[str]        =   pickle.load(__a						)

           _UpperCAmelCase      :     int        =   tokenizer_new.tokenize(__a						)

           self.assertListEqual(__a					,     __a						)



      @require_sudachi
      def 						snake_case_ (					self					:     List[Any]						):
           _UpperCAmelCase      :     List[Any]        =   SudachiTokenizer(sudachi_dict_type="core"						)

           self.assertListEqual(
               tokenizer.tokenize(" \tｱｯﾌﾟﾙストアでiPhone８ が  \n 発売された　。  "						)					,     [" ", "\t", "アップル", "ストア", "で", "iPhone", "8", " ", "が", " ", " ", "\n ", "発売", "さ", "れ", "た", " ", "。", " ", " "]					,     )



      @require_sudachi
      def 						snake_case_ (					self					:     Union[str, Any]						):
           _UpperCAmelCase      :     Optional[int]        =   SudachiTokenizer(sudachi_dict_type="core"					,     sudachi_split_mode="A"						)

           self.assertListEqual(tokenizer.tokenize("外国人参政権"						)					,     ["外国", "人", "参政", "権"]						)



      @require_sudachi
      def 						snake_case_ (					self					:     List[str]						):
           _UpperCAmelCase      :     Optional[int]        =   SudachiTokenizer(sudachi_dict_type="core"					,     sudachi_split_mode="B"						)

           self.assertListEqual(tokenizer.tokenize("外国人参政権"						)					,     ["外国人", "参政権"]						)



      @require_sudachi
      def 						snake_case_ (					self					:     str						):
           _UpperCAmelCase      :     Union[str, Any]        =   SudachiTokenizer(sudachi_dict_type="core"					,     sudachi_split_mode="C"						)

           self.assertListEqual(tokenizer.tokenize("外国人参政権"						)					,     ["外国人参政権"]						)



      @require_sudachi
      def 						snake_case_ (					self					:     Tuple						):
           _UpperCAmelCase      :     List[Any]        =   SudachiTokenizer(do_lower_case=__a					,     sudachi_dict_type="core"						)

           self.assertListEqual(
               tokenizer.tokenize(" \tｱｯﾌﾟﾙストアでiPhone８ が  \n 発売された　。  "						)					,     [" ", "\t", "アップル", "ストア", "で", "iphone", "8", " ", "が", " ", " ", "\n ", "発売", "さ", "れ", "た", " ", "。", " ", " "]					,     )



      @require_sudachi
      def 						snake_case_ (					self					:     Optional[int]						):
           _UpperCAmelCase      :     Dict        =   SudachiTokenizer(normalize_text=__a					,     sudachi_dict_type="core"						)

           self.assertListEqual(
               tokenizer.tokenize(" \tｱｯﾌﾟﾙストアでiPhone８ が  \n 発売された　。  "						)					,     [" ", "\t", "ｱｯﾌﾟﾙ", "ストア", "で", "iPhone", "８", " ", "が", " ", " ", "\n ", "発売", "さ", "れ", "た", "\u3000", "。", " ", " "]					,     )



      @require_sudachi
      def 						snake_case_ (					self					:     List[str]						):
           _UpperCAmelCase      :     List[Any]        =   SudachiTokenizer(trim_whitespace=__a					,     sudachi_dict_type="core"						)

           self.assertListEqual(
               tokenizer.tokenize(" \tｱｯﾌﾟﾙストアでiPhone８ が  \n 発売された　。  "						)					,     ["アップル", "ストア", "で", "iPhone", "8", "が", "発売", "さ", "れ", "た", "。"]					,     )



      @require_jumanpp
      def 						snake_case_ (					self					:     Dict						):
           _UpperCAmelCase      :     int        =   self.tokenizer_class(self.vocab_file					,     word_tokenizer_type="jumanpp"						)
           self.assertIsNotNone(__a						)

           _UpperCAmelCase      :     List[Any]        =   'こんにちは、世界。\nこんばんは、世界。'
           _UpperCAmelCase      :     Any        =   tokenizer.tokenize(__a						)
           self.assertListEqual(__a					,     ["こんにちは", "、", "世界", "。", "こん", "##ばんは", "、", "世界", "。"]						)
           self.assertListEqual(tokenizer.convert_tokens_to_ids(__a						)					,     [3, 1_2, 1_0, 1_4, 4, 9, 1_2, 1_0, 1_4]						)

           _UpperCAmelCase      :     Optional[Any]        =   os.path.join(self.tmpdirname					,     "tokenizer.bin"						)
           with open(__a					,     "wb"						) as handle:
                pickle.dump(__a					,     __a						)

           with open(__a					,     "rb"						) as handle:
                _UpperCAmelCase      :     List[str]        =   pickle.load(__a						)

           _UpperCAmelCase      :     Any        =   tokenizer_new.tokenize(__a						)

           self.assertListEqual(__a					,     __a						)



      @require_jumanpp
      def 						snake_case_ (					self					:     List[Any]						):
           _UpperCAmelCase      :     Any        =   JumanppTokenizer()

           self.assertListEqual(
               tokenizer.tokenize(" \tｱｯﾌﾟﾙストアでiPhone８ が  \n 発売された　。  "						)					,     ["アップル", "ストア", "で", "iPhone", "8", "\u3000", "が", "\u3000", "\u3000", "\u3000", "発売", "さ", "れた", "\u3000", "。"]					,     )



      @require_jumanpp
      def 						snake_case_ (					self					:     Optional[int]						):
           _UpperCAmelCase      :     Union[str, Any]        =   JumanppTokenizer(do_lower_case=__a						)

           self.assertListEqual(
               tokenizer.tokenize(" \tｱｯﾌﾟﾙストアでiPhone８ が  \n 発売された　。  "						)					,     ["アップル", "ストア", "で", "iphone", "8", "\u3000", "が", "\u3000", "\u3000", "\u3000", "発売", "さ", "れた", "\u3000", "。"]					,     )



      @require_jumanpp
      def 						snake_case_ (					self					:     str						):
           _UpperCAmelCase      :     Dict        =   JumanppTokenizer(normalize_text=__a						)

           self.assertListEqual(
               tokenizer.tokenize(" \tｱｯﾌﾟﾙストアでiPhone８ が  \n 発売された　。  "						)					,     ["ｱ", "ｯ", "ﾌ", "ﾟ", "ﾙ", "ストア", "で", "iPhone", "８", "\u3000", "が", "\u3000", "\u3000", "\u3000", "発売", "さ", "れた", "\u3000", "。"]					,     )



      @require_jumanpp
      def 						snake_case_ (					self					:     Optional[Any]						):
           _UpperCAmelCase      :     List[Any]        =   JumanppTokenizer(trim_whitespace=__a						)

           self.assertListEqual(
               tokenizer.tokenize(" \tｱｯﾌﾟﾙストアでiPhone８ が  \n 発売された　。  "						)					,     ["アップル", "ストア", "で", "iPhone", "8", "が", "発売", "さ", "れた", "。"]					,     )



      @require_jumanpp
      def 						snake_case_ (					self					:     str						):
           _UpperCAmelCase      :     Optional[Any]        =   JumanppTokenizer()

           self.assertListEqual(
               tokenizer.tokenize("ありがとうございますm(_ _)ｍ見つけるのが大変です。"						)					,     ["ありがとう", "ございます", "m(_ _)m", "見つける", "の", "が", "大変です", "。"]					,     )



      def 						snake_case_ (					self					:     List[Any]						):
           _UpperCAmelCase      :     Any        =   ['[UNK]', '[CLS]', '[SEP]', 'こんにちは', 'こん', 'にちは', 'ばんは', '##こん', '##にちは', '##ばんは']

           _UpperCAmelCase      :     Any        =   {}
           for i, token in enumerate(__a						):
                _UpperCAmelCase      :     str        =   i
           _UpperCAmelCase      :     List[Any]        =   WordpieceTokenizer(vocab=__a					,     unk_token="[UNK]"						)

           self.assertListEqual(tokenizer.tokenize(""						)					,     []						)

           self.assertListEqual(tokenizer.tokenize("こんにちは"						)					,     ["こんにちは"]						)

           self.assertListEqual(tokenizer.tokenize("こんばんは"						)					,     ["こん", "##ばんは"]						)

           self.assertListEqual(tokenizer.tokenize("こんばんは こんばんにちは こんにちは"						)					,     ["こん", "##ばんは", "[UNK]", "こんにちは"]						)



      def 						snake_case_ (					self					:     List[str]						):
           _UpperCAmelCase      :     int        =   BertJapaneseTokenizer.from_pretrained("nlp-waseda/roberta-base-japanese-with-auto-jumanpp"						)
           _UpperCAmelCase      :     Dict        =   tokenizer.subword_tokenizer

           _UpperCAmelCase      :     List[str]        =   subword_tokenizer.tokenize("国境 の 長い トンネル を 抜ける と 雪国 であった 。"						)
           self.assertListEqual(__a					,     ["▁国境", "▁の", "▁長い", "▁トンネル", "▁を", "▁抜ける", "▁と", "▁雪", "国", "▁であった", "▁。"]						)

           _UpperCAmelCase      :     List[Any]        =   subword_tokenizer.tokenize("こんばんは こんばん にち は こんにちは"						)
           self.assertListEqual(__a					,     ["▁こん", "ばん", "は", "▁こん", "ばん", "▁に", "ち", "▁は", "▁こんにちは"]						)



      def 						snake_case_ (					self					:     Optional[Any]						):
           _UpperCAmelCase      :     List[Any]        =   self.tokenizer_class.from_pretrained("cl-tohoku/bert-base-japanese"						)

           _UpperCAmelCase      :     List[Any]        =   tokenizer.encode("ありがとう。"					,     add_special_tokens=__a						)
           _UpperCAmelCase      :     str        =   tokenizer.encode("どういたしまして。"					,     add_special_tokens=__a						)

           _UpperCAmelCase      :     Optional[int]        =   tokenizer.build_inputs_with_special_tokens(__a						)
           _UpperCAmelCase      :     Dict        =   tokenizer.build_inputs_with_special_tokens(__a					,     __a						)

           # 2 is for "[CLS]", 3 is for "[SEP]"
           assert encoded_sentence == [2] + text + [3]
           assert encoded_pair == [2] + text + [3] + text_a + [3]







@custom_tokenizers
class      UpperCAmelCase_  (    SCREAMING_SNAKE_CASE_	,      unittest.TestCase						):
      __SCREAMING_SNAKE_CASE						:       Optional[Any]								=			BertJapaneseTokenizer
      __SCREAMING_SNAKE_CASE						:       Union[str, Any]								=			False



      def 						snake_case_ (					self					:     Optional[Any]						):
           super().setUp()

           _UpperCAmelCase      :     Optional[Any]        =   ['[UNK]', '[CLS]', '[SEP]', 'こ', 'ん', 'に', 'ち', 'は', 'ば', '世', '界', '、', '。']

           _UpperCAmelCase      :     int        =   os.path.join(self.tmpdirname					,     VOCAB_FILES_NAMES["vocab_file"]						)
           with open(self.vocab_file					,     "w"					,     encoding="utf-8"						) as vocab_writer:
                vocab_writer.write("".join([x + "\n" for x in vocab_tokens]						)						)



      def 						snake_case_ (					self					:     Tuple					,     **A					:     Dict						):
           return BertJapaneseTokenizer.from_pretrained(self.tmpdirname					,     subword_tokenizer_type="character"					,     **__a						)



      def 						snake_case_ (					self					:     Any					,     A					:     Union[str, Any]						):
           _UpperCAmelCase      :     Dict        =   'こんにちは、世界。 \nこんばんは、世界。'
           _UpperCAmelCase      :     str        =   'こ ん に ち は 、 世 界 。 こ ん ば ん は 、 世 界 。'
           return input_text, output_text



      def 						snake_case_ (					self					:     Any						):
           pass  # TODO add if relevant



      def 						snake_case_ (					self					:     int						):
           pass  # TODO add if relevant



      def 						snake_case_ (					self					:     List[Any]						):
           pass  # TODO add if relevant



      def 						snake_case_ (					self					:     List[Any]						):
           _UpperCAmelCase      :     Any        =   self.tokenizer_class(self.vocab_file					,     subword_tokenizer_type="character"						)

           _UpperCAmelCase      :     Any        =   tokenizer.tokenize("こんにちは、世界。 \nこんばんは、世界。"						)
           self.assertListEqual(
               __a					,     ["こ", "ん", "に", "ち", "は", "、", "世", "界", "。", "こ", "ん", "ば", "ん", "は", "、", "世", "界", "。"]						)
           self.assertListEqual(
               tokenizer.convert_tokens_to_ids(__a						)					,     [3, 4, 5, 6, 7, 1_1, 9, 1_0, 1_2, 3, 4, 8, 4, 7, 1_1, 9, 1_0, 1_2]						)



      def 						snake_case_ (					self					:     Tuple						):
           _UpperCAmelCase      :     Tuple        =   ['[UNK]', '[CLS]', '[SEP]', 'こ', 'ん', 'に', 'ち', 'は', 'ば', '世', '界', '、', '。']

           _UpperCAmelCase      :     Union[str, Any]        =   {}
           for i, token in enumerate(__a						):
                _UpperCAmelCase      :     Union[str, Any]        =   i
           _UpperCAmelCase      :     int        =   CharacterTokenizer(vocab=__a					,     unk_token="[UNK]"						)

           self.assertListEqual(tokenizer.tokenize(""						)					,     []						)

           self.assertListEqual(tokenizer.tokenize("こんにちは"						)					,     ["こ", "ん", "に", "ち", "は"]						)

           self.assertListEqual(tokenizer.tokenize("こんにちほ"						)					,     ["こ", "ん", "に", "ち", "[UNK]"]						)



      def 						snake_case_ (					self					:     List[Any]						):
           _UpperCAmelCase      :     List[Any]        =   self.tokenizer_class.from_pretrained("cl-tohoku/bert-base-japanese-char"						)

           _UpperCAmelCase      :     List[str]        =   tokenizer.encode("ありがとう。"					,     add_special_tokens=__a						)
           _UpperCAmelCase      :     Union[str, Any]        =   tokenizer.encode("どういたしまして。"					,     add_special_tokens=__a						)

           _UpperCAmelCase      :     Union[str, Any]        =   tokenizer.build_inputs_with_special_tokens(__a						)
           _UpperCAmelCase      :     int        =   tokenizer.build_inputs_with_special_tokens(__a					,     __a						)

           # 2 is for "[CLS]", 3 is for "[SEP]"
           assert encoded_sentence == [2] + text + [3]
           assert encoded_pair == [2] + text + [3] + text_a + [3]







@custom_tokenizers
class      UpperCAmelCase_  (    unittest.TestCase						):



      def 						snake_case_ (					self					:     Optional[int]						):
           _UpperCAmelCase      :     Dict        =   'cl-tohoku/bert-base-japanese'
           _UpperCAmelCase      :     List[str]        =   AutoTokenizer.from_pretrained(__a						)
           self.assertIsInstance(__a					,     __a						)







class      UpperCAmelCase_  (    unittest.TestCase						):



      def 						snake_case_ (					self					:     Union[str, Any]						):
           _UpperCAmelCase      :     Optional[int]        =   'cl-tohoku/bert-base-japanese'
           with self.assertLogs("transformers"					,     level="WARNING"						) as cm:
                BertTokenizer.from_pretrained(__a						)
                self.assertTrue(
                    cm.records[0].message.startswith(
                        "The tokenizer class you load from this checkpoint is not the same type as the class this function"
                        " is called from."						)						)
           _UpperCAmelCase      :     str        =   'bert-base-cased'
           with self.assertLogs("transformers"					,     level="WARNING"						) as cm:
                BertJapaneseTokenizer.from_pretrained(__a						)
                self.assertTrue(
                    cm.records[0].message.startswith(
                        "The tokenizer class you load from this checkpoint is not the same type as the class this function"
                        " is called from."						)						)





"""simple docstring"""




from collections.abc import Callable






class      UpperCAmelCase_  :



      def __init__(					self					:     Dict					,     A					:     Callable | None = None						):
           # Stores actual heap items.
           _UpperCAmelCase      :     list        =   []
           # Stores indexes of each item for supporting updates and deletion.
           _UpperCAmelCase      :     dict        =   {}
           # Stores current size of heap.
           _UpperCAmelCase      :     Tuple        =   0
           # Stores function used to evaluate the score of an item on which basis ordering
           # will be done.
           _UpperCAmelCase      :     Any        =   key or (lambda A						: x)



      def 						snake_case_ (					self					:     List[Any]					,     A					:     int						):
           return int((i - 1) / 2						) if i > 0 else None



      def 						snake_case_ (					self					:     List[Any]					,     A					:     int						):
           _UpperCAmelCase      :     Tuple        =   int(2 * i + 1						)
           return left if 0 < left < self.size else None



      def 						snake_case_ (					self					:     List[Any]					,     A					:     int						):
           _UpperCAmelCase      :     Tuple        =   int(2 * i + 2						)
           return right if 0 < right < self.size else None



      def 						snake_case_ (					self					:     Optional[int]					,     A					:     int					,     A					:     int						):
           _UpperCAmelCase    ,	_UpperCAmelCase      :     int        =   (
               self.pos_map[self.arr[j][0]],
               self.pos_map[self.arr[i][0]],
           )
           # Then swap the items in the list.
           _UpperCAmelCase    ,	_UpperCAmelCase      :     Any        =   self.arr[j], self.arr[i]



      def 						snake_case_ (					self					:     List[str]					,     A					:     int					,     A					:     int						):
           return self.arr[i][1] < self.arr[j][1]



      def 						snake_case_ (					self					:     Dict					,     A					:     int						):
           _UpperCAmelCase      :     str        =   self._left(A						)
           _UpperCAmelCase      :     str        =   self._right(A						)
           _UpperCAmelCase      :     List[Any]        =   i

           if left is not None and not self._cmp(A					,     A						):
                _UpperCAmelCase      :     Optional[int]        =   left
           if right is not None and not self._cmp(A					,     A						):
                _UpperCAmelCase      :     Any        =   right

           return valid_parent



      def 						snake_case_ (					self					:     Tuple					,     A					:     int						):
           _UpperCAmelCase      :     Tuple        =   self._parent(A						)
           while parent is not None and not self._cmp(A					,     A						):
                self._swap(A					,     A						)
                _UpperCAmelCase    ,	_UpperCAmelCase      :     Dict        =   parent, self._parent(A						)



      def 						snake_case_ (					self					:     Optional[int]					,     A					:     int						):
           _UpperCAmelCase      :     Tuple        =   self._get_valid_parent(A						)
           while valid_parent != index:
                self._swap(A					,     A						)
                _UpperCAmelCase    ,	_UpperCAmelCase      :     Optional[Any]        =   valid_parent, self._get_valid_parent(A						)



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



      def 						snake_case_ (					self					:     List[str]					,     A					:     int						):
           if item not in self.pos_map:
                return
           _UpperCAmelCase      :     str        =   self.pos_map[item]
           del self.pos_map[item]
           _UpperCAmelCase      :     Tuple        =   self.arr[self.size - 1]
           _UpperCAmelCase      :     List[Any]        =   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(A						)
                self._heapify_down(A						)



      def 						snake_case_ (					self					:     Any					,     A					:     int					,     A					:     int						):
           _UpperCAmelCase      :     Any        =   len(self.arr						)
           if arr_len == self.size:
                self.arr.append([item, self.key(A						)]						)
           else:
                _UpperCAmelCase      :     Any        =   [item, self.key(A						)]
           _UpperCAmelCase      :     List[Any]        =   self.size
           self.size += 1
           self._heapify_up(self.size - 1						)



      def 						snake_case_ (					self					:     Tuple						):
           return self.arr[0] if self.size else None



      def 						snake_case_ (					self					:     Any						):
           _UpperCAmelCase      :     Dict        =   self.get_top()
           if top_item_tuple:
                self.delete_item(top_item_tuple[0]						)
           return top_item_tuple







def 						__snake_case						(				)  ->       None:





     '''simple docstring'''



if __name__ == "__main__":
 import doctest

 doctest.testmod()
