Add puts an element on the end of the queue.
(elem interface{})
| 48 | |
| 49 | // Add puts an element on the end of the queue. |
| 50 | func (q *Queue) Add(elem interface{}) { |
| 51 | if q.count == len(q.buf) { |
| 52 | q.resize() |
| 53 | } |
| 54 | |
| 55 | q.buf[q.tail] = elem |
| 56 | // bitwise modulus |
| 57 | q.tail = (q.tail + 1) & (len(q.buf) - 1) |
| 58 | q.count++ |
| 59 | } |
| 60 | |
| 61 | // Peek returns the element at the head of the queue. This call panics |
| 62 | // if the queue is empty. |