Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
remove breaking change
  • Loading branch information
gurgunday committed Feb 26, 2025
commit db55a715dcde58ce6d87e9cbfd7f980b3e545fd1
9 changes: 4 additions & 5 deletions lib/internal/priority_queue.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,11 @@ module.exports = class PriorityQueue {
}

removeAt(pos) {
if (pos > this.#size) return;

const heap = this.#heap;
const size = --this.#size;
heap[pos] = heap[size + 1];
heap[size + 1] = undefined;
let size = this.#size;
heap[pos] = heap[size];
heap[size] = undefined;
size = --this.#size;

if (size > 0 && pos <= size) {
if (pos > 1 && this.#compare(heap[pos >> 1], heap[pos]) > 0)
Expand Down
3 changes: 0 additions & 3 deletions test/parallel/test-priority-queue.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,6 @@ const PriorityQueue = require('internal/priority_queue');
// Check that removing the last item doesn't throw
queue.removeAt(6);

// Check that removing an item that doesn't exist doesn't throw
queue.removeAt(15);

assert.strictEqual(queue.shift().value, 1);
assert.strictEqual(queue.shift().value, 2);
assert.strictEqual(queue.shift().value, 2);
Expand Down
Loading