





"""simple docstring"""


import json
import os
from dataclasses import dataclass

import numpy as np
import pyarrow as pa

import datasets
from utils import get_duration


a__       :  str       		=					1_0_0_0_0_0_0_0_0_0_0_0
a__       :  str       		=					1_0_0_0_0

a__       :  Optional[Any]       		=					os.path.split(__file__)
a__       :  Dict       		=					os.path.join(RESULTS_BASEPATH, """results""", RESULTS_FILENAME.replace(""".py""", """.json"""))





def 				a__      (	_UpperCAmelCase						,  _UpperCAmelCase						)     ->	datasets.Dataset:

 '''simple docstring'''






 snake_case__     				=					pa.Table.from_pydict({"col": [0] * chunk_size}						)
 snake_case__     				=					pa.concat_tables([table] * (num_examples // chunk_size)						)
 return datasets.Dataset(_UpperCAmelCase						,  fingerprint="table_100B"						)



@dataclass
class   lowercase_					:
       snake_case__					:				Optional[int]									=  42
       snake_case__					:				str									=  42
       snake_case__					:				Dict									=  42
       snake_case__					:				Any									=  42

       def 		_SCREAMING_SNAKE_CASE(      self  ):






        '''simple docstring'''

        snake_case__     				=					np.random.default_rng(self.seed  )
        snake_case__     				=					rng.integers(low=self.low ,       high=self.high ,       size=self.size  ).tolist()

       def __iter__(      self  ):






        '''simple docstring'''

        return iter(self._sampled_values  )

       def __len__(      self  ):






        '''simple docstring'''

        return self.size





@get_duration
def 				a__      (	_UpperCAmelCase						)     ->	int:

 '''simple docstring'''






 snake_case__     				=					dataset[0]





@get_duration
def 				a__      (	_UpperCAmelCase						)     ->	Optional[Any]:

 '''simple docstring'''






 snake_case__     				=					dataset[-1]





@get_duration
def 				a__      (	_UpperCAmelCase						)     ->	Optional[int]:

 '''simple docstring'''






 snake_case__     				=					dataset[range(len(_UpperCAmelCase						) // 2						,  len(_UpperCAmelCase						) // 2 + 1_0_2_4						)]





@get_duration
def 				a__      (	_UpperCAmelCase						)     ->	List[Any]:

 '''simple docstring'''






 snake_case__     				=					dataset[RandIter(0						,  len(_UpperCAmelCase						)						,  1_0_2_4						,  seed=4_2						)]





def 				a__      (	)     ->	Dict:

 '''simple docstring'''






 snake_case__     				=					{'num examples': SPEED_TEST_N_EXAMPLES}
 snake_case__     				=					(get_first_row, get_last_row, get_batch_of_aaaa_rows, get_batch_of_aaaa_random_rows)
 print("generating dataset"						)
 snake_case__     				=					generate_100B_dataset(num_examples=_UpperCAmelCase						,  chunk_size=_UpperCAmelCase						)
 print("Functions"						)
 for func in functions:
  print(func.__name__						)
  snake_case__     				=					func(_UpperCAmelCase						)

 with open(_UpperCAmelCase						,  "wb"						) as f:
  f.write(json.dumps(_UpperCAmelCase						).encode("utf-8"						)						)


if __name__ == "__main__":  # useful to run the profiler
   benchmark_table_100B()






"""simple docstring"""




from __future__ import annotations

from collections import defaultdict
from dataclasses import dataclass


@dataclass
class 	a__		:
   _lowerCamelCase       				=					42
   _lowerCamelCase       				=					None
   _lowerCamelCase       				=					None




def 	lowercase__  (      )  ->      TreeNode:






      '''simple docstring'''


      return TreeNode(3						,   TreeNode(9					)						,   TreeNode(20						,   TreeNode(15					)						,   TreeNode(7					)					)					)


def 	lowercase__  (      _UpperCAmelCase					)  ->      list[int]:






      '''simple docstring'''


      def depth_first_search(
          _UpperCAmelCase						,   _UpperCAmelCase						,   _UpperCAmelCase					) -> None:
            if not root:
                  return

            if depth == len(_UpperCAmelCase					):
                  right_view.append(root.val					)

            depth_first_search(root.right						,   depth + 1						,   _UpperCAmelCase					)
            depth_first_search(root.left						,   depth + 1						,   _UpperCAmelCase					)

      lowercase	:   list											= []
      if not root:
            return right_view

      depth_first_search(_UpperCAmelCase						,   0						,   _UpperCAmelCase					)
      return right_view


def 	lowercase__  (      _UpperCAmelCase					)  ->      list[int]:






      '''simple docstring'''


      def depth_first_search(
          _UpperCAmelCase						,   _UpperCAmelCase						,   _UpperCAmelCase					) -> None:
            if not root:
                  return

            if depth == len(_UpperCAmelCase					):
                  left_view.append(root.val					)

            depth_first_search(root.left						,   depth + 1						,   _UpperCAmelCase					)
            depth_first_search(root.right						,   depth + 1						,   _UpperCAmelCase					)

      lowercase	:   list											= []
      if not root:
            return left_view

      depth_first_search(_UpperCAmelCase						,   0						,   _UpperCAmelCase					)
      return left_view


def 	lowercase__  (      _UpperCAmelCase					)  ->      list[int]:






      '''simple docstring'''


      def breadth_first_search(_UpperCAmelCase						,   _UpperCAmelCase					) -> None:
            lowercase	:   List[str]											= [(root, 0)]
            lowercase	:   List[Any]											= defaultdict(_UpperCAmelCase					)

            while queue:
                  lowercase	:   Union[str, Any]											= queue.pop(0					)
                  lowercase						,     lowercase	:   str											= first

                  lookup[hd].append(node.val					)

                  if node.left:
                        queue.append((node.left, hd - 1)					)
                  if node.right:
                        queue.append((node.right, hd + 1)					)

            for pair in sorted(lookup.items()						,   key=lambda _UpperCAmelCase					: each[0]					):
                  top_view.append(pair[1][0]					)

      lowercase	:   list											= []
      if not root:
            return top_view

      breadth_first_search(_UpperCAmelCase						,   _UpperCAmelCase					)
      return top_view


def 	lowercase__  (      _UpperCAmelCase					)  ->      list[int]:






      '''simple docstring'''


      from collections import defaultdict

      def breadth_first_search(_UpperCAmelCase						,   _UpperCAmelCase					) -> None:
            lowercase	:   Any											= [(root, 0)]
            lowercase	:   Dict											= defaultdict(_UpperCAmelCase					)

            while queue:
                  lowercase	:   str											= queue.pop(0					)
                  lowercase						,     lowercase	:   List[Any]											= first
                  lookup[hd].append(node.val					)

                  if node.left:
                        queue.append((node.left, hd - 1)					)
                  if node.right:
                        queue.append((node.right, hd + 1)					)

            for pair in sorted(lookup.items()						,   key=lambda _UpperCAmelCase					: each[0]					):
                  bottom_view.append(pair[1][-1]					)

      lowercase	:   list											= []
      if not root:
            return bottom_view

      breadth_first_search(_UpperCAmelCase						,   _UpperCAmelCase					)
      return bottom_view


if __name__ == "__main__":
     import doctest

     doctest.testmod()
