Skip to content

Commit

Permalink
Fix emptying head with remove lead to wrong isEmpty behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
JaoodxD committed May 14, 2024
1 parent aefcc95 commit bd776c5
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/fixed-queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ export default class FixedQueue implements TaskQueue {
}

remove (task: Task) {
let prev = null;
let prev: FixedCircularBuffer | null = null;
let buffer = this.tail;
while (true) {
if (buffer.list.includes(task)) {
Expand All @@ -166,11 +166,17 @@ export default class FixedQueue implements TaskQueue {
buffer = buffer.next;
}
if (buffer.isEmpty()) {
if (prev !== null) {
prev.next = buffer.next;
// removing tail
if (prev === null) {
// if tail is not the last buffer
if (buffer.next !== null) this.tail = buffer.next;
} else {
if (buffer.next) {
this.tail = buffer.next;
// removing head
if (buffer.next === null) {
this.head = prev;
} else {
// removing buffer from middle
prev.next = buffer.next;
}
}
}
Expand Down

0 comments on commit bd776c5

Please sign in to comment.