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{} {
83
83
return q .buf [(q .head + i )& (len (q .buf )- 1 )]
84
84
}
85
85
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 {} {
89
89
if q .count <= 0 {
90
90
panic ("queue: Remove() called on empty queue" )
91
91
}
92
+ ret := q .buf [q .head ]
92
93
q .buf [q .head ] = nil
93
94
// bitwise modulus
94
95
q .head = (q .head + 1 ) & (len (q .buf ) - 1 )
@@ -97,4 +98,5 @@ func (q *Queue) Remove() {
97
98
if len (q .buf ) > minQueueLen && (q .count << 2 ) == len (q .buf ) {
98
99
q .resize ()
99
100
}
101
+ return ret
100
102
}
Original file line number Diff line number Diff line change @@ -12,7 +12,10 @@ func TestQueueSimple(t *testing.T) {
12
12
if q .Peek ().(int ) != i {
13
13
t .Error ("peek" , i , "had value" , q .Peek ())
14
14
}
15
- q .Remove ()
15
+ x := q .Remove ()
16
+ if x != i {
17
+ t .Error ("remove" , i , "had value" , x )
18
+ }
16
19
}
17
20
}
18
21
You can’t perform that action at this time.
0 commit comments