class    _UpperCamelCase      :


			"""simple docstring"""






			def __init__(   self						)     ->					List[Any]:

							'''simple docstring'''


							__lowercase 			=							0
							__lowercase 			=							0
							__lowercase 			=							{}





			def        _SCREAMING_SNAKE_CASE			(   self      ,   lowerCAmelCase__						)     ->					List[Any]:

							'''simple docstring'''


							if vertex not in self.adjacency:
											__lowercase 			=							{}
											self.num_vertices += 1





			def        _SCREAMING_SNAKE_CASE			(   self      ,   lowerCAmelCase__      ,   lowerCAmelCase__      ,   lowerCAmelCase__						)     ->					Any:

							'''simple docstring'''


							self.add_vertex(lowerCAmelCase__						)
							self.add_vertex(lowerCAmelCase__						)

							if head == tail:
											return

							__lowercase 			=							weight
							__lowercase 			=							weight





			def        _SCREAMING_SNAKE_CASE			(   self						)     ->					Dict:

							'''simple docstring'''


							__lowercase 			=							self.get_edges()
							for edge in edges:
											__lowercase			,     __lowercase			,     __lowercase 			=							edge
											edges.remove((tail, head, weight)						)
							for i in range(len(lowerCAmelCase__						)						):
											__lowercase 			=							list(edges[i]						)

							edges.sort(key=lambda lowerCAmelCase__						: e[2]						)
							for i in range(len(lowerCAmelCase__						) - 1						):
											if edges[i][2] >= edges[i + 1][2]:
															__lowercase 			=							edges[i][2] + 1
							for edge in edges:
											__lowercase			,     __lowercase			,     __lowercase 			=							edge
											__lowercase 			=							weight
											__lowercase 			=							weight





			def __str__(   self						)     ->					str:

							'''simple docstring'''


							__lowercase 			=							''''''
							for tail in self.adjacency:
											for head in self.adjacency[tail]:
															__lowercase 			=							self.adjacency[head][tail]
															string += F"{head} -> {tail} == {weight}\n"
							return string.rstrip('''\n'''						)





			def        _SCREAMING_SNAKE_CASE			(   self						)     ->					Tuple:

							'''simple docstring'''


							__lowercase 			=							[]
							for tail in self.adjacency:
											for head in self.adjacency[tail]:
															output.append((tail, head, self.adjacency[head][tail])						)
							return output





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

							'''simple docstring'''


							return self.adjacency.keys()





			@staticmethod
			def        _SCREAMING_SNAKE_CASE			(   lowerCAmelCase__=None      ,   lowerCAmelCase__=None						)     ->					Optional[Any]:

							'''simple docstring'''


							__lowercase 			=							Graph()
							if vertices is None:
											__lowercase 			=							[]
							if edges is None:
											__lowercase 			=							[]
							for vertex in vertices:
											g.add_vertex(lowerCAmelCase__						)
							for edge in edges:
											g.add_edge(*lowerCAmelCase__						)
							return g




			class    _UpperCamelCase      :


						"""simple docstring"""






						def __init__(   self						)     ->					int:

										'''simple docstring'''


										__lowercase 			=							{}
										__lowercase 			=							{}





						def __len__(   self						)     ->					Any:

										'''simple docstring'''


										return len(self.parent						)





						def        _SCREAMING_SNAKE_CASE			(   self      ,   lowerCAmelCase__						)     ->					List[str]:

										'''simple docstring'''


										if item in self.parent:
														return self.find(lowerCAmelCase__						)

										__lowercase 			=							item
										__lowercase 			=							0
										return item





						def        _SCREAMING_SNAKE_CASE			(   self      ,   lowerCAmelCase__						)     ->					List[Any]:

										'''simple docstring'''


										if item not in self.parent:
														return self.make_set(lowerCAmelCase__						)
										if item != self.parent[item]:
														__lowercase 			=							self.find(self.parent[item]						)
										return self.parent[item]





						def        _SCREAMING_SNAKE_CASE			(   self      ,   lowerCAmelCase__      ,   lowerCAmelCase__						)     ->					str:

										'''simple docstring'''


										__lowercase 			=							self.find(lowerCAmelCase__						)
										__lowercase 			=							self.find(lowerCAmelCase__						)

										if roota == roota:
														return roota

										if self.rank[roota] > self.rank[roota]:
														__lowercase 			=							roota
														return roota

										if self.rank[roota] < self.rank[roota]:
														__lowercase 			=							roota
														return roota

										if self.rank[roota] == self.rank[roota]:
														self.rank[roota] += 1
														__lowercase 			=							roota
														return roota
										return None





			@staticmethod
			def        _SCREAMING_SNAKE_CASE			(   lowerCAmelCase__						)     ->					str:

							'''simple docstring'''


							__lowercase 			=							graph.num_vertices

							__lowercase 			=							Graph.UnionFind()
							__lowercase 			=							[]
							while num_components > 1:
											__lowercase 			=							{}
											for vertex in graph.get_vertices():
															__lowercase 			=							-1

											__lowercase 			=							graph.get_edges()
											for edge in edges:
															__lowercase			,     __lowercase			,     __lowercase 			=							edge
															edges.remove((tail, head, weight)						)
											for edge in edges:
															__lowercase			,     __lowercase			,     __lowercase 			=							edge
															__lowercase 			=							union_find.find(lowerCAmelCase__						)
															__lowercase 			=							union_find.find(lowerCAmelCase__						)
															if seta != seta:
																			if cheap_edge[seta] == -1 or cheap_edge[seta][2] > weight:
																							__lowercase 			=							[head, tail, weight]

																			if cheap_edge[seta] == -1 or cheap_edge[seta][2] > weight:
																							__lowercase 			=							[head, tail, weight]
											for vertex in cheap_edge:
															if cheap_edge[vertex] != -1:
																			__lowercase			,     __lowercase			,     __lowercase 			=							cheap_edge[vertex]
																			if union_find.find(lowerCAmelCase__						) != union_find.find(lowerCAmelCase__						):
																							union_find.union(lowerCAmelCase__      ,   lowerCAmelCase__						)
																							mst_edges.append(cheap_edge[vertex]						)
																							__lowercase 			=							num_components - 1
							__lowercase 			=							Graph.build(edges=lowerCAmelCase__						)
							return mst
from typing import List, Optional, TypeVar

from .arrow_dataset import Dataset, _concatenate_map_style_datasets, _interleave_map_style_datasets
from .dataset_dict import DatasetDict, IterableDatasetDict
from .info import DatasetInfo
from .iterable_dataset import IterableDataset, _concatenate_iterable_datasets, _interleave_iterable_datasets
from .splits import NamedSplit
from .utils import logging
from .utils.py_utils import Literal


__a  :     Optional[Any]       =  logging.get_logger(__name__)


__a  :     List[str]       =  TypeVar("""DatasetType""", Dataset, IterableDataset)





def 				UpperCAmelCase						(    lowercase							,			lowercase = None							,			lowercase = None							,			lowercase = None							,			lowercase = None							,			lowercase = "first_exhausted"							,			):







				"""simple docstring"""



				from .arrow_dataset import Dataset
				from .iterable_dataset import IterableDataset

				if not datasets:
								raise ValueError('''Unable to interleave an empty list of datasets.'''							)
				for i, dataset in enumerate(lowercase							):
								if not isinstance(lowercase							,			(Dataset, IterableDataset)							):
												if isinstance(lowercase							,			(DatasetDict, IterableDatasetDict)							):
																if not dataset:
																				raise ValueError(
																				    F"Expected a list of Dataset objects or a list of IterableDataset objects, but element at position {i} "
																				    '''is an empty dataset dictionary.'''							)
																raise ValueError(
																    F"Dataset at position {i} has at least one split: {list(lowercase							)}\n"
																    F"Please pick one to interleave with the other datasets, for example: dataset['{next(iter(lowercase							)							)}']"							)
												raise ValueError(
												    F"Expected a list of Dataset objects or a list of IterableDataset objects, but element at position {i} is a {type(lowercase							).__name__}."							)
								if i == 0:
												__lowercase			,     __lowercase 			=							(
												    (Dataset, IterableDataset) if isinstance(lowercase							,			lowercase							) else (IterableDataset, Dataset)
												)
								elif not isinstance(lowercase							,			lowercase							):
												raise ValueError(
												    F"Unable to interleave a {dataset_type.__name__} (at position 0) with a {other_type.__name__} (at position {i}). Expected a list of Dataset objects or a list of IterableDataset objects."							)
				if stopping_strategy not in ["first_exhausted", "all_exhausted"]:
								raise ValueError(F"{stopping_strategy} is not supported. Please enter a valid stopping_strategy."							)
				if dataset_type is Dataset:
								return _interleave_map_style_datasets(
								    lowercase							,			lowercase							,			lowercase							,			info=lowercase							,			split=lowercase							,			stopping_strategy=lowercase							)
				else:
								return _interleave_iterable_datasets(
								    lowercase							,			lowercase							,			lowercase							,			info=lowercase							,			split=lowercase							,			stopping_strategy=lowercase							)





def 				UpperCAmelCase						(    lowercase							,			lowercase = None							,			lowercase = None							,			lowercase = 0							,			):







				"""simple docstring"""



				if not dsets:
								raise ValueError('''Unable to concatenate an empty list of datasets.'''							)
				for i, dataset in enumerate(lowercase							):
								if not isinstance(lowercase							,			(Dataset, IterableDataset)							):
												if isinstance(lowercase							,			(DatasetDict, IterableDatasetDict)							):
																if not dataset:
																				raise ValueError(
																				    F"Expected a list of Dataset objects or a list of IterableDataset objects, but element at position {i} "
																				    '''is an empty dataset dictionary.'''							)
																raise ValueError(
																    F"Dataset at position {i} has at least one split: {list(lowercase							)}\n"
																    F"Please pick one to interleave with the other datasets, for example: dataset['{next(iter(lowercase							)							)}']"							)
												raise ValueError(
												    F"Expected a list of Dataset objects or a list of IterableDataset objects, but element at position {i} is a {type(lowercase							).__name__}."							)
								if i == 0:
												__lowercase			,     __lowercase 			=							(
												    (Dataset, IterableDataset) if isinstance(lowercase							,			lowercase							) else (IterableDataset, Dataset)
												)
								elif not isinstance(lowercase							,			lowercase							):
												raise ValueError(
												    F"Unable to interleave a {dataset_type.__name__} (at position 0) with a {other_type.__name__} (at position {i}). Expected a list of Dataset objects or a list of IterableDataset objects."							)
				if dataset_type is Dataset:
								return _concatenate_map_style_datasets(lowercase							,			info=lowercase							,			split=lowercase							,			axis=lowercase							)
				else:
								return _concatenate_iterable_datasets(lowercase							,			info=lowercase							,			split=lowercase							,			axis=lowercase							)