operator []= method

void operator []=(
  1. int index,
  2. T value
)

Operator overload for setting an element at index. Note: O(N) complexity as it requires rebuilding parts of the queue.

Implementation

void operator []=(int index, T value) {
  if (index < 0 || index >= _queue.length) {
    throw RangeError.index(index, this, 'Index out of bounds');
  }
  final list = _queue.toList();
  list[index] = value;
  _queue.clear();
  _queue.addAll(list);
}