






"""simple docstring"""





import itertools
from dataclasses import dataclass
from io import StringIO
from typing import Optional

import pyarrow as pa

import datasets
from datasets.features.features import require_storage_cast
from datasets.table import table_cast


UpperCamelCase			=      datasets.utils.logging.get_logger(__name__)







@dataclass
class 		_a       (						datasets.BuilderConfig   ):





   '''simple docstring'''






   UpperCamelCase__      					=    None
   UpperCamelCase__      					=    "utf-8"
   UpperCamelCase__      					=    None
   UpperCamelCase__      					=    10 << 20  # 10MB
   UpperCamelCase__      					=    False
   UpperCamelCase__      					=    "line"







class 		_a       (						datasets.ArrowBasedBuilder   ):





   '''simple docstring'''






   UpperCamelCase__      					=    TextConfig





   def __lowercase    (   self)	-> Optional[Any]:




          '''simple docstring'''




          return datasets.DatasetInfo(features=self.config.features)





   def __lowercase    (   self			,				UpperCAmelCase_)	-> Optional[int]:




          '''simple docstring'''




          if not self.config.data_files:
                 raise ValueError(F"""At least one data file must be specified, but got data_files={self.config.data_files}""")
          lowercase__:    Any        =      dl_manager.download_and_extract(self.config.data_files)
          if isinstance(UpperCamelCase__			,				(str, list, tuple)):
                 lowercase__:    Optional[int]        =      data_files
                 if isinstance(UpperCamelCase__			,				UpperCamelCase__):
                        lowercase__:    Optional[Any]        =      [files]
                 lowercase__:    List[str]        =      [dl_manager.iter_files(UpperCamelCase__) for file in files]
                 return [datasets.SplitGenerator(name=datasets.Split.TRAIN			,				gen_kwargs={"files": files})]
          lowercase__:    Any        =      []
          for split_name, files in data_files.items():
                 if isinstance(UpperCamelCase__			,				UpperCamelCase__):
                        lowercase__:    Optional[Any]        =      [files]
                 lowercase__:    Optional[Any]        =      [dl_manager.iter_files(UpperCamelCase__) for file in files]
                 splits.append(datasets.SplitGenerator(name=UpperCamelCase__			,				gen_kwargs={"files": files}))
          return splits





   def __lowercase    (   self			,				UpperCAmelCase_)	-> pa.Table:




          '''simple docstring'''




          if self.config.features is not None:
                 lowercase__:    List[str]        =      self.config.features.arrow_schema
                 if all(not require_storage_cast(UpperCamelCase__) for feature in self.config.features.values()):
                        # cheaper cast
                        lowercase__:    Tuple        =      pa_table.cast(UpperCamelCase__)
                 else:
                        # more expensive cast; allows str <-> int/float or str to Audio for example
                        lowercase__:    Any        =      table_cast(UpperCamelCase__			,				UpperCamelCase__)
                 return pa_table
          else:
                 return pa_table.cast(pa.schema({"text": pa.string()}))





   def __lowercase    (   self			,				UpperCAmelCase_)	-> Tuple:




          '''simple docstring'''




          lowercase__:    List[Any]        =      list(self.config.features) if self.config.features is not None else ["text"]
          for file_idx, file in enumerate(itertools.chain.from_iterable(UpperCamelCase__)):
                 # open in text mode, by default translates universal newlines ("\n", "\r\n" and "\r") into "\n"
                 with open(UpperCamelCase__			,				encoding=self.config.encoding			,				errors=self.config.errors) as f:
                        if self.config.sample_by == "line":
                               lowercase__:    Any        =      0
                               while True:
                                      lowercase__:    Union[str, Any]        =      f.read(self.config.chunksize)
                                      if not batch:
                                             break
                                      batch += f.readline()  # finish current line
                                      # StringIO.readlines, by default splits only on "\n" (and keeps line breaks)
                                      lowercase__:    Optional[Any]        =      StringIO(UpperCamelCase__).readlines()
                                      if not self.config.keep_linebreaks:
                                             lowercase__:    List[Any]        =      [line.rstrip("\n") for line in batch]
                                      lowercase__:    Optional[int]        =      pa.Table.from_arrays([pa.array(UpperCamelCase__)]			,				names=UpperCamelCase__)
                                      # Uncomment for debugging (will print the Arrow table size and elements)
                                      # logger.warning(f"pa_table: {pa_table} num rows: {pa_table.num_rows}")
                                      # logger.warning('\n'.join(str(pa_table.slice(i, 1).to_pydict()) for i in range(pa_table.num_rows)))
                                      yield (file_idx, batch_idx), self._cast_table(UpperCamelCase__)
                                      batch_idx += 1
                        elif self.config.sample_by == "paragraph":
                               lowercase__:    Union[str, Any]        =      0
                               lowercase__:    List[str]        =      ""
                               while True:
                                      lowercase__:    Optional[Any]        =      f.read(self.config.chunksize)
                                      if not new_batch:
                                             break
                                      batch += new_batch
                                      batch += f.readline()  # finish current line
                                      lowercase__:    Tuple        =      batch.split("\n\n")
                                      lowercase__:    Tuple        =      pa.Table.from_arrays(
                                          [pa.array([example for example in batch[:-1] if example])]			,				names=UpperCamelCase__)
                                      # Uncomment for debugging (will print the Arrow table size and elements)
                                      # logger.warning(f"pa_table: {pa_table} num rows: {pa_table.num_rows}")
                                      # logger.warning('\n'.join(str(pa_table.slice(i, 1).to_pydict()) for i in range(pa_table.num_rows)))
                                      yield (file_idx, batch_idx), self._cast_table(UpperCamelCase__)
                                      batch_idx += 1
                                      lowercase__:    Optional[int]        =      batch[-1]
                               if batch:
                                      lowercase__:    Union[str, Any]        =      pa.Table.from_arrays([pa.array([batch])]			,				names=UpperCamelCase__)
                                      yield (file_idx, batch_idx), self._cast_table(UpperCamelCase__)
                        elif self.config.sample_by == "document":
                               lowercase__:    Optional[Any]        =      f.read()
                               lowercase__:    str        =      pa.Table.from_arrays([pa.array([text])]			,				names=UpperCamelCase__)
                               yield file_idx, self._cast_table(UpperCamelCase__)














"""simple docstring"""





from __future__ import annotations






def     A(  snake_case_						,       snake_case_		):
       """simple docstring"""





       lowercase__  ,     lowercase__:    Optional[int]        =      0, len(snake_case_		) - 1
       while start_ind <= end_ind:
              if array[start_ind] == search_item:
                     return start_ind
              elif array[end_ind] == search_item:
                     return end_ind
              else:
                     start_ind += 1
                     end_ind -= 1
    # returns -1 if search_item is not found in array
       return -1


if __name__ == "__main__":
  print(double_linear_search(list(range(1_00)), 40))






