data-structure-typed 1.37.9 → 1.38.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.
Files changed (81) hide show
  1. package/dist/data-structures/binary-tree/avl-tree.d.ts +9 -9
  2. package/dist/data-structures/binary-tree/avl-tree.js +22 -22
  3. package/dist/data-structures/binary-tree/avl-tree.js.map +1 -1
  4. package/dist/data-structures/binary-tree/binary-tree.d.ts +31 -31
  5. package/dist/data-structures/binary-tree/binary-tree.js +32 -32
  6. package/dist/data-structures/binary-tree/binary-tree.js.map +1 -1
  7. package/dist/data-structures/binary-tree/bst.js.map +1 -1
  8. package/dist/data-structures/binary-tree/rb-tree.d.ts +1 -1
  9. package/dist/data-structures/binary-tree/rb-tree.js.map +1 -1
  10. package/dist/data-structures/binary-tree/tree-multiset.d.ts +9 -9
  11. package/dist/data-structures/binary-tree/tree-multiset.js +23 -23
  12. package/dist/data-structures/binary-tree/tree-multiset.js.map +1 -1
  13. package/dist/data-structures/hash/hash-map.d.ts +25 -25
  14. package/dist/data-structures/hash/hash-map.js +59 -59
  15. package/dist/data-structures/hash/hash-map.js.map +1 -1
  16. package/dist/data-structures/hash/hash-table.d.ts +34 -34
  17. package/dist/data-structures/hash/hash-table.js +99 -99
  18. package/dist/data-structures/hash/hash-table.js.map +1 -1
  19. package/dist/data-structures/heap/heap.d.ts +67 -68
  20. package/dist/data-structures/heap/heap.js +167 -167
  21. package/dist/data-structures/heap/heap.js.map +1 -1
  22. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +1 -1
  23. package/dist/data-structures/linked-list/doubly-linked-list.js +3 -3
  24. package/dist/data-structures/linked-list/doubly-linked-list.js.map +1 -1
  25. package/dist/data-structures/linked-list/skip-linked-list.d.ts +17 -17
  26. package/dist/data-structures/linked-list/skip-linked-list.js +34 -34
  27. package/dist/data-structures/linked-list/skip-linked-list.js.map +1 -1
  28. package/dist/data-structures/matrix/matrix2d.d.ts +7 -7
  29. package/dist/data-structures/matrix/matrix2d.js +9 -9
  30. package/dist/data-structures/matrix/matrix2d.js.map +1 -1
  31. package/dist/data-structures/trie/trie.d.ts +2 -2
  32. package/dist/data-structures/trie/trie.js +6 -6
  33. package/dist/data-structures/trie/trie.js.map +1 -1
  34. package/dist/types/data-structures/binary-tree/bst.d.ts +0 -5
  35. package/dist/types/data-structures/binary-tree/bst.js +0 -7
  36. package/dist/types/data-structures/binary-tree/bst.js.map +1 -1
  37. package/dist/types/helpers.d.ts +5 -0
  38. package/dist/types/helpers.js +7 -0
  39. package/dist/types/helpers.js.map +1 -1
  40. package/lib/data-structures/binary-tree/avl-tree.d.ts +9 -9
  41. package/lib/data-structures/binary-tree/avl-tree.js +22 -22
  42. package/lib/data-structures/binary-tree/binary-tree.d.ts +31 -31
  43. package/lib/data-structures/binary-tree/binary-tree.js +32 -32
  44. package/lib/data-structures/binary-tree/rb-tree.d.ts +1 -1
  45. package/lib/data-structures/binary-tree/tree-multiset.d.ts +9 -9
  46. package/lib/data-structures/binary-tree/tree-multiset.js +23 -23
  47. package/lib/data-structures/hash/hash-map.d.ts +25 -25
  48. package/lib/data-structures/hash/hash-map.js +59 -59
  49. package/lib/data-structures/hash/hash-table.d.ts +34 -34
  50. package/lib/data-structures/hash/hash-table.js +99 -99
  51. package/lib/data-structures/heap/heap.d.ts +67 -68
  52. package/lib/data-structures/heap/heap.js +167 -167
  53. package/lib/data-structures/linked-list/doubly-linked-list.d.ts +1 -1
  54. package/lib/data-structures/linked-list/doubly-linked-list.js +3 -3
  55. package/lib/data-structures/linked-list/skip-linked-list.d.ts +17 -17
  56. package/lib/data-structures/linked-list/skip-linked-list.js +34 -34
  57. package/lib/data-structures/matrix/matrix2d.d.ts +7 -7
  58. package/lib/data-structures/matrix/matrix2d.js +9 -9
  59. package/lib/data-structures/trie/trie.d.ts +2 -2
  60. package/lib/data-structures/trie/trie.js +6 -6
  61. package/lib/types/data-structures/binary-tree/bst.d.ts +0 -5
  62. package/lib/types/data-structures/binary-tree/bst.js +1 -6
  63. package/lib/types/helpers.d.ts +5 -0
  64. package/lib/types/helpers.js +6 -1
  65. package/package.json +7 -6
  66. package/src/data-structures/binary-tree/avl-tree.ts +27 -27
  67. package/src/data-structures/binary-tree/binary-tree.ts +55 -55
  68. package/src/data-structures/binary-tree/bst.ts +4 -0
  69. package/src/data-structures/binary-tree/rb-tree.ts +2 -2
  70. package/src/data-structures/binary-tree/tree-multiset.ts +29 -29
  71. package/src/data-structures/hash/hash-map.ts +81 -75
  72. package/src/data-structures/hash/hash-table.ts +112 -109
  73. package/src/data-structures/heap/heap.ts +183 -183
  74. package/src/data-structures/linked-list/doubly-linked-list.ts +4 -4
  75. package/src/data-structures/linked-list/skip-linked-list.ts +45 -38
  76. package/src/data-structures/matrix/matrix2d.ts +10 -10
  77. package/src/data-structures/trie/trie.ts +9 -9
  78. package/src/types/helpers.ts +5 -1
  79. package/test/unit/data-structures/binary-tree/binary-index-tree.test.ts +1 -1
  80. package/umd/bundle.min.js +1 -1
  81. package/umd/bundle.min.js.map +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"hash-table.js","sourceRoot":"","sources":["../../../src/data-structures/hash/hash-table.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;AAEH,MAAa,aAAa;IAKxB,YAAY,GAAM,EAAE,GAAM;QACxB,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;CACF;AAVD,sCAUC;AAID,MAAa,SAAS;IACpB,IAAI,MAAM;QACR,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IAED,IAAI,MAAM,CAAC,KAAsB;QAC/B,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC;IACvB,CAAC;IAED,IAAI,OAAO;QACT,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;IAED,IAAI,OAAO,CAAC,KAAwC;QAClD,I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AG,CAAC,CAAC;QACvC,MAAM,UAAU,GAAG,IAAI,KAAK,CAA6B,WAAW,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAEjF,KAAK,MAAM,MAAM,IAAI,IAAI,CAAC,QAAQ,EAAE;YAClC,IAAI,WAAW,GAAG,MAAM,CAAC;YACzB,OAAO,WAAW,EAAE;gBAClB,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;gBAC7C,MAAM,OAAO,GAAG,IAAI,aAAa,CAAO,WAAW,CAAC,GAAG,EAAE,WAAW,CAAC,GAAG,CAAC,CAAC;gBAE1E,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE;oBACzB,UAAU,CAAC,QAAQ,CAAC,GAAG,OAAO,CAAC;iBAChC;qBAAM;oBACL,IAAI,cAAc,GAAG,UAAU,CAAC,QAAQ,CAAE,CAAC;oBAC3C,OAAO,cAAc,CAAC,IAAI,EAAE;wBAC1B,cAAc,GAAG,cAAc,CAAC,IAAI,CAAC;qBACtC;oBACD,cAAc,CAAC,IAAI,GAAG,OAAO,CAAC;iBAC/B;gBACD,WAAW,GAAG,WAAW,CAAC,IAAI,CAAC;aAChC;SACF;QAED,IAAI,CAAC,QAAQ,GAAG,UAAU,CAAC;QAC3B,IAAI,CAAC,SAAS,GAAG,WAAW,CAAC;IAC/B,CAAC;;AAhQH,8BAiQC;AAhQyB,0BAAgB,GAAG,EAAE,CAAC;AACtB,qBAAW,GAAG,IAAI,CAAC"}
@@ -4,12 +4,27 @@
4
4
  * @copyright Copyright (c) 2022 Kirk Qi <qilinaus@gmail.com>
5
5
  * @license MIT License
6
6
  */
7
- import type { Comparator } from '../../types';
8
- import { DFSOrderPattern } from '../../types';
7
+ import type { Comparator, DFSOrderPattern } from '../../types';
9
8
  export declare class Heap<E> {
10
9
  protected nodes: E[];
11
10
  protected readonly comparator: Comparator<E>;
12
11
  constructor(comparator: Comparator<E>);
12
+ /**
13
+ * Get the size (number of elements) of the heap.
14
+ */
15
+ get size(): number;
16
+ /**
17
+ * Get the last element in the heap, which is not necessarily a leaf node.
18
+ * @returns The last element or undefined if the heap is empty.
19
+ */
20
+ get leaf(): E | undefined;
21
+ /**
22
+ * Static method that creates a binary heap from an array of nodes and a comparison function.
23
+ * @param nodes
24
+ * @param comparator - Comparison function.
25
+ * @returns A new Heap instance.
26
+ */
27
+ static heapify<E>(nodes: E[], comparator: Comparator<E>): Heap<E>;
13
28
  /**
14
29
  * Insert an element into the heap and maintain the heap properties.
15
30
  * @param element - The element to be inserted.
@@ -30,34 +45,11 @@ export declare class Heap<E> {
30
45
  * @returns The top element or undefined if the heap is empty.
31
46
  */
32
47
  pop(): E | undefined;
33
- /**
34
- * Float operation to maintain heap properties after adding an element.
35
- * @param index - The index of the newly added element.
36
- */
37
- protected bubbleUp(index: number): void;
38
- /**
39
- * Sinking operation to maintain heap properties after removing the top element.
40
- * @param index - The index from which to start sinking.
41
- */
42
- protected sinkDown(index: number): void;
43
- /**
44
- * Fix the entire heap to maintain heap properties.
45
- */
46
- protected fix(): void;
47
48
  /**
48
49
  * Peek at the top element of the heap without removing it.
49
50
  * @returns The top element or undefined if the heap is empty.
50
51
  */
51
52
  peek(): E | undefined;
52
- /**
53
- * Get the size (number of elements) of the heap.
54
- */
55
- get size(): number;
56
- /**
57
- * Get the last element in the heap, which is not necessarily a leaf node.
58
- * @returns The last element or undefined if the heap is empty.
59
- */
60
- get leaf(): E | undefined;
61
53
  /**
62
54
  * Check if the heap is empty.
63
55
  * @returns True if the heap is empty, otherwise false.
@@ -101,12 +93,19 @@ export declare class Heap<E> {
101
93
  */
102
94
  sort(): E[];
103
95
  /**
104
- * Static method that creates a binary heap from an array of nodes and a comparison function.
105
- * @param nodes
106
- * @param comparator - Comparison function.
107
- * @returns A new Heap instance.
96
+ * Float operation to maintain heap properties after adding an element.
97
+ * @param index - The index of the newly added element.
108
98
  */
109
- static heapify<E>(nodes: E[], comparator: Comparator<E>): Heap<E>;
99
+ protected bubbleUp(index: number): void;
100
+ /**
101
+ * Sinking operation to maintain heap properties after removing the top element.
102
+ * @param index - The index from which to start sinking.
103
+ */
104
+ protected sinkDown(index: number): void;
105
+ /**
106
+ * Fix the entire heap to maintain heap properties.
107
+ */
108
+ protected fix(): void;
110
109
  }
111
110
  export declare class FibonacciHeapNode<E> {
112
111
  element: E;
@@ -120,33 +119,15 @@ export declare class FibonacciHeapNode<E> {
120
119
  }
121
120
  export declare class FibonacciHeap<E> {
122
121
  root?: FibonacciHeapNode<E>;
123
- protected min?: FibonacciHeapNode<E>;
124
122
  size: number;
123
+ protected min?: FibonacciHeapNode<E>;
125
124
  protected readonly comparator: Comparator<E>;
126
125
  constructor(comparator?: Comparator<E>);
127
- /**
128
- * Default comparator function used by the heap.
129
- * @param {E} a
130
- * @param {E} b
131
- * @protected
132
- */
133
- protected defaultComparator(a: E, b: E): number;
134
126
  /**
135
127
  * Get the size (number of elements) of the heap.
136
128
  * @returns {number} The size of the heap. Returns 0 if the heap is empty. Returns -1 if the heap is invalid.
137
129
  */
138
130
  clear(): void;
139
- /**
140
- * Create a new node.
141
- * @param element
142
- * @protected
143
- */
144
- protected createNode(element: E): FibonacciHeapNode<E>;
145
- /**
146
- * Merge the given node with the root list.
147
- * @param node - The node to be merged.
148
- */
149
- protected mergeWithRoot(node: FibonacciHeapNode<E>): void;
150
131
  /**
151
132
  * O(1) time operation.
152
133
  * Insert an element into the heap and maintain the heap properties.
@@ -176,13 +157,6 @@ export declare class FibonacciHeap<E> {
176
157
  * @returns FibonacciHeapNode<E>[] - An array containing the nodes of the linked list.
177
158
  */
178
159
  consumeLinkedList(head?: FibonacciHeapNode<E>): FibonacciHeapNode<E>[];
179
- /**
180
- * O(log n) time operation.
181
- * Remove and return the top element (smallest or largest element) from the heap.
182
- * @param node - The node to be removed.
183
- * @protected
184
- */
185
- protected removeFromRoot(node: FibonacciHeapNode<E>): void;
186
160
  /**
187
161
  * O(log n) time operation.
188
162
  * Remove and return the top element (smallest or largest element) from the heap.
@@ -193,33 +167,58 @@ export declare class FibonacciHeap<E> {
193
167
  /**
194
168
  * O(log n) time operation.
195
169
  * Remove and return the top element (smallest or largest element) from the heap.
196
- * @param y
197
- * @param x
198
- * @protected
170
+ * @returns The top element or undefined if the heap is empty.
199
171
  */
200
- protected link(y: FibonacciHeapNode<E>, x: FibonacciHeapNode<E>): void;
172
+ poll(): E | undefined;
201
173
  /**
202
174
  * O(log n) time operation.
203
175
  * Remove and return the top element (smallest or largest element) from the heap.
176
+ * @returns The top element or undefined if the heap is empty.
177
+ */
178
+ pop(): E | undefined;
179
+ /**
180
+ * O(log n) time operation.
181
+ * merge two heaps. The heap that is merged will be cleared. The heap that is merged into will remain.
182
+ * @param heapToMerge
183
+ */
184
+ merge(heapToMerge: FibonacciHeap<E>): void;
185
+ /**
186
+ * Default comparator function used by the heap.
187
+ * @param {E} a
188
+ * @param {E} b
204
189
  * @protected
205
190
  */
206
- protected consolidate(): void;
191
+ protected defaultComparator(a: E, b: E): number;
192
+ /**
193
+ * Create a new node.
194
+ * @param element
195
+ * @protected
196
+ */
197
+ protected createNode(element: E): FibonacciHeapNode<E>;
198
+ /**
199
+ * Merge the given node with the root list.
200
+ * @param node - The node to be merged.
201
+ */
202
+ protected mergeWithRoot(node: FibonacciHeapNode<E>): void;
207
203
  /**
208
204
  * O(log n) time operation.
209
205
  * Remove and return the top element (smallest or largest element) from the heap.
210
- * @returns The top element or undefined if the heap is empty.
206
+ * @param node - The node to be removed.
207
+ * @protected
211
208
  */
212
- poll(): E | undefined;
209
+ protected removeFromRoot(node: FibonacciHeapNode<E>): void;
213
210
  /**
214
211
  * O(log n) time operation.
215
212
  * Remove and return the top element (smallest or largest element) from the heap.
216
- * @returns The top element or undefined if the heap is empty.
213
+ * @param y
214
+ * @param x
215
+ * @protected
217
216
  */
218
- pop(): E | undefined;
217
+ protected link(y: FibonacciHeapNode<E>, x: FibonacciHeapNode<E>): void;
219
218
  /**
220
219
  * O(log n) time operation.
221
- * merge two heaps. The heap that is merged will be cleared. The heap that is merged into will remain.
222
- * @param heapToMerge
220
+ * Remove and return the top element (smallest or largest element) from the heap.
221
+ * @protected
223
222
  */
224
- merge(heapToMerge: FibonacciHeap<E>): void;
223
+ protected consolidate(): void;
225
224
  }
@@ -12,6 +12,32 @@ class Heap {
12
12
  this.nodes = [];
13
13
  this.comparator = comparator;
14
14
  }
15
+ /**
16
+ * Get the size (number of elements) of the heap.
17
+ */
18
+ get size() {
19
+ return this.nodes.length;
20
+ }
21
+ /**
22
+ * Get the last element in the heap, which is not necessarily a leaf node.
23
+ * @returns The last element or undefined if the heap is empty.
24
+ */
25
+ get leaf() {
26
+ var _a;
27
+ return (_a = this.nodes[this.size - 1]) !== null && _a !== void 0 ? _a : undefined;
28
+ }
29
+ /**
30
+ * Static method that creates a binary heap from an array of nodes and a comparison function.
31
+ * @param nodes
32
+ * @param comparator - Comparison function.
33
+ * @returns A new Heap instance.
34
+ */
35
+ static heapify(nodes, comparator) {
36
+ const binaryHeap = new Heap(comparator);
37
+ binaryHeap.nodes = [...nodes];
38
+ binaryHeap.fix(); // Fix heap properties
39
+ return binaryHeap;
40
+ }
15
41
  /**
16
42
  * Insert an element into the heap and maintain the heap properties.
17
43
  * @param element - The element to be inserted.
@@ -51,54 +77,6 @@ class Heap {
51
77
  pop() {
52
78
  return this.poll();
53
79
  }
54
- /**
55
- * Float operation to maintain heap properties after adding an element.
56
- * @param index - The index of the newly added element.
57
- */
58
- bubbleUp(index) {
59
- const element = this.nodes[index];
60
- while (index > 0) {
61
- const parentIndex = Math.floor((index - 1) / 2);
62
- const parent = this.nodes[parentIndex];
63
- if (this.comparator(element, parent) < 0) {
64
- this.nodes[index] = parent;
65
- this.nodes[parentIndex] = element;
66
- index = parentIndex;
67
- }
68
- else {
69
- break;
70
- }
71
- }
72
- }
73
- /**
74
- * Sinking operation to maintain heap properties after removing the top element.
75
- * @param index - The index from which to start sinking.
76
- */
77
- sinkDown(index) {
78
- const leftChildIndex = 2 * index + 1;
79
- const rightChildIndex = 2 * index + 2;
80
- const length = this.nodes.length;
81
- let targetIndex = index;
82
- if (leftChildIndex < length && this.comparator(this.nodes[leftChildIndex], this.nodes[targetIndex]) < 0) {
83
- targetIndex = leftChildIndex;
84
- }
85
- if (rightChildIndex < length && this.comparator(this.nodes[rightChildIndex], this.nodes[targetIndex]) < 0) {
86
- targetIndex = rightChildIndex;
87
- }
88
- if (targetIndex !== index) {
89
- const temp = this.nodes[index];
90
- this.nodes[index] = this.nodes[targetIndex];
91
- this.nodes[targetIndex] = temp;
92
- this.sinkDown(targetIndex);
93
- }
94
- }
95
- /**
96
- * Fix the entire heap to maintain heap properties.
97
- */
98
- fix() {
99
- for (let i = Math.floor(this.size / 2); i >= 0; i--)
100
- this.sinkDown(i);
101
- }
102
80
  /**
103
81
  * Peek at the top element of the heap without removing it.
104
82
  * @returns The top element or undefined if the heap is empty.
@@ -109,20 +87,6 @@ class Heap {
109
87
  }
110
88
  return this.nodes[0];
111
89
  }
112
- /**
113
- * Get the size (number of elements) of the heap.
114
- */
115
- get size() {
116
- return this.nodes.length;
117
- }
118
- /**
119
- * Get the last element in the heap, which is not necessarily a leaf node.
120
- * @returns The last element or undefined if the heap is empty.
121
- */
122
- get leaf() {
123
- var _a;
124
- return (_a = this.nodes[this.size - 1]) !== null && _a !== void 0 ? _a : undefined;
125
- }
126
90
  /**
127
91
  * Check if the heap is empty.
128
92
  * @returns True if the heap is empty, otherwise false.
@@ -216,16 +180,52 @@ class Heap {
216
180
  return visitedNode;
217
181
  }
218
182
  /**
219
- * Static method that creates a binary heap from an array of nodes and a comparison function.
220
- * @param nodes
221
- * @param comparator - Comparison function.
222
- * @returns A new Heap instance.
183
+ * Float operation to maintain heap properties after adding an element.
184
+ * @param index - The index of the newly added element.
223
185
  */
224
- static heapify(nodes, comparator) {
225
- const binaryHeap = new Heap(comparator);
226
- binaryHeap.nodes = [...nodes];
227
- binaryHeap.fix(); // Fix heap properties
228
- return binaryHeap;
186
+ bubbleUp(index) {
187
+ const element = this.nodes[index];
188
+ while (index > 0) {
189
+ const parentIndex = Math.floor((index - 1) / 2);
190
+ const parent = this.nodes[parentIndex];
191
+ if (this.comparator(element, parent) < 0) {
192
+ this.nodes[index] = parent;
193
+ this.nodes[parentIndex] = element;
194
+ index = parentIndex;
195
+ }
196
+ else {
197
+ break;
198
+ }
199
+ }
200
+ }
201
+ /**
202
+ * Sinking operation to maintain heap properties after removing the top element.
203
+ * @param index - The index from which to start sinking.
204
+ */
205
+ sinkDown(index) {
206
+ const leftChildIndex = 2 * index + 1;
207
+ const rightChildIndex = 2 * index + 2;
208
+ const length = this.nodes.length;
209
+ let targetIndex = index;
210
+ if (leftChildIndex < length && this.comparator(this.nodes[leftChildIndex], this.nodes[targetIndex]) < 0) {
211
+ targetIndex = leftChildIndex;
212
+ }
213
+ if (rightChildIndex < length && this.comparator(this.nodes[rightChildIndex], this.nodes[targetIndex]) < 0) {
214
+ targetIndex = rightChildIndex;
215
+ }
216
+ if (targetIndex !== index) {
217
+ const temp = this.nodes[index];
218
+ this.nodes[index] = this.nodes[targetIndex];
219
+ this.nodes[targetIndex] = temp;
220
+ this.sinkDown(targetIndex);
221
+ }
222
+ }
223
+ /**
224
+ * Fix the entire heap to maintain heap properties.
225
+ */
226
+ fix() {
227
+ for (let i = Math.floor(this.size / 2); i >= 0; i--)
228
+ this.sinkDown(i);
229
229
  }
230
230
  }
231
231
  exports.Heap = Heap;
@@ -246,19 +246,6 @@ class FibonacciHeap {
246
246
  throw new Error('FibonacciHeap constructor: given comparator should be a function.');
247
247
  }
248
248
  }
249
- /**
250
- * Default comparator function used by the heap.
251
- * @param {E} a
252
- * @param {E} b
253
- * @protected
254
- */
255
- defaultComparator(a, b) {
256
- if (a < b)
257
- return -1;
258
- if (a > b)
259
- return 1;
260
- return 0;
261
- }
262
249
  /**
263
250
  * Get the size (number of elements) of the heap.
264
251
  * @returns {number} The size of the heap. Returns 0 if the heap is empty. Returns -1 if the heap is invalid.
@@ -268,29 +255,6 @@ class FibonacciHeap {
268
255
  this.min = undefined;
269
256
  this.size = 0;
270
257
  }
271
- /**
272
- * Create a new node.
273
- * @param element
274
- * @protected
275
- */
276
- createNode(element) {
277
- return new FibonacciHeapNode(element);
278
- }
279
- /**
280
- * Merge the given node with the root list.
281
- * @param node - The node to be merged.
282
- */
283
- mergeWithRoot(node) {
284
- if (!this.root) {
285
- this.root = node;
286
- }
287
- else {
288
- node.right = this.root.right;
289
- node.left = this.root;
290
- this.root.right.left = node;
291
- this.root.right = node;
292
- }
293
- }
294
258
  /**
295
259
  * O(1) time operation.
296
260
  * Insert an element into the heap and maintain the heap properties.
@@ -351,20 +315,6 @@ class FibonacciHeap {
351
315
  }
352
316
  return nodes;
353
317
  }
354
- /**
355
- * O(log n) time operation.
356
- * Remove and return the top element (smallest or largest element) from the heap.
357
- * @param node - The node to be removed.
358
- * @protected
359
- */
360
- removeFromRoot(node) {
361
- if (this.root === node)
362
- this.root = node.right;
363
- if (node.left)
364
- node.left.right = node.right;
365
- if (node.right)
366
- node.right.left = node.left;
367
- }
368
318
  /**
369
319
  * O(log n) time operation.
370
320
  * Remove and return the top element (smallest or largest element) from the heap.
@@ -382,52 +332,6 @@ class FibonacciHeap {
382
332
  parent.child.right = node;
383
333
  }
384
334
  }
385
- /**
386
- * O(log n) time operation.
387
- * Remove and return the top element (smallest or largest element) from the heap.
388
- * @param y
389
- * @param x
390
- * @protected
391
- */
392
- link(y, x) {
393
- this.removeFromRoot(y);
394
- y.left = y;
395
- y.right = y;
396
- this.mergeWithChild(x, y);
397
- x.degree++;
398
- y.parent = x;
399
- }
400
- /**
401
- * O(log n) time operation.
402
- * Remove and return the top element (smallest or largest element) from the heap.
403
- * @protected
404
- */
405
- consolidate() {
406
- const A = new Array(this.size);
407
- const nodes = this.consumeLinkedList(this.root);
408
- let x, y, d, t;
409
- for (const node of nodes) {
410
- x = node;
411
- d = x.degree;
412
- while (A[d]) {
413
- y = A[d];
414
- if (this.comparator(x.element, y.element) > 0) {
415
- t = x;
416
- x = y;
417
- y = t;
418
- }
419
- this.link(y, x);
420
- A[d] = undefined;
421
- d++;
422
- }
423
- A[d] = x;
424
- }
425
- for (let i = 0; i < this.size; i++) {
426
- if (A[i] && this.comparator(A[i].element, this.min.element) <= 0) {
427
- this.min = A[i];
428
- }
429
- }
430
- }
431
335
  /**
432
336
  * O(log n) time operation.
433
337
  * Remove and return the top element (smallest or largest element) from the heap.
@@ -493,6 +397,102 @@ class FibonacciHeap {
493
397
  // Clear the heap that was merged
494
398
  heapToMerge.clear();
495
399
  }
400
+ /**
401
+ * Default comparator function used by the heap.
402
+ * @param {E} a
403
+ * @param {E} b
404
+ * @protected
405
+ */
406
+ defaultComparator(a, b) {
407
+ if (a < b)
408
+ return -1;
409
+ if (a > b)
410
+ return 1;
411
+ return 0;
412
+ }
413
+ /**
414
+ * Create a new node.
415
+ * @param element
416
+ * @protected
417
+ */
418
+ createNode(element) {
419
+ return new FibonacciHeapNode(element);
420
+ }
421
+ /**
422
+ * Merge the given node with the root list.
423
+ * @param node - The node to be merged.
424
+ */
425
+ mergeWithRoot(node) {
426
+ if (!this.root) {
427
+ this.root = node;
428
+ }
429
+ else {
430
+ node.right = this.root.right;
431
+ node.left = this.root;
432
+ this.root.right.left = node;
433
+ this.root.right = node;
434
+ }
435
+ }
436
+ /**
437
+ * O(log n) time operation.
438
+ * Remove and return the top element (smallest or largest element) from the heap.
439
+ * @param node - The node to be removed.
440
+ * @protected
441
+ */
442
+ removeFromRoot(node) {
443
+ if (this.root === node)
444
+ this.root = node.right;
445
+ if (node.left)
446
+ node.left.right = node.right;
447
+ if (node.right)
448
+ node.right.left = node.left;
449
+ }
450
+ /**
451
+ * O(log n) time operation.
452
+ * Remove and return the top element (smallest or largest element) from the heap.
453
+ * @param y
454
+ * @param x
455
+ * @protected
456
+ */
457
+ link(y, x) {
458
+ this.removeFromRoot(y);
459
+ y.left = y;
460
+ y.right = y;
461
+ this.mergeWithChild(x, y);
462
+ x.degree++;
463
+ y.parent = x;
464
+ }
465
+ /**
466
+ * O(log n) time operation.
467
+ * Remove and return the top element (smallest or largest element) from the heap.
468
+ * @protected
469
+ */
470
+ consolidate() {
471
+ const A = new Array(this.size);
472
+ const nodes = this.consumeLinkedList(this.root);
473
+ let x, y, d, t;
474
+ for (const node of nodes) {
475
+ x = node;
476
+ d = x.degree;
477
+ while (A[d]) {
478
+ y = A[d];
479
+ if (this.comparator(x.element, y.element) > 0) {
480
+ t = x;
481
+ x = y;
482
+ y = t;
483
+ }
484
+ this.link(y, x);
485
+ A[d] = undefined;
486
+ d++;
487
+ }
488
+ A[d] = x;
489
+ }
490
+ for (let i = 0; i < this.size; i++) {
491
+ if (A[i] && this.comparator(A[i].element, this.min.element) <= 0) {
492
+ this.min = A[i];
493
+ }
494
+ }
495
+ }
496
496
  }
497
497
  exports.FibonacciHeap = FibonacciHeap;
498
498
  //# sourceMappingURL=heap.js.map