{"record":{"id":"a00ab14b5f8b2e34","repo":"krahets/hello-algo","slug":"error-a00ab1","errorCode":null,"errorMessage":"очередь заполнена","messagePattern":"очередь заполнена","errorType":"exception","errorClass":"IndexError","httpStatus":null,"severity":"error","filePath":"ru/codes/ruby/chapter_stack_and_queue/array_queue.rb","lineNumber":31,"sourceCode":"  def initialize(size)\n    @nums = Array.new(size, 0) # Массив для хранения элементов очереди\n    @front = 0 # Указатель head, указывающий на первый элемент очереди\n    @size = 0 # Длина очереди\n  end\n\n  ### Получить вместимость очереди ###\n  def capacity\n    @nums.length\n  end\n\n  ### Проверка, пуста ли очередь ###\n  def is_empty?\n    size.zero?\n  end\n\n  ### Добавление в очередь ###\n  def push(num)\n    raise IndexError, 'очередь заполнена' if size == capacity\n\n    # Вычислить указатель хвоста, указывающий на индекс хвоста + 1\n    # С помощью операции взятия по модулю вернуть rear к началу после выхода за конец массива\n    rear = (@front + size) % capacity\n    # Добавить num в хвост очереди\n    @nums[rear] = num\n    @size += 1\n  end\n\n  ### Извлечение из очереди ###\n  def pop\n    num = peek\n    # Указатель head сдвигается на одну позицию назад; если он выходит за конец, то возвращается в начало массива\n    @front = (@front + 1) % capacity\n    @size -= 1\n    num\n  end\n","sourceCodeStart":13,"sourceCodeEnd":49,"githubUrl":"https://github.com/krahets/hello-algo/blob/69932aed1891a7b7f6a0de88cd116d3fe13e7032/ru/codes/ruby/chapter_stack_and_queue/array_queue.rb#L13-L49","documentation":"Raised by ArrayQueue#push (ru) when `size == capacity` — this is a FULL condition, not empty. ArrayQueue wraps a fixed-size circular array sized at construction (`initialize(size)`); there is no auto-grow, so push raises IndexError 'очередь заполнена' once the ring is full. This is the ONLY capacity error in the set and reflects the bounded-buffer design.","triggerScenarios":"Calling `queue.push(num)` more than `capacity` times without intervening pops; constructing `ArrayQueue.new(n)` and pushing n+1 items. The circular ring cannot grow past the constructor-given size.","commonSituations":"Producer faster than consumer in a fixed-capacity queue; sizing the queue too small for the workload; assuming auto-resize like a Ruby Array (it does not).","solutions":["Check `queue.size < queue.capacity` before push, and backpressure/skip when full.","Construct the queue with a larger capacity up front: `ArrayQueue.new(larger_n)`.","If unbounded growth is required, use a linked-list queue (LinkedListQueue) instead of the fixed ring.","Pop before pushing to free a slot in steady-state ring usage."],"exampleFix":"// before\nqueue.push(num)  # raises 'очередь заполнена' once full\n\n// after\nqueue.push(num) unless queue.size == queue.capacity","handlingStrategy":"validation","validationCode":"queue.push(num) unless queue.size == queue.capacity","typeGuard":"def queue_has_room?(q) = q.size < q.capacity","tryCatchPattern":"begin\n  queue.push(num)\nrescue IndexError => e\n  raise unless e.message == 'очередь заполнена'\n  # apply backpressure: drop, retry, or grow by recreating\nend","preventionTips":["ArrayQueue capacity is fixed at construction — size it for peak load.","Check size < capacity before push, or apply backpressure.","For unbounded growth use LinkedListQueue, not the ring.","Remember this is the only 'full' (capacity) error in the set."],"tags":["ruby","queue","circular-array","capacity","bounded-buffer","index-error"],"backgroundTag":null,"analyzedSha":"69932aed1891a7b7f6a0de88cd116d3fe13e7032","analyzedAt":"2026-08-13T23:02:37.581Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}