Merge pull request #13 from gammazero/master
Remove() returns item removed.
Evan Huus authored 7 years ago
GitHub committed 7 years ago
82 | 82 | return q.buf[(q.head+i)&(len(q.buf)-1)] |
83 | 83 | } |
84 | 84 | |
85 | // Remove removes the element from the front of the queue. If you actually | |
86 | // want the element, call Peek first. This call panics if the queue is empty. | |
87 | func (q *Queue) Remove() { | |
85 | // Remove removes and returns the element from the front of the queue. If the | |
86 | // queue is empty, the call will panic. | |
87 | func (q *Queue) Remove() interface{} { | |
88 | 88 | if q.count <= 0 { |
89 | 89 | panic("queue: Remove() called on empty queue") |
90 | 90 | } |
91 | ret := q.buf[q.head] | |
91 | 92 | q.buf[q.head] = nil |
92 | 93 | // bitwise modulus |
93 | 94 | q.head = (q.head + 1) & (len(q.buf) - 1) |
96 | 97 | if len(q.buf) > minQueueLen && (q.count<<2) == len(q.buf) { |
97 | 98 | q.resize() |
98 | 99 | } |
100 | return ret | |
99 | 101 | } |