resize rebuilds buf with head back at index 0, sized to 2*count but never below minLen so the zero value of Queue grows on first Add.
()
| 20 | // resize rebuilds buf with head back at index 0, sized to 2*count but never |
| 21 | // below minLen so the zero value of Queue grows on first Add. |
| 22 | func (q *Queue[T]) resize() { |
| 23 | newBuf := make([]T, max(minLen, q.count<<1)) |
| 24 | if q.tail > q.head { |
| 25 | copy(newBuf, q.buf[q.head:q.tail]) |
| 26 | } else { |
| 27 | n := copy(newBuf, q.buf[q.head:]) |
| 28 | copy(newBuf[n:], q.buf[:q.tail]) |
| 29 | } |
| 30 | q.head = 0 |
| 31 | q.tail = q.count |
| 32 | q.buf = newBuf |
| 33 | } |
| 34 | |
| 35 | // Add appends elem, growing the buffer if it is full. |
| 36 | func (q *Queue[T]) Add(elem T) { |