aboutsummaryrefslogtreecommitdiffstats
path: root/deque.go
diff options
context:
space:
mode:
authorRose Hogenson <rosehogenson@posteo.net>2025-04-11 16:51:37 -0700
committerRose Hogenson <rosehogenson@posteo.net>2025-04-11 16:51:37 -0700
commitbcc8f03b95c35e8988f90e5fd3b58112fd634016 (patch)
treea07e5254312bb04b3f4e78792c0a6c87f79662fa /deque.go
parent43e0f85d803045a073e2c78063bd8bc944d0fe68 (diff)
downloaddeque-bcc8f03b95c35e8988f90e5fd3b58112fd634016.tar.zst
Fix a bug in PopAll when the queue is full
Diffstat (limited to 'deque.go')
-rw-r--r--deque.go9
1 files changed, 2 insertions, 7 deletions
diff --git a/deque.go b/deque.go
index 1208019..d4ef4be 100644
--- a/deque.go
+++ b/deque.go
@@ -182,15 +182,10 @@ func (q *Deque[T]) PopAll() func(func(T) bool) {
n := len(q.buf)
q.buf = q.buf[:0]
return func(yield func(T) bool) {
- endIdx := q.toPhysicalIdx(n)
- for i := q.head; ; {
- if !yield(q.buf[:cap(q.buf)][i]) {
+ for i := range n {
+ if !yield(q.buf[:cap(q.buf)][q.toPhysicalIdx(i)]) {
return
}
- i = q.wrapAdd(i, 1)
- if i == endIdx {
- break
- }
}
}
}