Add appends elem, growing the buffer if it is full.
(elem T)
| 34 | |
| 35 | // Add appends elem, growing the buffer if it is full. |
| 36 | func (q *Queue[T]) Add(elem T) { |
| 37 | if q.count == len(q.buf) { |
| 38 | q.resize() |
| 39 | } |
| 40 | q.buf[q.tail] = elem |
| 41 | q.tail = (q.tail + 1) & (len(q.buf) - 1) |
| 42 | q.count++ |
| 43 | } |
| 44 | |
| 45 | // Peek returns the head element. It panics if the queue is empty. |
| 46 | func (q *Queue[T]) Peek() T { |