
class       A__  :





							def __init__(					self    :  Tuple	,					_UpperCAmelCase    :  Tuple							)		->						List[str]:



											"""simple docstring"""


											__lowercase								=   data
											__lowercase								=   None
											__lowercase								=   None





							def __str__(					self    :  Union[str, Any]							)		->						Dict:



											"""simple docstring"""


											return f"""{self.data}"""






class       A__  :





							def __init__(					self    :  Tuple							)		->						Optional[int]:



											"""simple docstring"""


											__lowercase								=   None
											__lowercase								=   None





							def __iter__(					self    :  str							)		->						List[Any]:



											"""simple docstring"""


											__lowercase								=   self.head
											while node:
															yield node.data
															__lowercase								=   node.next





							def __str__(					self    :  Dict							)		->						int:



											"""simple docstring"""


											return "->".join([str(_UpperCAmelCase							) for item in self]							)





							def __len__(					self    :  Union[str, Any]							)		->						Any:



											"""simple docstring"""


											return sum(1 for _ in self							)





							def      a__					(					self    :  Optional[int]	,					_UpperCAmelCase    :  List[Any]							)		->						Optional[Any]:



											"""simple docstring"""


											self.insert_at_nth(0	,					_UpperCAmelCase							)





							def      a__					(					self    :  int	,					_UpperCAmelCase    :  int							)		->						Union[str, Any]:



											"""simple docstring"""


											self.insert_at_nth(len(self							)	,					_UpperCAmelCase							)





							def      a__					(					self    :  int	,					_UpperCAmelCase    :  int	,					_UpperCAmelCase    :  Any							)		->						List[str]:



											"""simple docstring"""


											__lowercase								=   len(self							)

											if not 0 <= index <= length:
															raise IndexError('list index out of range'							)
											__lowercase								=   Node(_UpperCAmelCase							)
											if self.head is None:
															__lowercase								=   __lowercase								=   new_node
											elif index == 0:
															__lowercase								=   new_node
															__lowercase								=   self.head
															__lowercase								=   new_node
											elif index == length:
															__lowercase								=   new_node
															__lowercase								=   self.tail
															__lowercase								=   new_node
											else:
															__lowercase								=   self.head
															for _ in range(0	,					_UpperCAmelCase							):
																			__lowercase								=   temp.next
															__lowercase								=   new_node
															__lowercase								=   temp.previous
															__lowercase								=   temp
															__lowercase								=   new_node





							def      a__					(					self    :  Tuple							)		->						Union[str, Any]:



											"""simple docstring"""


											return self.delete_at_nth(0							)





							def      a__					(					self    :  Optional[Any]							)		->						str:



											"""simple docstring"""


											return self.delete_at_nth(len(self							) - 1							)





							def      a__					(					self    :  Optional[Any]	,					_UpperCAmelCase    :  int							)		->						Optional[int]:



											"""simple docstring"""


											__lowercase								=   len(self							)

											if not 0 <= index <= length - 1:
															raise IndexError('list index out of range'							)
											__lowercase								=   self.head  # default first node
											if length == 1:
															__lowercase								=   __lowercase								=   None
											elif index == 0:
															__lowercase								=   self.head.next
															__lowercase								=   None
											elif index == length - 1:
															__lowercase								=   self.tail
															__lowercase								=   self.tail.previous
															__lowercase								=   None
											else:
															__lowercase								=   self.head
															for _ in range(0	,					_UpperCAmelCase							):
																			__lowercase								=   temp.next
															__lowercase								=   temp
															__lowercase								=   temp.previous
															__lowercase								=   temp.next
											return delete_node.data





							def      a__					(					self    :  List[str]	,					_UpperCAmelCase    :  List[str]							)		->						str:



											"""simple docstring"""


											__lowercase								=   self.head

											while current.data != data:  # Find the position to delete
															if current.next:
																			__lowercase								=   current.next
															else:  # We have reached the end an no value matches
																			raise ValueError('No data matching given value'							)

											if current == self.head:
															self.delete_head()

											elif current == self.tail:
															self.delete_tail()

											else:  # Before: 1 <--> 2(current) <--> 3
															__lowercase								=   current.next  # 1 --> 3
															__lowercase								=   current.previous  # 1 <--> 3
											return data





							def      a__					(					self    :  Tuple							)		->						Dict:



											"""simple docstring"""


											return len(self							) == 0






def 				__SCREAMING_SNAKE_CASE  (						)	->		None:
				__lowercase								=   DoublyLinkedList()
				assert linked_list.is_empty() is True
				assert str(SCREAMING_SNAKE_CASE     ) == ""

				try:
								linked_list.delete_head()
								raise AssertionError  # This should not happen.
				except IndexError:
								assert True  # This should happen.

				try:
								linked_list.delete_tail()
								raise AssertionError  # This should not happen.
				except IndexError:
								assert True  # This should happen.

				for i in range(10     ):
								assert len(SCREAMING_SNAKE_CASE     ) == i
								linked_list.insert_at_nth(SCREAMING_SNAKE_CASE       ,				i + 1     )
				assert str(SCREAMING_SNAKE_CASE     ) == "->".join(str(SCREAMING_SNAKE_CASE     ) for i in range(1       ,				11     )     )

				linked_list.insert_at_head(0     )
				linked_list.insert_at_tail(11     )
				assert str(SCREAMING_SNAKE_CASE     ) == "->".join(str(SCREAMING_SNAKE_CASE     ) for i in range(0       ,				12     )     )

				assert linked_list.delete_head() == 0
				assert linked_list.delete_at_nth(9     ) == 10
				assert linked_list.delete_tail() == 11
				assert len(SCREAMING_SNAKE_CASE     ) == 9
				assert str(SCREAMING_SNAKE_CASE     ) == "->".join(str(SCREAMING_SNAKE_CASE     ) for i in range(1       ,				10     )     )


if __name__ == "__main__":
							from doctest import testmod

							testmod()







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__				=							datasets.utils.logging.get_logger(__name__)
@dataclass
class       A__  (		datasets.BuilderConfig							):
							lowerCAmelCase__						:		Optional[datasets.Features]            =				None
							lowerCAmelCase__						:		str            =				"utf-8"
							lowerCAmelCase__						:		Optional[str]            =				None
							lowerCAmelCase__						:		int            =				10 << 20  # 10MB
							lowerCAmelCase__						:		bool            =				False
							lowerCAmelCase__						:		str            =				"line"






class       A__  (		datasets.ArrowBasedBuilder							):
							lowerCAmelCase__						:		Optional[int]            =				TextConfig





							def      a__					(					self    :  List[str]							)		->						Any:



											"""simple docstring"""


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





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





							def      a__					(					self    :  int	,					_UpperCAmelCase    :  pa.Table							)		->						pa.Table:



											"""simple docstring"""


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





							def      a__					(					self    :  Union[str, Any]	,					_UpperCAmelCase    :  Optional[Any]							)		->						List[Any]:



											"""simple docstring"""


											__lowercase								=   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								=   0
																							while True:
																											__lowercase								=   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								=   StringIO(_UpperCAmelCase							).readlines()
																											if not self.config.keep_linebreaks:
																															__lowercase								=   [line.rstrip('\n'							) for line in batch]
																											__lowercase								=   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								=   0
																							__lowercase								=   ''
																							while True:
																											__lowercase								=   f.read(self.config.chunksize							)
																											if not new_batch:
																															break
																											batch += new_batch
																											batch += f.readline()  # finish current line
																											__lowercase								=   batch.split('\n\n'							)
																											__lowercase								=   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								=   batch[-1]
																							if batch:
																											__lowercase								=   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								=   f.read()
																							__lowercase								=   pa.Table.from_arrays([pa.array([text]							)]	,					names=_UpperCAmelCase							)
																							yield file_idx, self._cast_table(_UpperCAmelCase							)





