




'''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


SCREAMING_SNAKE_CASE:    str											=   datasets.utils.logging.get_logger(__name__)



@dataclass
class       lowercase_		(datasets.BuilderConfig   ):
						lowerCAmelCase__ 			=None
						lowerCAmelCase__ 			="utf-8"
						lowerCAmelCase__ 			=None
						lowerCAmelCase__ 			=10 << 20  # 10MB
						lowerCAmelCase__ 			=False
						lowerCAmelCase__ 			="line"



class       lowercase_		(datasets.ArrowBasedBuilder   ):
						lowerCAmelCase__ 			=TextConfig



						def   __a				( self  :      Union[str, Any]     ):

								"""simple docstring"""

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



						def   __a				( self  :      Optional[Any]				,       snake_case__  :      str     ):

								"""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}'''     )
								SCREAMING_SNAKE_CASE_							=       dl_manager.download_and_extract(self.config.data_files     )
								if isinstance(snake_case__				,       (str, list, tuple)     ):
										SCREAMING_SNAKE_CASE_							=       data_files
										if isinstance(snake_case__				,       snake_case__     ):
												SCREAMING_SNAKE_CASE_							=       [files]
										SCREAMING_SNAKE_CASE_							=       [dl_manager.iter_files(snake_case__     ) for file in files]
										return [datasets.SplitGenerator(name=datasets.Split.TRAIN				,       gen_kwargs={'files': files}     )]
								SCREAMING_SNAKE_CASE_							=       []
								for split_name, files in data_files.items():
										if isinstance(snake_case__				,       snake_case__     ):
												SCREAMING_SNAKE_CASE_							=       [files]
										SCREAMING_SNAKE_CASE_							=       [dl_manager.iter_files(snake_case__     ) for file in files]
										splits.append(datasets.SplitGenerator(name=snake_case__				,       gen_kwargs={'files': files}     )     )
								return splits



						def   __a				( self  :      Any				,       snake_case__  :      pa.Table     ):

								"""simple docstring"""

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






						def   __a				( self  :      int				,       snake_case__  :      Any     ):

								"""simple docstring"""

								SCREAMING_SNAKE_CASE_							=       list(self.config.features     ) if self.config.features is not None else ['text']
								for file_idx, file in enumerate(itertools.chain.from_iterable(snake_case__     )     ):
										# open in text mode, by default translates universal newlines ("\n", "\r\n" and "\r") into "\n"
										with open(snake_case__				,       encoding=self.config.encoding				,       errors=self.config.errors     ) as f:
												if self.config.sample_by == "line":
														SCREAMING_SNAKE_CASE_							=       0
														while True:
																SCREAMING_SNAKE_CASE_							=       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)
																SCREAMING_SNAKE_CASE_							=       StringIO(snake_case__     ).readlines()
																if not self.config.keep_linebreaks:
																		SCREAMING_SNAKE_CASE_							=       [line.rstrip('\n'     ) for line in batch]
																SCREAMING_SNAKE_CASE_							=       pa.Table.from_arrays([pa.array(snake_case__     )]				,       names=snake_case__     )
																# 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(snake_case__     )
																batch_idx += 1
												elif self.config.sample_by == "paragraph":
														SCREAMING_SNAKE_CASE_							=       0
														SCREAMING_SNAKE_CASE_							=       ''
														while True:
																SCREAMING_SNAKE_CASE_							=       f.read(self.config.chunksize     )
																if not new_batch:
																		break
																batch += new_batch
																batch += f.readline()  # finish current line
																SCREAMING_SNAKE_CASE_							=       batch.split('\n\n'     )
																SCREAMING_SNAKE_CASE_							=       pa.Table.from_arrays(
																    [pa.array([example for example in batch[:-1] if example]     )]				,       names=snake_case__     )
																# 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(snake_case__     )
																batch_idx += 1
																SCREAMING_SNAKE_CASE_							=       batch[-1]
														if batch:
																SCREAMING_SNAKE_CASE_							=       pa.Table.from_arrays([pa.array([batch]     )]				,       names=snake_case__     )
																yield (file_idx, batch_idx), self._cast_table(snake_case__     )
												elif self.config.sample_by == "document":
														SCREAMING_SNAKE_CASE_							=       f.read()
														SCREAMING_SNAKE_CASE_							=       pa.Table.from_arrays([pa.array([text]     )]				,       names=snake_case__     )
														yield file_idx, self._cast_table(snake_case__     )





from __future__ import annotations


def 				_a       (				lowerCAmelCase						,	lowerCAmelCase   )->  int:
		SCREAMING_SNAKE_CASE_			,							SCREAMING_SNAKE_CASE_							=       0, len(lowerCAmelCase   ) - 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_0_0)), 4_0))