class_docstr: FIFO queue with fast indexing
  
  Operations getitem, setitem, append, popleft, and len
  are amortized O(1)-time, if this data structure is used ephemerally.
class_docstr_tok: ["FIFO","queue","with","fast","indexing","Operations","getitem",",","setitem",",","append",",","popleft",",","and","len","are","amortized","O","(","1",")","-time",",","if","this","data","structure","is","used","ephemerally","."]
code: def __setitem__(self, i, x):
      if i >= 0:
          nf = len(self._queue_front)
          if i < nf:
              self._queue_front[~i] = x
          else:
              i -= nf
              if i < len(self._queue_back):
                  self._queue_back[i] = x
              else:
                  raise IndexError(
                      "RandomAccessQueue index out of range"
                  )
  
      else:
          nb = len(self._queue_back)
          if i >= -nb:
              self._queue_back[i] = x
          else:
              i += nb
              if i >= -len(self._queue_front):
                  self._queue_front[~i] = x
              else:
                  raise IndexError(
                      "RandomAccessQueue index out of range"
                  )
  
file_path: chainerrl/chainerrl/misc/collections.py
imports: import itertools
  from chainerrl.misc.random import sample_n_k
label_desc: Use image node_id 7 for calling the RandomAccessQueue obj's underlying member method code with example usage: obj.__setitem__(i, x) without return types