resizes the queue to fit exactly twice its current contents this can result in shrinking if the queue is less than half-full
()
| 32 | // resizes the queue to fit exactly twice its current contents |
| 33 | // this can result in shrinking if the queue is less than half-full |
| 34 | func (q *Queue) resize() { |
| 35 | newBuf := make([]interface{}, q.count<<1) |
| 36 | |
| 37 | if q.tail > q.head { |
| 38 | copy(newBuf, q.buf[q.head:q.tail]) |
| 39 | } else { |
| 40 | n := copy(newBuf, q.buf[q.head:]) |
| 41 | copy(newBuf[n:], q.buf[:q.tail]) |
| 42 | } |
| 43 | |
| 44 | q.head = 0 |
| 45 | q.tail = q.count |
| 46 | q.buf = newBuf |
| 47 | } |
| 48 | |
| 49 | // Add puts an element on the end of the queue. |
| 50 | func (q *Queue) Add(elem interface{}) { |