max-heap-typed 2.2.0 → 2.2.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.
@@ -125,7 +125,9 @@ export declare class AVLTreeNode<K = any, V = any> {
125
125
  * 4. Order Preservation: Maintains the binary search tree property where left child values are less than the parent, and right child values are greater.
126
126
  * 5. Efficient Lookups: Offers O(log n) search time, where 'n' is the number of nodes, due to its balanced nature.
127
127
  * 6. Complex Insertions and Deletions: Due to rebalancing, these operations are more complex than in a regular BST.
128
- * 7. Path Length: The path length from the root to any leaf is longer compared to an unbalanced BST, but shorter than a linear chain of nodes.@example
128
+ * 7. Path Length: The path length from the root to any leaf is longer compared to an unbalanced BST, but shorter than a linear chain of nodes.
129
+ *
130
+ * @example
129
131
  * // Find elements in a range
130
132
  * // In interval queries, AVL trees, with their strictly balanced structure and lower height, offer better query efficiency, making them ideal for frequent and high-performance interval queries. In contrast, Red-Black trees, with lower update costs, are more suitable for scenarios involving frequent insertions and deletions where the requirements for interval queries are less demanding.
131
133
  * type Datum = { timestamp: Date; temperature: number };
@@ -123,6 +123,7 @@ export declare class BinaryTreeNode<K = any, V = any> {
123
123
  * 3. Depth and Height: Depth is the number of edges from the root to a node; height is the maximum depth in the tree.
124
124
  * 4. Subtrees: Each child of a node forms the root of a subtree.
125
125
  * 5. Leaf Nodes: Nodes without children are leaves.
126
+ *
126
127
  * @example
127
128
  * // determine loan approval using a decision tree
128
129
  * // Decision tree structure
@@ -124,6 +124,7 @@ export declare class BSTNode<K = any, V = any> {
124
124
  * 5. Logarithmic Operations: Ideal operations like insertion, deletion, and searching are O(log n) time-efficient.
125
125
  * 6. Balance Variability: Can become unbalanced; special types maintain balance.
126
126
  * 7. No Auto-Balancing: Standard BSTs don't automatically balance themselves.
127
+ *
127
128
  * @example
128
129
  * // Merge 3 sorted datasets
129
130
  * const dataset1 = new BST<number, string>([
@@ -110,6 +110,7 @@ export declare class RedBlackTreeNode<K = any, V = any> {
110
110
  * @template R
111
111
  * 1. Efficient self-balancing, but not completely balanced. Compared with AVLTree, the addition and deletion efficiency is high, but the query efficiency is slightly lower.
112
112
  * 2. It is BST itself. Compared with Heap which is not completely ordered, RedBlackTree is completely ordered.
113
+ *
113
114
  * @example
114
115
  * // using Red-Black Tree as a price-based index for stock data
115
116
  * // Define the structure of individual stock records
@@ -113,6 +113,7 @@ export declare class TreeMultiMapNode<K = any, V = any> {
113
113
  * @template K
114
114
  * @template V
115
115
  * @template R
116
+ *
116
117
  * @example
117
118
  * // players ranked by score with their equipment
118
119
  * type Equipment = {
@@ -1,6 +1,6 @@
1
1
  import { IterableElementBase, IterableEntryBase } from '../../../data-structures';
2
2
  import { LinearBase } from '../../../data-structures/base/linear-base';
3
- export type EntryCallback<K, V, R> = (key: K, value: V, index: number, original: IterableEntryBase<K, V>) => R;
3
+ export type EntryCallback<K, V, R> = (value: V, key: K, index: number, original: IterableEntryBase<K, V>) => R;
4
4
  export type ElementCallback<E, R, RT> = (element: E, index: number, original: IterableElementBase<E, R>) => RT;
5
5
  export type ReduceEntryCallback<K, V, R> = (accumulator: R, value: V, key: K, index: number, original: IterableEntryBase<K, V>) => R;
6
6
  export type ReduceElementCallback<E, R, U = E> = (accumulator: U, value: E, index: number, self: IterableElementBase<E, R>) => U;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "max-heap-typed",
3
- "version": "2.2.0",
3
+ "version": "2.2.1",
4
4
  "description": "Max Heap",
5
5
  "browser": "dist/umd/max-heap-typed.min.js",
6
6
  "umd:main": "dist/umd/max-heap-typed.min.js",
@@ -170,6 +170,6 @@
170
170
  "typescript": "^4.9.5"
171
171
  },
172
172
  "dependencies": {
173
- "data-structure-typed": "^2.2.0"
173
+ "data-structure-typed": "^2.2.1"
174
174
  }
175
175
  }
@@ -66,7 +66,7 @@ export abstract class IterableEntryBase<K = any, V = any> {
66
66
  every(predicate: EntryCallback<K, V, boolean>, thisArg?: any): boolean {
67
67
  let index = 0;
68
68
  for (const item of this) {
69
- if (!predicate.call(thisArg, item[0], item[1], index++, this)) {
69
+ if (!predicate.call(thisArg, item[1], item[0], index++, this)) {
70
70
  return false;
71
71
  }
72
72
  }
@@ -83,7 +83,7 @@ export abstract class IterableEntryBase<K = any, V = any> {
83
83
  some(predicate: EntryCallback<K, V, boolean>, thisArg?: any): boolean {
84
84
  let index = 0;
85
85
  for (const item of this) {
86
- if (predicate.call(thisArg, item[0], item[1], index++, this)) {
86
+ if (predicate.call(thisArg, item[1], item[0], index++, this)) {
87
87
  return true;
88
88
  }
89
89
  }
@@ -100,7 +100,7 @@ export abstract class IterableEntryBase<K = any, V = any> {
100
100
  let index = 0;
101
101
  for (const item of this) {
102
102
  const [key, value] = item;
103
- callbackfn.call(thisArg, key, value, index++, this);
103
+ callbackfn.call(thisArg, value, key, index++, this);
104
104
  }
105
105
  }
106
106
 
@@ -115,7 +115,7 @@ export abstract class IterableEntryBase<K = any, V = any> {
115
115
  let index = 0;
116
116
  for (const item of this) {
117
117
  const [key, value] = item;
118
- if (callbackfn.call(thisArg, key, value, index++, this)) return item;
118
+ if (callbackfn.call(thisArg, value, key, index++, this)) return item;
119
119
  }
120
120
  return;
121
121
  }
@@ -411,7 +411,7 @@ export class AVLTreeCounter<K = any, V = any, R = any> extends AVLTree<K, V, R>
411
411
 
412
412
  let index = 0;
413
413
  for (const [key, value] of this) {
414
- out.add(callback.call(thisArg, key, value, index++, this));
414
+ out.add(callback.call(thisArg, value, key, index++, this));
415
415
  }
416
416
  return out;
417
417
  }
@@ -393,7 +393,7 @@ export class AVLTreeMultiMap<K = any, V = any, R = any> extends AVLTree<K, V[],
393
393
  ): AVLTree<MK, MV, MR> {
394
394
  const out = this._createLike<MK, MV, MR>([], options);
395
395
  let i = 0;
396
- for (const [k, v] of this) out.add(callback.call(thisArg, k, v, i++, this));
396
+ for (const [k, v] of this) out.add(callback.call(thisArg, v, k, i++, this));
397
397
  return out;
398
398
  }
399
399
 
@@ -195,7 +195,9 @@ export class AVLTreeNode<K = any, V = any> {
195
195
  * 4. Order Preservation: Maintains the binary search tree property where left child values are less than the parent, and right child values are greater.
196
196
  * 5. Efficient Lookups: Offers O(log n) search time, where 'n' is the number of nodes, due to its balanced nature.
197
197
  * 6. Complex Insertions and Deletions: Due to rebalancing, these operations are more complex than in a regular BST.
198
- * 7. Path Length: The path length from the root to any leaf is longer compared to an unbalanced BST, but shorter than a linear chain of nodes.@example
198
+ * 7. Path Length: The path length from the root to any leaf is longer compared to an unbalanced BST, but shorter than a linear chain of nodes.
199
+ *
200
+ * @example
199
201
  * // Find elements in a range
200
202
  * // In interval queries, AVL trees, with their strictly balanced structure and lower height, offer better query efficiency, making them ideal for frequent and high-performance interval queries. In contrast, Red-Black trees, with lower update costs, are more suitable for scenarios involving frequent insertions and deletions where the requirements for interval queries are less demanding.
201
203
  * type Datum = { timestamp: Date; temperature: number };
@@ -403,7 +405,7 @@ export class AVLTree<K = any, V = any, R = any> extends BST<K, V, R> implements
403
405
  // Iterates in-order
404
406
  for (const [key, value] of this) {
405
407
  // `add` on the new tree will be O(log N) and will self-balance.
406
- out.add(callback.call(thisArg, key, value, index++, this));
408
+ out.add(callback.call(thisArg, value, key, index++, this));
407
409
  }
408
410
  return out;
409
411
  }
@@ -203,6 +203,7 @@ export class BinaryTreeNode<K = any, V = any> {
203
203
  * 3. Depth and Height: Depth is the number of edges from the root to a node; height is the maximum depth in the tree.
204
204
  * 4. Subtrees: Each child of a node forms the root of a subtree.
205
205
  * 5. Leaf Nodes: Nodes without children are leaves.
206
+ *
206
207
  * @example
207
208
  * // determine loan approval using a decision tree
208
209
  * // Decision tree structure
@@ -1673,7 +1674,7 @@ export class BinaryTree<K = any, V = any, R = any>
1673
1674
  filter(predicate: EntryCallback<K, V | undefined, boolean>, thisArg?: unknown): this {
1674
1675
  const out = this._createInstance<K, V, R>();
1675
1676
  let i = 0;
1676
- for (const [k, v] of this) if (predicate.call(thisArg, k, v, i++, this)) out.add([k, v]);
1677
+ for (const [k, v] of this) if (predicate.call(thisArg, v, k, i++, this)) out.add([k, v]);
1677
1678
  return out;
1678
1679
  }
1679
1680
 
@@ -1696,7 +1697,7 @@ export class BinaryTree<K = any, V = any, R = any>
1696
1697
  ): BinaryTree<MK, MV, MR> {
1697
1698
  const out = this._createLike<MK, MV, MR>([], options);
1698
1699
  let i = 0;
1699
- for (const [k, v] of this) out.add(cb.call(thisArg, k, v, i++, this));
1700
+ for (const [k, v] of this) out.add(cb.call(thisArg, v, k, i++, this));
1700
1701
  return out;
1701
1702
  }
1702
1703
 
@@ -199,6 +199,7 @@ export class BSTNode<K = any, V = any> {
199
199
  * 5. Logarithmic Operations: Ideal operations like insertion, deletion, and searching are O(log n) time-efficient.
200
200
  * 6. Balance Variability: Can become unbalanced; special types maintain balance.
201
201
  * 7. No Auto-Balancing: Standard BSTs don't automatically balance themselves.
202
+ *
202
203
  * @example
203
204
  * // Merge 3 sorted datasets
204
205
  * const dataset1 = new BST<number, string>([
@@ -908,7 +909,7 @@ export class BST<K = any, V = any, R = any> extends BinaryTree<K, V, R> implemen
908
909
  let index = 0;
909
910
  // Iterates in-order
910
911
  for (const [key, value] of this) {
911
- out.add(callback.call(thisArg, key, value, index++, this));
912
+ out.add(callback.call(thisArg, value, key, index++, this));
912
913
  }
913
914
  return out;
914
915
  }
@@ -186,6 +186,7 @@ export class RedBlackTreeNode<K = any, V = any> {
186
186
  * @template R
187
187
  * 1. Efficient self-balancing, but not completely balanced. Compared with AVLTree, the addition and deletion efficiency is high, but the query efficiency is slightly lower.
188
188
  * 2. It is BST itself. Compared with Heap which is not completely ordered, RedBlackTree is completely ordered.
189
+ *
189
190
  * @example
190
191
  * // using Red-Black Tree as a price-based index for stock data
191
192
  * // Define the structure of individual stock records
@@ -420,7 +421,7 @@ export class RedBlackTree<K = any, V = any, R = any> extends BST<K, V, R> implem
420
421
 
421
422
  let index = 0;
422
423
  for (const [key, value] of this) {
423
- out.add(callback.call(thisArg, key, value, index++, this));
424
+ out.add(callback.call(thisArg, value, key, index++, this));
424
425
  }
425
426
  return out;
426
427
  }
@@ -439,7 +439,7 @@ export class TreeCounter<K = any, V = any, R = any> extends RedBlackTree<K, V, R
439
439
 
440
440
  let index = 0;
441
441
  for (const [key, value] of this) {
442
- out.add(callback.call(thisArg, key, value, index++, this));
442
+ out.add(callback.call(thisArg, value, key, index++, this));
443
443
  }
444
444
  return out;
445
445
  }
@@ -183,6 +183,7 @@ export class TreeMultiMapNode<K = any, V = any> {
183
183
  * @template K
184
184
  * @template V
185
185
  * @template R
186
+ *
186
187
  * @example
187
188
  * // players ranked by score with their equipment
188
189
  * type Equipment = {
@@ -503,7 +504,7 @@ export class TreeMultiMap<K = any, V = any, R = any> extends RedBlackTree<K, V[]
503
504
  ): RedBlackTree<MK, MV, MR> {
504
505
  const out = this._createLike<MK, MV, MR>([], options);
505
506
  let i = 0;
506
- for (const [k, v] of this) out.add(callback.call(thisArg, k, v, i++, this));
507
+ for (const [k, v] of this) out.add(callback.call(thisArg, v, k, i++, this));
507
508
  return out;
508
509
  }
509
510
 
@@ -897,7 +897,7 @@ export abstract class AbstractGraph<
897
897
  const filtered: [VertexKey, V | undefined][] = [];
898
898
  let index = 0;
899
899
  for (const [key, value] of this) {
900
- if (predicate.call(thisArg, key, value, index, this)) {
900
+ if (predicate.call(thisArg, value, key, index, this)) {
901
901
  filtered.push([key, value]);
902
902
  }
903
903
  index++;
@@ -916,7 +916,7 @@ export abstract class AbstractGraph<
916
916
  const filtered: [VertexKey, V | undefined][] = [];
917
917
  let index = 0;
918
918
  for (const [key, value] of this) {
919
- if (predicate.call(thisArg, key, value, index, this)) {
919
+ if (predicate.call(thisArg, value, key, index, this)) {
920
920
  filtered.push([key, value]);
921
921
  }
922
922
  index++;
@@ -928,7 +928,7 @@ export abstract class AbstractGraph<
928
928
  const mapped: T[] = [];
929
929
  let index = 0;
930
930
  for (const [key, value] of this) {
931
- mapped.push(callback.call(thisArg, key, value, index, this));
931
+ mapped.push(callback.call(thisArg, value, key, index, this));
932
932
  index++;
933
933
  }
934
934
  return mapped;
@@ -290,7 +290,7 @@ export class HashMap<K = any, V = any, R = [K, V]> extends IterableEntryBase<K,
290
290
  map<VM>(callbackfn: EntryCallback<K, V, VM>, thisArg?: any): any {
291
291
  const out = this._createLike<K, VM, [K, VM]>();
292
292
  let index = 0;
293
- for (const [key, value] of this) out.set(key, callbackfn.call(thisArg, key, value, index++, this));
293
+ for (const [key, value] of this) out.set(key, callbackfn.call(thisArg, value, key, index++, this));
294
294
  return out;
295
295
  }
296
296
 
@@ -305,7 +305,7 @@ export class HashMap<K = any, V = any, R = [K, V]> extends IterableEntryBase<K,
305
305
  filter(predicate: EntryCallback<K, V, boolean>, thisArg?: any): any {
306
306
  const out = this._createLike<K, V, [K, V]>();
307
307
  let index = 0;
308
- for (const [key, value] of this) if (predicate.call(thisArg, key, value, index++, this)) out.set(key, value);
308
+ for (const [key, value] of this) if (predicate.call(thisArg, value, key, index++, this)) out.set(key, value);
309
309
  return out;
310
310
  }
311
311
 
@@ -677,7 +677,7 @@ export class LinkedHashMap<K = any, V = any, R = [K, V]> extends IterableEntryBa
677
677
  const out = this._createLike<K, V, [K, V]>();
678
678
  let index = 0;
679
679
  for (const [key, value] of this) {
680
- if (predicate.call(thisArg, key, value, index, this)) out.set(key, value);
680
+ if (predicate.call(thisArg, value, key, index, this)) out.set(key, value);
681
681
  index++;
682
682
  }
683
683
  return out;
@@ -696,7 +696,7 @@ export class LinkedHashMap<K = any, V = any, R = [K, V]> extends IterableEntryBa
696
696
  const out = this._createLike<MK, MV, [MK, MV]>();
697
697
  let index = 0;
698
698
  for (const [key, value] of this) {
699
- const [newKey, newValue] = callback.call(thisArg, key, value, index, this);
699
+ const [newKey, newValue] = callback.call(thisArg, value, key, index, this);
700
700
  out.set(newKey, newValue);
701
701
  index++;
702
702
  }
@@ -1,7 +1,7 @@
1
1
  import { IterableElementBase, IterableEntryBase } from '../../../data-structures';
2
2
  import { LinearBase } from '../../../data-structures/base/linear-base';
3
3
 
4
- export type EntryCallback<K, V, R> = (key: K, value: V, index: number, original: IterableEntryBase<K, V>) => R;
4
+ export type EntryCallback<K, V, R> = (value: V, key: K, index: number, original: IterableEntryBase<K, V>) => R;
5
5
  export type ElementCallback<E, R, RT> = (element: E, index: number, original: IterableElementBase<E, R>) => RT;
6
6
  export type ReduceEntryCallback<K, V, R> = (
7
7
  accumulator: R,