Remove removes and returns the element from the front of the queue. If the queue is empty, the call will panic.
()
| 86 | // Remove removes and returns the element from the front of the queue. If the |
| 87 | // queue is empty, the call will panic. |
| 88 | func (q *Queue) Remove() interface{} { |
| 89 | if q.count <= 0 { |
| 90 | panic("queue: Remove() called on empty queue") |
| 91 | } |
| 92 | ret := q.buf[q.head] |
| 93 | q.buf[q.head] = nil |
| 94 | // bitwise modulus |
| 95 | q.head = (q.head + 1) & (len(q.buf) - 1) |
| 96 | q.count-- |
| 97 | // Resize down if buffer 1/4 full. |
| 98 | if len(q.buf) > minQueueLen && (q.count<<2) == len(q.buf) { |
| 99 | q.resize() |
| 100 | } |
| 101 | return ret |
| 102 | } |