{"record":{"id":"a25193b75bd74cae","repo":"krahets/hello-algo","slug":"error-a25193","errorCode":null,"errorMessage":"キューがいっぱいです","messagePattern":"キューがいっぱいです","errorType":"exception","errorClass":"IndexError","httpStatus":null,"severity":"error","filePath":"ja/codes/python/chapter_stack_and_queue/array_queue.py","lineNumber":32,"sourceCode":"        self._front: int = 0  # 先頭ポインタ。先頭要素を指す\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        # 先頭ポインタを1つ後ろへ進め、末尾を越えたら配列先頭に戻す\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/ja/codes/python/chapter_stack_and_queue/array_queue.py#L14-L50","documentation":"This IndexError (Japanese: 'キューがいっぱいです' = 'queue is full') is raised by ArrayQueue.push(num) (array_queue.py:32) when the number of live elements equals the backing array length. ArrayQueue is a fixed-capacity circular-array queue — unlike the deque in this repo, the queue does NOT auto-grow, so pushing past capacity is a hard error. The capacity is the integer passed to the constructor `ArrayQueue(size)`.","triggerScenarios":"Calling push() after `self._size == self.capacity()`. Pushing more than the constructor-supplied size elements without an equal number of pop() calls. Using a small capacity (e.g. ArrayQueue(5)) and pushing 6 times.","commonSituations":"Underestimating the required capacity at construction time. Producer faster than consumer in a producer/consumer setup with no backpressure check. Confusing this fixed-capacity queue with Python's unbounded collections.deque. The driver loop at the bottom of the file pushes then pops each round to stay within capacity — omitting the pop triggers this.","solutions":["Check `if queue.size() < queue.capacity(): queue.push(num)` before pushing.","Size the constructor capacity to the maximum concurrent elements: `ArrayQueue(max_concurrent)`.","In a producer/consumer pattern, pop() before push() when at capacity, or use a growable structure.","Wrap push in try/except IndexError if dropping on full is acceptable."],"exampleFix":"// before\nq = ArrayQueue(5)\nfor i in range(10):\n    q.push(i)  # IndexError on the 6th push\n\n// after\nq = ArrayQueue(5)\nfor i in range(10):\n    if q.size() == q.capacity():\n        q.pop()\n    q.push(i)","handlingStrategy":"validation","validationCode":"if queue.size() < queue.capacity():\n    queue.push(num)\nelse:\n    # at capacity: pop first, resize at construction, or drop\n    pass","typeGuard":"def queue_has_room(q: ArrayQueue) -> bool:\n    return q.size() < q.capacity()","tryCatchPattern":"try:\n    queue.push(num)\nexcept IndexError:\n    # queue full — enqueue failed; apply backpressure or drop\n    pass","preventionTips":["Size ArrayQueue(max_concurrent) to the peak number of simultaneous elements.","Check size() < capacity() before push — the queue does NOT auto-grow.","In producer/consumer code, pop before push when full, or switch to a growable structure.","Do not confuse this fixed-capacity queue with Python's unbounded collections.deque."],"tags":["queue","python","index-error","capacity","circular-array"],"backgroundTag":null,"analyzedSha":"69932aed1891a7b7f6a0de88cd116d3fe13e7032","analyzedAt":"2026-08-13T23:02:37.581Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}