{"record":{"id":"45d59c1b86e9e471","repo":"krahets/hello-algo","slug":"error-45d59c","errorCode":null,"errorMessage":"очередь заполнена","messagePattern":"очередь заполнена","errorType":"exception","errorClass":"IndexError","httpStatus":null,"severity":"error","filePath":"ru/codes/python/chapter_stack_and_queue/array_queue.py","lineNumber":32,"sourceCode":"        self._front: int = 0  # Указатель head, указывающий на первый элемент очереди\n        self._size: int = 0  # Длина очереди\n\n    def capacity(self) -> int:\n        \"\"\"Получить вместимость очереди\"\"\"\n        return len(self._nums)\n\n    def size(self) -> int:\n        \"\"\"Получение длины очереди\"\"\"\n        return self._size\n\n    def is_empty(self) -> bool:\n        \"\"\"Проверка, пуста ли очередь\"\"\"\n        return self._size == 0\n\n    def push(self, num: int):\n        \"\"\"Поместить в очередь\"\"\"\n        if self._size == self.capacity():\n            raise IndexError(\"очередь заполнена\")\n        # Вычислить указатель хвоста, указывающий на индекс хвоста + 1\n        # С помощью операции взятия по модулю вернуть rear к началу после выхода за конец массива\n        rear: int = (self._front + self._size) % self.capacity()\n        # Добавить num в хвост очереди\n        self._nums[rear] = num\n        self._size += 1\n\n    def pop(self) -> int:\n        \"\"\"Извлечь из очереди\"\"\"\n        num: int = self.peek()\n        # Указатель head сдвигается на одну позицию назад; если он выходит за конец, то возвращается в начало массива\n        self._front = (self._front + 1) % self.capacity()\n        self._size -= 1\n        return num\n\n    def peek(self) -> int:\n        \"\"\"Доступ к элементу в начале очереди\"\"\"\n        if self.is_empty():","sourceCodeStart":14,"sourceCodeEnd":50,"githubUrl":"https://github.com/krahets/hello-algo/blob/69932aed1891a7b7f6a0de88cd116d3fe13e7032/ru/codes/python/chapter_stack_and_queue/array_queue.py#L14-L50","documentation":"Raised by ArrayQueue.push(num) in chapter_stack_and_queue/array_queue.py:32 — IndexError(\"очередь заполнена\" = \"queue is full\"). ArrayQueue is a FIXED-capacity ring buffer (no auto-grow); push refuses when _size == capacity(). This is the defining constraint of the type and the one error that is not an empty-state error but a full-state error.","triggerScenarios":"Pushing more items than the capacity given at construction. A producer outrunning a consumer so the buffer fills. Reusing a queue without draining between batches.","commonSituations":"Default/under-sized capacity for the workload. Forgetting the queue does not resize (unlike collections.deque). Backpressure not implemented upstream.","solutions":["Check before push: if q.size() < q.capacity(): q.push(x) else: <backpressure/drop>.","Construct with a larger capacity sized to peak load.","Drain (pop) before pushing when full.","Wrap push in try/except IndexError to implement drop-newest backpressure."],"exampleFix":"// before\nq.push(x)\n// after\nif q.size() < q.capacity():\n    q.push(x)\nelse:\n    q.pop()      # drop oldest\n    q.push(x)","handlingStrategy":"validation","validationCode":"def safe_push(q, x):\n    if q.size() < q.capacity():\n        q.push(x)\n        return True\n    return False  # apply backpressure","typeGuard":"def queue_has_room(q) -> bool:\n    return q.size() < q.capacity()","tryCatchPattern":"try:\n    q.push(x)\nexcept IndexError:\n    # queue full — drop oldest, newest, or block\n    q.pop()\n    q.push(x)","preventionTips":["Size capacity to peak load at construction","This queue does NOT auto-grow — unlike collections.deque","Implement backpressure (drop-oldest or drop-newest) at the call site"],"tags":["indexerror","queue","ring-buffer","fixed-capacity","backpressure","python"],"backgroundTag":null,"analyzedSha":"69932aed1891a7b7f6a0de88cd116d3fe13e7032","analyzedAt":"2026-08-13T23:02:37.581Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}