]> Piment Noir Git Repositories - poolifier.git/commitdiff
refactor: add guard to priority queue delete()
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Wed, 20 Aug 2025 15:05:08 +0000 (17:05 +0200)
committerJérôme Benoit <jerome.benoit@piment-noir.org>
Wed, 20 Aug 2025 15:05:08 +0000 (17:05 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
src/queues/priority-queue.ts

index e90b4c3304a2392607d3ec2054b6bfc589706a92..bcd93cdabb40018a3a79ec00b8862a7dc5713a42 100644 (file)
@@ -93,6 +93,9 @@ export class PriorityQueue<T> {
    * @returns `true` if the data was deleted, `false` otherwise.
    */
   public delete (data: T): boolean {
+    if (this.size === 0) {
+      return false
+    }
     let node: PriorityQueueNode<T> | undefined = this.tail
     let prev: PriorityQueueNode<T> | undefined
     while (node != null) {