'''simple docstring'''


from __future__ import annotations

from collections.abc import Iterable
from dataclasses import dataclass
from typing import Any






class      __SCREAMING_SNAKE_CASE						:







  '''simple docstring'''






  lowerCamelCase_		:Optional[Any]						    =		('''_front''', '''_back''', '''_len''')






  @dataclass
  class      __SCREAMING_SNAKE_CASE						:







    '''simple docstring'''






    lowerCamelCase_		:Any						    =		None
    lowerCamelCase_		:Deque._Node | None						    =		None
    lowerCamelCase_		:Deque._Node | None						    =		None







  class      __SCREAMING_SNAKE_CASE						:







    '''simple docstring'''






    lowerCamelCase_		:List[str]						    =		('''_cur''',)


    def __init__( self      ,		snake_case_						):




         '''simple docstring'''

         UpperCAmelCase_							:   Dict   =      cur


    def __iter__( self						):




         '''simple docstring'''

         return self






    def _UpperCamelCase     ( self						):




         '''simple docstring'''

         if self._cur is None:
              # finished iterating
              raise StopIteration
         UpperCAmelCase_							:   int   =      self._cur.val
         UpperCAmelCase_							:   List[str]   =      self._cur.next_node

         return val







  def __init__( self      ,		snake_case_ = None						):




       '''simple docstring'''

       UpperCAmelCase_							:   Any   =      None
       UpperCAmelCase_							:   Any   =      None
       UpperCAmelCase_							:   int   =      0

       if iterable is not None:
            # append every value to the deque
            for val in iterable:
                 self.append(snake_case_						)


  def _UpperCamelCase     ( self      ,		snake_case_						):




       '''simple docstring'''

       UpperCAmelCase_							:   Any   =      self._Node(snake_case_      ,		snake_case_      ,		snake_case_						)
       if self.is_empty():
            # front = back
            UpperCAmelCase_							:   Tuple   =      node
            UpperCAmelCase_							:   int   =      1
       else:
            # connect nodes
            UpperCAmelCase_							:   Tuple   =      node
            UpperCAmelCase_							:   Optional[Any]   =      self._back
            UpperCAmelCase_							:   int   =      node  # assign new back to the new node

            self._len += 1

            # make sure there were no errors
            assert not self.is_empty(), "Error on appending value."


  def _UpperCamelCase     ( self      ,		snake_case_						):




       '''simple docstring'''

       UpperCAmelCase_							:   Any   =      self._Node(snake_case_      ,		snake_case_      ,		snake_case_						)
       if self.is_empty():
            # front = back
            UpperCAmelCase_							:   Dict   =      node
            UpperCAmelCase_							:   Union[str, Any]   =      1
       else:
            # connect nodes
            UpperCAmelCase_							:   Any   =      self._front
            UpperCAmelCase_							:   List[str]   =      node
            UpperCAmelCase_							:   int   =      node  # assign new front to the new node

            self._len += 1

            # make sure there were no errors
            assert not self.is_empty(), "Error on appending value."


  def _UpperCamelCase     ( self      ,		snake_case_						):




       '''simple docstring'''

       for val in iterable:
            self.append(snake_case_						)


  def _UpperCamelCase     ( self      ,		snake_case_						):




       '''simple docstring'''

       for val in iterable:
            self.appendleft(snake_case_						)


  def _UpperCamelCase     ( self						):




       '''simple docstring'''

       assert not self.is_empty(), "Deque is empty."

       UpperCAmelCase_							:   int   =      self._back
       UpperCAmelCase_							:   int   =      self._back.prev_node  # set new back
       # drop the last node - python will deallocate memory automatically
       UpperCAmelCase_							:   Dict   =      None

       self._len -= 1

       return topop.val


  def _UpperCamelCase     ( self						):




       '''simple docstring'''

       assert not self.is_empty(), "Deque is empty."

       UpperCAmelCase_							:   List[str]   =      self._front
       UpperCAmelCase_							:   Any   =      self._front.next_node  # set new front and drop the first node
       UpperCAmelCase_							:   List[str]   =      None

       self._len -= 1

       return topop.val


  def _UpperCamelCase     ( self						):




       '''simple docstring'''

       return self._front is None


  def __len__( self						):




       '''simple docstring'''

       return self._len


  def __eq__( self      ,		snake_case_						):




       '''simple docstring'''

       if not isinstance(snake_case_      ,		snake_case_						):
            return NotImplemented

       UpperCAmelCase_							:   Optional[Any]   =      self._front
       UpperCAmelCase_							:   Union[str, Any]   =      other._front

       # if the length of the dequeues are not the same, they are not equal
       if len(self						) != len(snake_case_						):
            return False

       while me is not None and oth is not None:
            # compare every value
            if me.val != oth.val:
                 return False
            UpperCAmelCase_							:   Union[str, Any]   =      me.next_node
            UpperCAmelCase_							:   Any   =      oth.next_node

       return True


  def __iter__( self						):




       '''simple docstring'''

       return Deque._Iterator(self._front						)






  def __repr__( self						):




       '''simple docstring'''

       UpperCAmelCase_							:   Dict   =      []
       UpperCAmelCase_							:   List[str]   =      self._front
       while aux is not None:
            # append the values in a list to display
            values_list.append(aux.val						)
            UpperCAmelCase_							:   Tuple   =      aux.next_node

       return F'''[{', '.join(repr(snake_case_						) for val in values_list						)}]'''


if __name__ == "__main__":
 import doctest

 doctest.testmod()







'''simple docstring'''


from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


snake_case__     :			Optional[Any]      			=  {'''configuration_nat''': ['''NAT_PRETRAINED_CONFIG_ARCHIVE_MAP''', '''NatConfig''']}


try:
 if not is_torch_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 snake_case__     :			Tuple      			=  [
     '''NAT_PRETRAINED_MODEL_ARCHIVE_LIST''',
     '''NatForImageClassification''',
     '''NatModel''',
     '''NatPreTrainedModel''',
     '''NatBackbone''',
 ]

if TYPE_CHECKING:
 from .configuration_nat import NAT_PRETRAINED_CONFIG_ARCHIVE_MAP, NatConfig

 try:
  if not is_torch_available():
   raise OptionalDependencyNotAvailable()
 except OptionalDependencyNotAvailable:
  pass
 else:
  from .modeling_nat import (
      NAT_PRETRAINED_MODEL_ARCHIVE_LIST,
      NatBackbone,
      NatForImageClassification,
      NatModel,
      NatPreTrainedModel,
  )

else:
 import sys

 snake_case__     :			int      			=  _LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)






