File tree Expand file tree Collapse file tree 2 files changed +9
-4
lines changed Expand file tree Collapse file tree 2 files changed +9
-4
lines changed Original file line number Diff line number Diff line change @@ -83,12 +83,13 @@ func (q *Queue) Get(i int) interface{} {
8383return q .buf [(q .head + i )& (len (q .buf )- 1 )]
8484}
8585
86- // Remove removes the element from the front of the queue. If you actually
87- // want the element, call Peek first. This call panics if the queue is empty .
88- func (q * Queue ) Remove () {
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 {} {
8989if q .count <= 0 {
9090panic ("queue: Remove() called on empty queue" )
9191}
92+ ret := q .buf [q .head ]
9293q .buf [q .head ] = nil
9394// bitwise modulus
9495q .head = (q .head + 1 ) & (len (q .buf ) - 1 )
@@ -97,4 +98,5 @@ func (q *Queue) Remove() {
9798if len (q .buf ) > minQueueLen && (q .count << 2 ) == len (q .buf ) {
9899q .resize ()
99100}
101+ return ret
100102}
Original file line number Diff line number Diff line change @@ -12,7 +12,10 @@ func TestQueueSimple(t *testing.T) {
1212if q .Peek ().(int ) != i {
1313t .Error ("peek" , i , "had value" , q .Peek ())
1414}
15- q .Remove ()
15+ x := q .Remove ()
16+ if x != i {
17+ t .Error ("remove" , i , "had value" , x )
18+ }
1619}
1720}
1821
You can’t perform that action at this time.
0 commit comments