undirected-graph-typed 1.54.2 → 2.0.0

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 (84) hide show
  1. package/dist/data-structures/base/iterable-element-base.d.ts +14 -40
  2. package/dist/data-structures/base/iterable-element-base.js +14 -11
  3. package/dist/data-structures/base/linear-base.d.ts +277 -0
  4. package/dist/data-structures/base/linear-base.js +552 -0
  5. package/dist/data-structures/binary-tree/avl-tree-counter.d.ts +21 -20
  6. package/dist/data-structures/binary-tree/avl-tree-counter.js +8 -7
  7. package/dist/data-structures/binary-tree/avl-tree-multi-map.d.ts +23 -19
  8. package/dist/data-structures/binary-tree/avl-tree-multi-map.js +51 -38
  9. package/dist/data-structures/binary-tree/avl-tree.d.ts +89 -21
  10. package/dist/data-structures/binary-tree/avl-tree.js +76 -8
  11. package/dist/data-structures/binary-tree/binary-tree.d.ts +173 -225
  12. package/dist/data-structures/binary-tree/binary-tree.js +244 -149
  13. package/dist/data-structures/binary-tree/bst.d.ts +62 -56
  14. package/dist/data-structures/binary-tree/bst.js +89 -133
  15. package/dist/data-structures/binary-tree/red-black-tree.d.ts +19 -25
  16. package/dist/data-structures/binary-tree/red-black-tree.js +7 -13
  17. package/dist/data-structures/binary-tree/tree-counter.d.ts +19 -19
  18. package/dist/data-structures/binary-tree/tree-counter.js +12 -12
  19. package/dist/data-structures/binary-tree/tree-multi-map.d.ts +186 -25
  20. package/dist/data-structures/binary-tree/tree-multi-map.js +211 -41
  21. package/dist/data-structures/graph/abstract-graph.js +2 -2
  22. package/dist/data-structures/heap/heap.d.ts +3 -11
  23. package/dist/data-structures/heap/heap.js +0 -10
  24. package/dist/data-structures/heap/max-heap.d.ts +2 -2
  25. package/dist/data-structures/heap/min-heap.d.ts +2 -2
  26. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +65 -94
  27. package/dist/data-structures/linked-list/doubly-linked-list.js +131 -146
  28. package/dist/data-structures/linked-list/singly-linked-list.d.ts +79 -75
  29. package/dist/data-structures/linked-list/singly-linked-list.js +217 -169
  30. package/dist/data-structures/priority-queue/max-priority-queue.d.ts +2 -2
  31. package/dist/data-structures/priority-queue/min-priority-queue.d.ts +2 -2
  32. package/dist/data-structures/priority-queue/priority-queue.d.ts +2 -2
  33. package/dist/data-structures/queue/deque.d.ts +130 -91
  34. package/dist/data-structures/queue/deque.js +269 -169
  35. package/dist/data-structures/queue/queue.d.ts +84 -40
  36. package/dist/data-structures/queue/queue.js +134 -50
  37. package/dist/data-structures/stack/stack.d.ts +3 -11
  38. package/dist/data-structures/stack/stack.js +0 -10
  39. package/dist/data-structures/trie/trie.d.ts +4 -3
  40. package/dist/data-structures/trie/trie.js +3 -0
  41. package/dist/types/data-structures/base/base.d.ts +9 -4
  42. package/dist/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +1 -1
  43. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +1 -0
  44. package/dist/types/data-structures/binary-tree/bst.d.ts +1 -1
  45. package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +1 -1
  46. package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +2 -2
  47. package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +2 -2
  48. package/dist/types/data-structures/queue/deque.d.ts +2 -3
  49. package/dist/types/data-structures/queue/queue.d.ts +2 -2
  50. package/dist/utils/utils.d.ts +2 -2
  51. package/package.json +2 -2
  52. package/src/data-structures/base/iterable-element-base.ts +29 -20
  53. package/src/data-structures/base/linear-base.ts +649 -0
  54. package/src/data-structures/binary-tree/avl-tree-counter.ts +30 -23
  55. package/src/data-structures/binary-tree/avl-tree-multi-map.ts +74 -49
  56. package/src/data-structures/binary-tree/avl-tree.ts +99 -29
  57. package/src/data-structures/binary-tree/binary-tree.ts +474 -257
  58. package/src/data-structures/binary-tree/bst.ts +150 -152
  59. package/src/data-structures/binary-tree/red-black-tree.ts +27 -35
  60. package/src/data-structures/binary-tree/tree-counter.ts +33 -27
  61. package/src/data-structures/binary-tree/tree-multi-map.ts +235 -53
  62. package/src/data-structures/graph/abstract-graph.ts +2 -2
  63. package/src/data-structures/heap/heap.ts +3 -14
  64. package/src/data-structures/heap/max-heap.ts +2 -2
  65. package/src/data-structures/heap/min-heap.ts +2 -2
  66. package/src/data-structures/linked-list/doubly-linked-list.ts +144 -160
  67. package/src/data-structures/linked-list/singly-linked-list.ts +241 -185
  68. package/src/data-structures/priority-queue/max-priority-queue.ts +2 -5
  69. package/src/data-structures/priority-queue/min-priority-queue.ts +2 -5
  70. package/src/data-structures/priority-queue/priority-queue.ts +2 -2
  71. package/src/data-structures/queue/deque.ts +286 -183
  72. package/src/data-structures/queue/queue.ts +149 -63
  73. package/src/data-structures/stack/stack.ts +3 -18
  74. package/src/data-structures/trie/trie.ts +7 -3
  75. package/src/types/data-structures/base/base.ts +17 -8
  76. package/src/types/data-structures/binary-tree/avl-tree-multi-map.ts +1 -1
  77. package/src/types/data-structures/binary-tree/binary-tree.ts +1 -0
  78. package/src/types/data-structures/binary-tree/bst.ts +1 -1
  79. package/src/types/data-structures/binary-tree/tree-multi-map.ts +1 -1
  80. package/src/types/data-structures/linked-list/doubly-linked-list.ts +2 -2
  81. package/src/types/data-structures/linked-list/singly-linked-list.ts +2 -2
  82. package/src/types/data-structures/queue/deque.ts +2 -3
  83. package/src/types/data-structures/queue/queue.ts +2 -2
  84. package/src/utils/utils.ts +2 -2
@@ -5,10 +5,11 @@
5
5
  * @copyright Copyright (c) 2022 Pablo Zeng <zrwusa@gmail.com>
6
6
  * @license MIT License
7
7
  */
8
- import type { BinaryTreeDeleteResult, BSTNOptKeyOrNode, BTNRep, EntryCallback, IterationType, OptNodeOrNull, RBTNColor, TreeCounterOptions } from '../../types';
8
+ import type { BinaryTreeDeleteResult, BSTNOptKeyOrNode, EntryCallback, IterationType, RBTNColor, TreeCounterOptions } from '../../types';
9
9
  import { IBinaryTree } from '../../interfaces';
10
10
  import { RedBlackTree, RedBlackTreeNode } from './red-black-tree';
11
11
  export declare class TreeCounterNode<K = any, V = any> extends RedBlackTreeNode<K, V> {
12
+ parent?: TreeCounterNode<K, V>;
12
13
  /**
13
14
  * The constructor function initializes a Red-Black Tree node with a key, value, count, and color.
14
15
  * @param {K} key - The key parameter represents the key of the node in the Red-Black Tree. It is
@@ -22,13 +23,12 @@ export declare class TreeCounterNode<K = any, V = any> extends RedBlackTreeNode<
22
23
  * in a Red-Black Tree. It is optional and has a default value of `'BLACK'`.
23
24
  */
24
25
  constructor(key: K, value?: V, count?: number, color?: RBTNColor);
25
- parent?: TreeCounterNode<K, V>;
26
- _left?: OptNodeOrNull<TreeCounterNode<K, V>>;
27
- get left(): OptNodeOrNull<TreeCounterNode<K, V>>;
28
- set left(v: OptNodeOrNull<TreeCounterNode<K, V>>);
29
- _right?: OptNodeOrNull<TreeCounterNode<K, V>>;
30
- get right(): OptNodeOrNull<TreeCounterNode<K, V>>;
31
- set right(v: OptNodeOrNull<TreeCounterNode<K, V>>);
26
+ _left?: TreeCounterNode<K, V> | null | undefined;
27
+ get left(): TreeCounterNode<K, V> | null | undefined;
28
+ set left(v: TreeCounterNode<K, V> | null | undefined);
29
+ _right?: TreeCounterNode<K, V> | null | undefined;
30
+ get right(): TreeCounterNode<K, V> | null | undefined;
31
+ set right(v: TreeCounterNode<K, V> | null | undefined);
32
32
  }
33
33
  /**
34
34
  *
@@ -43,7 +43,7 @@ export declare class TreeCounter<K = any, V = any, R = object, MK = any, MV = an
43
43
  * behavior of the `TreeCounter` constructor. It can include properties such as `compareKeys` and
44
44
  * `compareValues`, which are functions used to compare keys and values respectively.
45
45
  */
46
- constructor(keysNodesEntriesOrRaws?: Iterable<BTNRep<K, V, TreeCounterNode<K, V>> | R>, options?: TreeCounterOptions<K, V, R>);
46
+ constructor(keysNodesEntriesOrRaws?: Iterable<K | TreeCounterNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | R>, options?: TreeCounterOptions<K, V, R>);
47
47
  protected _count: number;
48
48
  /**
49
49
  * The function calculates the sum of the count property of all nodes in a tree structure.
@@ -84,19 +84,19 @@ export declare class TreeCounter<K = any, V = any, R = object, MK = any, MV = an
84
84
  createTree(options?: TreeCounterOptions<K, V, R>): TreeCounter<K, V, R, MK, MV, MR>;
85
85
  /**
86
86
  * The function checks if the input is an instance of the TreeCounterNode class.
87
- * @param {BTNRep<K, V, TreeCounterNode<K, V>>} keyNodeOrEntry - The parameter
88
- * `keyNodeOrEntry` can be of type `R` or `BTNRep<K, V, TreeCounterNode<K, V>>`.
87
+ * @param {K | TreeCounterNode<K, V> | [K | null | undefined, V | undefined] | null | undefined} keyNodeOrEntry - The parameter
88
+ * `keyNodeOrEntry` can be of type `R` or `K | TreeCounterNode<K, V> | [K | null | undefined, V | undefined] | null | undefined`.
89
89
  * @returns a boolean value indicating whether the input parameter `keyNodeOrEntry` is
90
90
  * an instance of the `TreeCounterNode` class.
91
91
  */
92
- isNode(keyNodeOrEntry: BTNRep<K, V, TreeCounterNode<K, V>>): keyNodeOrEntry is TreeCounterNode<K, V>;
92
+ isNode(keyNodeOrEntry: K | TreeCounterNode<K, V> | [K | null | undefined, V | undefined] | null | undefined): keyNodeOrEntry is TreeCounterNode<K, V>;
93
93
  /**
94
94
  * Time Complexity: O(log n)
95
95
  * Space Complexity: O(1)
96
96
  *
97
97
  * The function overrides the add method of a class and adds a new node to a data structure, updating
98
98
  * the count and returning a boolean indicating success.
99
- * @param {BTNRep<K, V, TreeCounterNode<K, V>>} keyNodeOrEntry - The
99
+ * @param {K | TreeCounterNode<K, V> | [K | null | undefined, V | undefined] | null | undefined} keyNodeOrEntry - The
100
100
  * `keyNodeOrEntry` parameter can accept one of the following types:
101
101
  * @param {V} [value] - The `value` parameter represents the value associated with the key in the
102
102
  * data structure. It is an optional parameter, so it can be omitted if not needed.
@@ -106,14 +106,14 @@ export declare class TreeCounter<K = any, V = any, R = object, MK = any, MV = an
106
106
  * @returns The method is returning a boolean value. It returns true if the addition of the new node
107
107
  * was successful, and false otherwise.
108
108
  */
109
- add(keyNodeOrEntry: BTNRep<K, V, TreeCounterNode<K, V>>, value?: V, count?: number): boolean;
109
+ add(keyNodeOrEntry: K | TreeCounterNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, value?: V, count?: number): boolean;
110
110
  /**
111
111
  * Time Complexity: O(log n)
112
112
  * Space Complexity: O(1)
113
113
  *
114
114
  * The function `delete` in TypeScript overrides the deletion operation in a binary tree data
115
115
  * structure, handling cases where nodes have children and maintaining balance in the tree.
116
- * @param {BTNRep<K, V, TreeCounterNode<K, V>>} keyNodeOrEntry - The `predicate`
116
+ * @param {K | TreeCounterNode<K, V> | [K | null | undefined, V | undefined] | null | undefined} keyNodeOrEntry - The `predicate`
117
117
  * parameter in the `delete` method is used to specify the condition or key based on which a node
118
118
  * should be deleted from the binary tree. It can be a key, a node, or an entry.
119
119
  * @param [ignoreCount=false] - The `ignoreCount` parameter in the `override delete` method is a
@@ -122,7 +122,7 @@ export declare class TreeCounter<K = any, V = any, R = object, MK = any, MV = an
122
122
  * `ignoreCount` is `false
123
123
  * @returns The `override delete` method returns an array of `BinaryTreeDeleteResult<TreeCounterNode<K, V>>` objects.
124
124
  */
125
- delete(keyNodeOrEntry: BTNRep<K, V, TreeCounterNode<K, V>>, ignoreCount?: boolean): BinaryTreeDeleteResult<TreeCounterNode<K, V>>[];
125
+ delete(keyNodeOrEntry: K | TreeCounterNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, ignoreCount?: boolean): BinaryTreeDeleteResult<TreeCounterNode<K, V>>[];
126
126
  /**
127
127
  * Time Complexity: O(1)
128
128
  * Space Complexity: O(1)
@@ -172,8 +172,8 @@ export declare class TreeCounter<K = any, V = any, R = object, MK = any, MV = an
172
172
  /**
173
173
  * The function `keyValueNodeEntryRawToNodeAndValue` takes in a key, value, and count and returns a
174
174
  * node based on the input.
175
- * @param {BTNRep<K, V, TreeCounterNode<K, V>>} keyNodeOrEntry - The parameter
176
- * `keyNodeOrEntry` can be of type `R` or `BTNRep<K, V, TreeCounterNode<K, V>>`.
175
+ * @param {K | TreeCounterNode<K, V> | [K | null | undefined, V | undefined] | null | undefined} keyNodeOrEntry - The parameter
176
+ * `keyNodeOrEntry` can be of type `R` or `K | TreeCounterNode<K, V> | [K | null | undefined, V | undefined] | null | undefined`.
177
177
  * @param {V} [value] - The `value` parameter is an optional value that represents the value
178
178
  * associated with the key in the node. It is used when creating a new node or updating the value of
179
179
  * an existing node.
@@ -181,7 +181,7 @@ export declare class TreeCounter<K = any, V = any, R = object, MK = any, MV = an
181
181
  * times the key-value pair should be added to the data structure. If not provided, it defaults to 1.
182
182
  * @returns either a TreeCounterNode<K, V> object or undefined.
183
183
  */
184
- protected _keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry: BTNRep<K, V, TreeCounterNode<K, V>>, value?: V, count?: number): [TreeCounterNode<K, V> | undefined, V | undefined];
184
+ protected _keyValueNodeOrEntryToNodeAndValue(keyNodeOrEntry: K | TreeCounterNode<K, V> | [K | null | undefined, V | undefined] | null | undefined, value?: V, count?: number): [TreeCounterNode<K, V> | undefined, V | undefined];
185
185
  /**
186
186
  * Time Complexity: O(1)
187
187
  * Space Complexity: O(1)
@@ -79,7 +79,7 @@ class TreeCounter extends red_black_tree_1.RedBlackTree {
79
79
  */
80
80
  getComputedCount() {
81
81
  let sum = 0;
82
- this.dfs(node => (sum += node.count));
82
+ this.dfs(node => (sum += node ? node.count : 0));
83
83
  return sum;
84
84
  }
85
85
  /**
@@ -111,8 +111,8 @@ class TreeCounter extends red_black_tree_1.RedBlackTree {
111
111
  }
112
112
  /**
113
113
  * The function checks if the input is an instance of the TreeCounterNode class.
114
- * @param {BTNRep<K, V, TreeCounterNode<K, V>>} keyNodeOrEntry - The parameter
115
- * `keyNodeOrEntry` can be of type `R` or `BTNRep<K, V, TreeCounterNode<K, V>>`.
114
+ * @param {K | TreeCounterNode<K, V> | [K | null | undefined, V | undefined] | null | undefined} keyNodeOrEntry - The parameter
115
+ * `keyNodeOrEntry` can be of type `R` or `K | TreeCounterNode<K, V> | [K | null | undefined, V | undefined] | null | undefined`.
116
116
  * @returns a boolean value indicating whether the input parameter `keyNodeOrEntry` is
117
117
  * an instance of the `TreeCounterNode` class.
118
118
  */
@@ -125,7 +125,7 @@ class TreeCounter extends red_black_tree_1.RedBlackTree {
125
125
  *
126
126
  * The function overrides the add method of a class and adds a new node to a data structure, updating
127
127
  * the count and returning a boolean indicating success.
128
- * @param {BTNRep<K, V, TreeCounterNode<K, V>>} keyNodeOrEntry - The
128
+ * @param {K | TreeCounterNode<K, V> | [K | null | undefined, V | undefined] | null | undefined} keyNodeOrEntry - The
129
129
  * `keyNodeOrEntry` parameter can accept one of the following types:
130
130
  * @param {V} [value] - The `value` parameter represents the value associated with the key in the
131
131
  * data structure. It is an optional parameter, so it can be omitted if not needed.
@@ -153,7 +153,7 @@ class TreeCounter extends red_black_tree_1.RedBlackTree {
153
153
  *
154
154
  * The function `delete` in TypeScript overrides the deletion operation in a binary tree data
155
155
  * structure, handling cases where nodes have children and maintaining balance in the tree.
156
- * @param {BTNRep<K, V, TreeCounterNode<K, V>>} keyNodeOrEntry - The `predicate`
156
+ * @param {K | TreeCounterNode<K, V> | [K | null | undefined, V | undefined] | null | undefined} keyNodeOrEntry - The `predicate`
157
157
  * parameter in the `delete` method is used to specify the condition or key based on which a node
158
158
  * should be deleted from the binary tree. It can be a key, a node, or an entry.
159
159
  * @param [ignoreCount=false] - The `ignoreCount` parameter in the `override delete` method is a
@@ -294,9 +294,9 @@ class TreeCounter extends red_black_tree_1.RedBlackTree {
294
294
  return;
295
295
  const m = l + Math.floor((r - l) / 2);
296
296
  const midNode = sorted[m];
297
- if (this._isMapMode)
297
+ if (this._isMapMode && midNode !== null)
298
298
  this.add(midNode.key, undefined, midNode.count);
299
- else
299
+ else if (midNode !== null)
300
300
  this.add(midNode.key, midNode.value, midNode.count);
301
301
  buildBalanceBST(l, m - 1);
302
302
  buildBalanceBST(m + 1, r);
@@ -313,9 +313,9 @@ class TreeCounter extends red_black_tree_1.RedBlackTree {
313
313
  if (l <= r) {
314
314
  const m = l + Math.floor((r - l) / 2);
315
315
  const midNode = sorted[m];
316
- if (this._isMapMode)
316
+ if (this._isMapMode && midNode !== null)
317
317
  this.add(midNode.key, undefined, midNode.count);
318
- else
318
+ else if (midNode !== null)
319
319
  this.add(midNode.key, midNode.value, midNode.count);
320
320
  stack.push([m + 1, r]);
321
321
  stack.push([l, m - 1]);
@@ -334,7 +334,7 @@ class TreeCounter extends red_black_tree_1.RedBlackTree {
334
334
  */
335
335
  clone() {
336
336
  const cloned = this.createTree();
337
- this.bfs(node => cloned.add(node.key, undefined, node.count));
337
+ this.bfs(node => cloned.add(node === null ? null : node.key, undefined, node === null ? 0 : node.count));
338
338
  if (this._isMapMode)
339
339
  cloned._store = this._store;
340
340
  return cloned;
@@ -365,8 +365,8 @@ class TreeCounter extends red_black_tree_1.RedBlackTree {
365
365
  /**
366
366
  * The function `keyValueNodeEntryRawToNodeAndValue` takes in a key, value, and count and returns a
367
367
  * node based on the input.
368
- * @param {BTNRep<K, V, TreeCounterNode<K, V>>} keyNodeOrEntry - The parameter
369
- * `keyNodeOrEntry` can be of type `R` or `BTNRep<K, V, TreeCounterNode<K, V>>`.
368
+ * @param {K | TreeCounterNode<K, V> | [K | null | undefined, V | undefined] | null | undefined} keyNodeOrEntry - The parameter
369
+ * `keyNodeOrEntry` can be of type `R` or `K | TreeCounterNode<K, V> | [K | null | undefined, V | undefined] | null | undefined`.
370
370
  * @param {V} [value] - The `value` parameter is an optional value that represents the value
371
371
  * associated with the key in the node. It is used when creating a new node or updating the value of
372
372
  * an existing node.
@@ -5,10 +5,11 @@
5
5
  * @copyright Copyright (c) 2022 Pablo Zeng <zrwusa@gmail.com>
6
6
  * @license MIT License
7
7
  */
8
- import type { BTNRep, OptNodeOrNull, TreeMultiMapOptions } from '../../types';
8
+ import type { TreeMultiMapOptions } from '../../types';
9
9
  import { RedBlackTree, RedBlackTreeNode } from './red-black-tree';
10
10
  import { IBinaryTree } from '../../interfaces';
11
11
  export declare class TreeMultiMapNode<K = any, V = any> extends RedBlackTreeNode<K, V[]> {
12
+ parent?: TreeMultiMapNode<K, V>;
12
13
  /**
13
14
  * This TypeScript constructor initializes an object with a key of type K and an array of values of
14
15
  * type V.
@@ -18,23 +19,180 @@ export declare class TreeMultiMapNode<K = any, V = any> extends RedBlackTreeNode
18
19
  * @param {V[]} value - The `value` parameter in the constructor represents an array of values of
19
20
  * type `V`.
20
21
  */
21
- constructor(key: K, value: V[]);
22
- parent?: TreeMultiMapNode<K, V>;
23
- _left?: OptNodeOrNull<TreeMultiMapNode<K, V>>;
24
- get left(): OptNodeOrNull<TreeMultiMapNode<K, V>>;
25
- set left(v: OptNodeOrNull<TreeMultiMapNode<K, V>>);
26
- _right?: OptNodeOrNull<TreeMultiMapNode<K, V>>;
27
- get right(): OptNodeOrNull<TreeMultiMapNode<K, V>>;
28
- set right(v: OptNodeOrNull<TreeMultiMapNode<K, V>>);
22
+ constructor(key: K, value?: V[]);
23
+ _left?: TreeMultiMapNode<K, V> | null | undefined;
24
+ get left(): TreeMultiMapNode<K, V> | null | undefined;
25
+ set left(v: TreeMultiMapNode<K, V> | null | undefined);
26
+ _right?: TreeMultiMapNode<K, V> | null | undefined;
27
+ get right(): TreeMultiMapNode<K, V> | null | undefined;
28
+ set right(v: TreeMultiMapNode<K, V> | null | undefined);
29
29
  }
30
30
  /**
31
31
  *
32
32
  * @example
33
- * // Find elements in a range
34
- * const tmm = new TreeMultiMap<number>([10, 5, 15, 3, 7, 12, 18]);
35
- * console.log(tmm.search(new Range(5, 10))); // [5, 10, 7]
36
- * console.log(tmm.search(new Range(4, 12))); // [5, 10, 12, 7]
37
- * console.log(tmm.search(new Range(15, 20))); // [15, 18]
33
+ * // players ranked by score with their equipment
34
+ * type Equipment = {
35
+ * name: string; // Equipment name
36
+ * quality: 'legendary' | 'epic' | 'rare' | 'common';
37
+ * level: number;
38
+ * };
39
+ *
40
+ * type Player = {
41
+ * name: string;
42
+ * score: number;
43
+ * equipments: Equipment[];
44
+ * };
45
+ *
46
+ * // Mock player data with their scores and equipment
47
+ * const players: Player[] = [
48
+ * {
49
+ * name: 'DragonSlayer',
50
+ * score: 8750,
51
+ * equipments: [
52
+ * { name: 'AWM', quality: 'legendary', level: 85 },
53
+ * { name: 'Level 3 Helmet', quality: 'epic', level: 80 },
54
+ * { name: 'Extended Quickdraw Mag', quality: 'rare', level: 75 },
55
+ * { name: 'Compensator', quality: 'epic', level: 78 },
56
+ * { name: 'Vertical Grip', quality: 'rare', level: 72 }
57
+ * ]
58
+ * },
59
+ * {
60
+ * name: 'ShadowNinja',
61
+ * score: 7200,
62
+ * equipments: [
63
+ * { name: 'M416', quality: 'epic', level: 75 },
64
+ * { name: 'Ghillie Suit', quality: 'rare', level: 70 },
65
+ * { name: 'Red Dot Sight', quality: 'common', level: 65 },
66
+ * { name: 'Extended QuickDraw Mag', quality: 'rare', level: 68 }
67
+ * ]
68
+ * },
69
+ * {
70
+ * name: 'RuneMaster',
71
+ * score: 9100,
72
+ * equipments: [
73
+ * { name: 'KAR98K', quality: 'legendary', level: 90 },
74
+ * { name: 'Level 3 Vest', quality: 'legendary', level: 85 },
75
+ * { name: 'Holographic Sight', quality: 'epic', level: 82 },
76
+ * { name: 'Suppressor', quality: 'legendary', level: 88 },
77
+ * { name: 'Level 3 Backpack', quality: 'epic', level: 80 }
78
+ * ]
79
+ * },
80
+ * {
81
+ * name: 'BattleKing',
82
+ * score: 8500,
83
+ * equipments: [
84
+ * { name: 'AUG', quality: 'epic', level: 82 },
85
+ * { name: 'Red Dot Sight', quality: 'rare', level: 75 },
86
+ * { name: 'Extended Mag', quality: 'common', level: 70 },
87
+ * { name: 'Tactical Stock', quality: 'rare', level: 76 }
88
+ * ]
89
+ * },
90
+ * {
91
+ * name: 'SniperElite',
92
+ * score: 7800,
93
+ * equipments: [
94
+ * { name: 'M24', quality: 'legendary', level: 88 },
95
+ * { name: 'Compensator', quality: 'epic', level: 80 },
96
+ * { name: 'Scope 8x', quality: 'legendary', level: 85 },
97
+ * { name: 'Level 2 Helmet', quality: 'rare', level: 75 }
98
+ * ]
99
+ * },
100
+ * {
101
+ * name: 'RushMaster',
102
+ * score: 7500,
103
+ * equipments: [
104
+ * { name: 'Vector', quality: 'rare', level: 72 },
105
+ * { name: 'Level 2 Helmet', quality: 'common', level: 65 },
106
+ * { name: 'Quickdraw Mag', quality: 'common', level: 60 },
107
+ * { name: 'Laser Sight', quality: 'rare', level: 68 }
108
+ * ]
109
+ * },
110
+ * {
111
+ * name: 'GhostWarrior',
112
+ * score: 8200,
113
+ * equipments: [
114
+ * { name: 'SCAR-L', quality: 'epic', level: 78 },
115
+ * { name: 'Extended Quickdraw Mag', quality: 'rare', level: 70 },
116
+ * { name: 'Holographic Sight', quality: 'epic', level: 75 },
117
+ * { name: 'Suppressor', quality: 'rare', level: 72 },
118
+ * { name: 'Vertical Grip', quality: 'common', level: 65 }
119
+ * ]
120
+ * },
121
+ * {
122
+ * name: 'DeathDealer',
123
+ * score: 7300,
124
+ * equipments: [
125
+ * { name: 'SKS', quality: 'epic', level: 76 },
126
+ * { name: 'Holographic Sight', quality: 'rare', level: 68 },
127
+ * { name: 'Extended Mag', quality: 'common', level: 65 }
128
+ * ]
129
+ * },
130
+ * {
131
+ * name: 'StormRider',
132
+ * score: 8900,
133
+ * equipments: [
134
+ * { name: 'MK14', quality: 'legendary', level: 92 },
135
+ * { name: 'Level 3 Backpack', quality: 'legendary', level: 85 },
136
+ * { name: 'Scope 8x', quality: 'epic', level: 80 },
137
+ * { name: 'Suppressor', quality: 'legendary', level: 88 },
138
+ * { name: 'Tactical Stock', quality: 'rare', level: 75 }
139
+ * ]
140
+ * },
141
+ * {
142
+ * name: 'CombatLegend',
143
+ * score: 7600,
144
+ * equipments: [
145
+ * { name: 'UMP45', quality: 'rare', level: 74 },
146
+ * { name: 'Level 2 Vest', quality: 'common', level: 67 },
147
+ * { name: 'Red Dot Sight', quality: 'common', level: 62 },
148
+ * { name: 'Extended Mag', quality: 'rare', level: 70 }
149
+ * ]
150
+ * }
151
+ * ];
152
+ *
153
+ * // Create a TreeMultiMap for player rankings
154
+ * const playerRankings = new TreeMultiMap<number, Equipment, Player>(players, {
155
+ * toEntryFn: ({ score, equipments }) => [score, equipments],
156
+ * isMapMode: false
157
+ * });
158
+ *
159
+ * const topPlayersEquipments = playerRankings.rangeSearch([8900, 10000], node => playerRankings.get(node));
160
+ * console.log(topPlayersEquipments); // [
161
+ * // [
162
+ * // {
163
+ * // name: 'MK14',
164
+ * // quality: 'legendary',
165
+ * // level: 92
166
+ * // },
167
+ * // { name: 'Level 3 Backpack', quality: 'legendary', level: 85 },
168
+ * // {
169
+ * // name: 'Scope 8x',
170
+ * // quality: 'epic',
171
+ * // level: 80
172
+ * // },
173
+ * // { name: 'Suppressor', quality: 'legendary', level: 88 },
174
+ * // {
175
+ * // name: 'Tactical Stock',
176
+ * // quality: 'rare',
177
+ * // level: 75
178
+ * // }
179
+ * // ],
180
+ * // [
181
+ * // { name: 'KAR98K', quality: 'legendary', level: 90 },
182
+ * // {
183
+ * // name: 'Level 3 Vest',
184
+ * // quality: 'legendary',
185
+ * // level: 85
186
+ * // },
187
+ * // { name: 'Holographic Sight', quality: 'epic', level: 82 },
188
+ * // {
189
+ * // name: 'Suppressor',
190
+ * // quality: 'legendary',
191
+ * // level: 88
192
+ * // },
193
+ * // { name: 'Level 3 Backpack', quality: 'epic', level: 80 }
194
+ * // ]
195
+ * // ]
38
196
  */
39
197
  export declare class TreeMultiMap<K = any, V = any, R = object, MK = any, MV = any, MR = object> extends RedBlackTree<K, V[], R, MK, MV[], MR> implements IBinaryTree<K, V[], R, MK, MV, MR> {
40
198
  /**
@@ -48,7 +206,7 @@ export declare class TreeMultiMap<K = any, V = any, R = object, MK = any, MV = a
48
206
  * `TreeMultiMapOptions<K, V[], R>`. It is an optional parameter that allows you to specify
49
207
  * additional options for configuring the TreeMultiMap instance.
50
208
  */
51
- constructor(keysNodesEntriesOrRaws?: Iterable<BTNRep<K, V[], TreeMultiMapNode<K, V>> | R>, options?: TreeMultiMapOptions<K, V[], R>);
209
+ constructor(keysNodesEntriesOrRaws?: Iterable<K | TreeMultiMapNode<K, V> | [K | null | undefined, V[] | undefined] | null | undefined | R>, options?: TreeMultiMapOptions<K, V[], R>);
52
210
  /**
53
211
  * Time Complexity: O(1)
54
212
  * Space Complexity: O(1)
@@ -67,15 +225,18 @@ export declare class TreeMultiMap<K = any, V = any, R = object, MK = any, MV = a
67
225
  * Time Complexity: O(1)
68
226
  * Space Complexity: O(1)
69
227
  *
70
- * The function `createNode` overrides the method to create a new `TreeMultiMapNode` with a specified
71
- * key and an empty array of values.
72
- * @param {K} key - The `key` parameter in the `createNode` method represents the key of the node
73
- * that will be created in the TreeMultiMap data structure.
74
- * @returns A new instance of `TreeMultiMapNode<K, V>` is being returned, with the specified key and
75
- * an empty array as its value.
228
+ * The function `createNode` overrides the creation of a new TreeMultiMapNode with a specified key
229
+ * and value array.
230
+ * @param {K} key - The `key` parameter represents the key of the node being created in the
231
+ * `TreeMultiMap`.
232
+ * @param {V[]} value - The `value` parameter in the `createNode` method represents an array of
233
+ * values associated with a specific key in the TreeMultiMap data structure.
234
+ * @returns A new instance of `TreeMultiMapNode<K, V>` is being returned with the specified key and
235
+ * value. If `_isMapMode` is true, an empty array is passed as the value, otherwise the provided
236
+ * value is used.
76
237
  */
77
- createNode(key: K): TreeMultiMapNode<K, V>;
78
- add(node: BTNRep<K, V[], TreeMultiMapNode<K, V>>): boolean;
238
+ createNode(key: K, value?: V[]): TreeMultiMapNode<K, V>;
239
+ add(keyNodeOrEntry: K | TreeMultiMapNode<K, V> | [K | null | undefined, V[] | undefined] | null | undefined): boolean;
79
240
  add(key: K, value: V): boolean;
80
241
  /**
81
242
  * Time Complexity: O(log n)
@@ -83,7 +244,7 @@ export declare class TreeMultiMap<K = any, V = any, R = object, MK = any, MV = a
83
244
  *
84
245
  * The function `deleteValue` removes a specific value from a key in a TreeMultiMap data structure
85
246
  * and deletes the entire node if no values are left for that key.
86
- * @param {BTNRep<K, V[], TreeMultiMapNode<K, V>> | K} keyNodeOrEntry - The `keyNodeOrEntry`
247
+ * @param {K | TreeMultiMapNode<K, V> | [K | null | undefined, V[] | undefined] | null | undefined} keyNodeOrEntry - The `keyNodeOrEntry`
87
248
  * parameter in the `deleteValue` function can be either a `BTNRep` object containing a key and an
88
249
  * array of values, or just a key itself.
89
250
  * @param {V} value - The `value` parameter in the `deleteValue` function represents the specific
@@ -93,7 +254,7 @@ export declare class TreeMultiMap<K = any, V = any, R = object, MK = any, MV = a
93
254
  * @returns The `deleteValue` function returns a boolean value - `true` if the specified `value` was
94
255
  * successfully deleted from the values associated with the `keyNodeOrEntry`, and `false` otherwise.
95
256
  */
96
- deleteValue(keyNodeOrEntry: BTNRep<K, V[], TreeMultiMapNode<K, V>> | K, value: V): boolean;
257
+ deleteValue(keyNodeOrEntry: K | TreeMultiMapNode<K, V> | [K | null | undefined, V[] | undefined] | null | undefined, value: V): boolean;
97
258
  /**
98
259
  * Time Complexity: O(n)
99
260
  * Space Complexity: O(n)