@cldmv/holdmytask 1.6.0 → 1.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/utils.mjs DELETED
@@ -1,120 +0,0 @@
1
- /**
2
- * @Project: @cldmv/holdmytask
3
- * @Filename: /src/utils.mjs
4
- * @Date: 2025-11-08 17:43:09 -08:00 (1762652589)
5
- * @Author: Nate Hyson <CLDMV>
6
- * @Email: <Shinrai@users.noreply.github.com>
7
- * -----
8
- * @Last modified by: Nate Hyson <CLDMV> (Shinrai@users.noreply.github.com)
9
- * @Last modified time: 2025-11-09 16:22:05 -08:00 (1762734125)
10
- * -----
11
- * @Copyright: Copyright (c) 2013-2025 Catalyzed Motivation Inc. All rights reserved.
12
- */
13
-
14
- /**
15
- * A min-heap implementation with custom comparison function.
16
- * Maintains the heap property where parent nodes are smaller than their children.
17
- */
18
- export class MinHeap {
19
- /**
20
- * Creates a new MinHeap with a custom comparison function.
21
- * @param {Function} compare - Comparison function that returns negative if a < b, positive if a > b, 0 if equal
22
- * @example
23
- * // Priority queue (higher priority = smaller value)
24
- * const heap = new MinHeap((a, b) => a.priority - b.priority);
25
- */
26
- constructor(compare) {
27
- this.heap = [];
28
- this.compare = compare;
29
- }
30
-
31
- /**
32
- * Adds an item to the heap, maintaining heap property.
33
- * @param {*} item - The item to add to the heap
34
- * @returns {void}
35
- * @example
36
- * heap.push({ value: 5, priority: 1 });
37
- */
38
- push(item) {
39
- this.heap.push(item);
40
- this.bubbleUp(this.heap.length - 1);
41
- }
42
-
43
- /**
44
- * Removes and returns the minimum item from the heap.
45
- * @returns {*|undefined} The minimum item, or undefined if heap is empty
46
- * @example
47
- * const min = heap.pop(); // Returns item with smallest comparison value
48
- */
49
- pop() {
50
- if (this.heap.length === 0) return undefined;
51
- const root = this.heap[0];
52
- const last = this.heap.pop();
53
- if (this.heap.length > 0) {
54
- this.heap[0] = last;
55
- this.sinkDown(0);
56
- }
57
- return root;
58
- }
59
-
60
- /**
61
- * Returns the minimum item without removing it from the heap.
62
- * @returns {*|undefined} The minimum item, or undefined if heap is empty
63
- * @example
64
- * const min = heap.peek(); // Look at minimum without removing
65
- */
66
- peek() {
67
- return this.heap[0];
68
- }
69
-
70
- /**
71
- * Returns the number of items in the heap.
72
- * @returns {number} The size of the heap
73
- * @example
74
- * const count = heap.size(); // 5
75
- */
76
- size() {
77
- return this.heap.length;
78
- }
79
-
80
- /**
81
- * Moves an item up the heap to maintain heap property after insertion.
82
- * @param {number} index - Index of the item to bubble up
83
- * @returns {void}
84
- * @private
85
- */
86
- bubbleUp(index) {
87
- while (index > 0) {
88
- const parentIndex = Math.floor((index - 1) / 2);
89
- if (this.compare(this.heap[index], this.heap[parentIndex]) >= 0) break;
90
- [this.heap[index], this.heap[parentIndex]] = [this.heap[parentIndex], this.heap[index]];
91
- index = parentIndex;
92
- }
93
- }
94
-
95
- /**
96
- * Moves an item down the heap to maintain heap property after removal.
97
- * @param {number} index - Index of the item to sink down
98
- * @returns {void}
99
- * @private
100
- */
101
- sinkDown(index) {
102
- const length = this.heap.length;
103
- while (true) {
104
- let left = 2 * index + 1;
105
- let right = 2 * index + 2;
106
- let smallest = index;
107
-
108
- if (left < length && this.compare(this.heap[left], this.heap[smallest]) < 0) {
109
- smallest = left;
110
- }
111
- if (right < length && this.compare(this.heap[right], this.heap[smallest]) < 0) {
112
- smallest = right;
113
- }
114
- if (smallest === index) break;
115
-
116
- [this.heap[index], this.heap[smallest]] = [this.heap[smallest], this.heap[index]];
117
- index = smallest;
118
- }
119
- }
120
- }