Package list golang-gopkg-eapache-queue.v1 / 44cc805
Merge pull request #13 from gammazero/master Remove() returns item removed. Evan Huus authored 4 years ago GitHub committed 4 years ago
2 changed file(s) with 9 addition(s) and 4 deletion(s). Raw diff Collapse all Expand all
8282 return q.buf[(q.head+i)&(len(q.buf)-1)]
8383 }
8484
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{} {
8888 if q.count <= 0 {
8989 panic("queue: Remove() called on empty queue")
9090 }
91 ret := q.buf[q.head]
9192 q.buf[q.head] = nil
9293 // bitwise modulus
9394 q.head = (q.head + 1) & (len(q.buf) - 1)
9697 if len(q.buf) > minQueueLen && (q.count<<2) == len(q.buf) {
9798 q.resize()
9899 }
100 return ret
99101 }
1111 if q.Peek().(int) != i {
1212 t.Error("peek", i, "had value", q.Peek())
1313 }
14 q.Remove()
14 x := q.Remove()
15 if x != i {
16 t.Error("remove", i, "had value", x)
17 }
1518 }
1619 }
1720