data-structure-typed 2.2.6 → 2.2.8

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 (72) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/CONTRIBUTING.md +47 -1
  3. package/README.md +19 -8
  4. package/README_CN.md +119 -275
  5. package/benchmark/report.html +1 -1
  6. package/benchmark/report.json +20 -324
  7. package/dist/cjs/index.cjs +109 -107
  8. package/dist/cjs/index.cjs.map +1 -1
  9. package/dist/cjs-legacy/index.cjs +109 -107
  10. package/dist/cjs-legacy/index.cjs.map +1 -1
  11. package/dist/esm/index.mjs +109 -107
  12. package/dist/esm/index.mjs.map +1 -1
  13. package/dist/esm-legacy/index.mjs +109 -107
  14. package/dist/esm-legacy/index.mjs.map +1 -1
  15. package/dist/leetcode/avl-tree-counter.mjs +2957 -0
  16. package/dist/leetcode/avl-tree-multi-map.mjs +2889 -0
  17. package/dist/leetcode/avl-tree.mjs +2720 -0
  18. package/dist/leetcode/binary-tree.mjs +1594 -0
  19. package/dist/leetcode/bst.mjs +2398 -0
  20. package/dist/leetcode/deque.mjs +683 -0
  21. package/dist/leetcode/directed-graph.mjs +1733 -0
  22. package/dist/leetcode/doubly-linked-list.mjs +709 -0
  23. package/dist/leetcode/hash-map.mjs +493 -0
  24. package/dist/leetcode/heap.mjs +542 -0
  25. package/dist/leetcode/max-heap.mjs +375 -0
  26. package/dist/leetcode/max-priority-queue.mjs +383 -0
  27. package/dist/leetcode/min-heap.mjs +363 -0
  28. package/dist/leetcode/min-priority-queue.mjs +371 -0
  29. package/dist/leetcode/priority-queue.mjs +363 -0
  30. package/dist/leetcode/queue.mjs +943 -0
  31. package/dist/leetcode/red-black-tree.mjs +2765 -0
  32. package/dist/leetcode/singly-linked-list.mjs +754 -0
  33. package/dist/leetcode/stack.mjs +217 -0
  34. package/dist/leetcode/tree-counter.mjs +3039 -0
  35. package/dist/leetcode/tree-multi-map.mjs +2913 -0
  36. package/dist/leetcode/trie.mjs +413 -0
  37. package/dist/leetcode/undirected-graph.mjs +1650 -0
  38. package/dist/types/data-structures/binary-tree/avl-tree-counter.d.ts +1 -1
  39. package/dist/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +2 -2
  40. package/dist/types/data-structures/binary-tree/avl-tree.d.ts +10 -10
  41. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +22 -23
  42. package/dist/types/data-structures/binary-tree/bst.d.ts +11 -11
  43. package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +1 -1
  44. package/dist/types/data-structures/binary-tree/tree-counter.d.ts +1 -1
  45. package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +2 -2
  46. package/dist/umd/data-structure-typed.js +105 -103
  47. package/dist/umd/data-structure-typed.js.map +1 -1
  48. package/dist/umd/data-structure-typed.min.js +2 -2
  49. package/dist/umd/data-structure-typed.min.js.map +1 -1
  50. package/package.json +48 -171
  51. package/src/data-structures/binary-tree/avl-tree-counter.ts +6 -6
  52. package/src/data-structures/binary-tree/avl-tree-multi-map.ts +13 -13
  53. package/src/data-structures/binary-tree/avl-tree.ts +15 -15
  54. package/src/data-structures/binary-tree/binary-tree.ts +53 -55
  55. package/src/data-structures/binary-tree/bst.ts +21 -22
  56. package/src/data-structures/binary-tree/red-black-tree.ts +3 -3
  57. package/src/data-structures/binary-tree/tree-counter.ts +4 -4
  58. package/src/data-structures/binary-tree/tree-multi-map.ts +13 -13
  59. package/test/performance/data-structures/binary-tree/red-black-tree.test.ts +1 -2
  60. package/test/unit/data-structures/binary-tree/avl-tree-counter.test.ts +30 -30
  61. package/test/unit/data-structures/binary-tree/avl-tree-multi-map.test.ts +46 -46
  62. package/test/unit/data-structures/binary-tree/avl-tree.test.ts +43 -43
  63. package/test/unit/data-structures/binary-tree/binary-tree.test.ts +151 -151
  64. package/test/unit/data-structures/binary-tree/bst.test.ts +99 -99
  65. package/test/unit/data-structures/binary-tree/overall.test.ts +20 -20
  66. package/test/unit/data-structures/binary-tree/red-black-tree.test.ts +141 -141
  67. package/test/unit/data-structures/binary-tree/tree-counter.test.ts +37 -37
  68. package/test/unit/data-structures/binary-tree/tree-multi-map.test.ts +145 -145
  69. package/tsup.config.js +50 -21
  70. package/tsup.leetcode.config.js +1 -1
  71. package/tsup.umd.config.js +29 -0
  72. package/tsup.node.config.js +0 -83
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "data-structure-typed",
3
- "version": "2.2.6",
3
+ "version": "2.2.8",
4
4
  "description": "Standard data structure",
5
5
  "browser": "dist/umd/data-structure-typed.min.js",
6
6
  "umd:main": "dist/umd/data-structure-typed.min.js",
@@ -38,21 +38,21 @@
38
38
  "npm": ">=6.14.0"
39
39
  },
40
40
  "scripts": {
41
- "build": "npm run build:ecu && npm run build:docs-class",
42
- "build:node": "tsup --config tsup.node.config.js",
43
- "build:leetcode": "tsup --config tsup.leetcode.config.js",
41
+ "build": "npm run build:ecut && npm run build:docs-class",
42
+ "build:node": "tsup",
43
+ "build:umd": "tsup --config tsup.umd.config.js",
44
44
  "build:types": "rm -rf dist/types && tsc -p tsconfig.types.json",
45
- "build:umd": "tsup",
46
- "build:ecu": "npm run build:node && npm run build:types && npm run build:umd",
45
+ "build:ecut": "npm run build:node && npm run build:types && npm run build:umd",
46
+ "build:leetcode": "tsup --config tsup.leetcode.config.js",
47
47
  "build:docs": "npm run gen:examples && typedoc --out docs ./src",
48
48
  "build:docs-class": "npm run gen:examples && typedoc --out docs ./src/data-structures",
49
49
  "gen:examples": "ts-node scripts/test-to-example.ts",
50
50
  "test:in-band": "jest --runInBand",
51
51
  "test": "npm run test:in-band",
52
52
  "test:integration": "npm run update:subs && jest --config jest.integration.config.js && tsc test/integration/compile.test.ts && node test/integration/compile.mjs",
53
- "test:perf": "npm run build:ecu && ts-node test/performance/benchmark-runner.ts --isolate --gc --cooldown-ms=80",
53
+ "test:perf": "npm run build:ecut && ts-node test/performance/benchmark-runner.ts --isolate --gc --cooldown-ms=80",
54
54
  "check": "npm run check:src && npm run check:test",
55
- "check:src": "tsc -p tsconfig.test.json --noEmit",
55
+ "check:src": "tsc --noEmit",
56
56
  "check:test": "tsc -p tsconfig.test.json --noEmit",
57
57
  "check:circular-refs": "dependency-cruiser src",
58
58
  "lint:src": "eslint --fix 'src/**/*.{js,ts}'",
@@ -102,7 +102,7 @@
102
102
  "benchmark": "^2.1.4",
103
103
  "binary-tree-typed": "^1.54.3",
104
104
  "bst-typed": "^1.54.3",
105
- "data-structure-typed": "^2.2.5",
105
+ "data-structure-typed": "^2.2.7",
106
106
  "dependency-cruiser": "^16.5.0",
107
107
  "doctoc": "^2.2.1",
108
108
  "eslint": "^9.13.0",
@@ -124,178 +124,55 @@
124
124
  "typescript": "^5.6.3"
125
125
  },
126
126
  "keywords": [
127
- "data",
128
- "structure",
129
- "structures",
130
- "data structure",
131
- "datastructure",
132
- "data-structure",
133
- "data structures",
134
- "datastructures",
135
- "data-structures",
136
- "in data structures",
137
- "in data structure",
138
- "binary",
139
- "depth",
140
- "breadth",
141
- "first",
142
- "search",
143
- "index",
144
- "avl",
145
- "red",
146
- "black",
147
- "redblack",
148
- "RB",
149
- "segment",
150
- "prefix",
151
- "tree",
152
- "multi",
153
- "map",
154
- "set",
155
- "multiset",
156
- "multimap",
157
- "directed",
158
- "undirected",
159
- "graph",
160
- "min",
161
- "max",
162
- "heap",
163
- "priority",
164
- "queue",
165
- "singly",
166
- "doubly",
167
- "linked",
168
- "list",
169
- "js",
170
- "ts",
171
- "javascript",
172
- "typscript",
173
- "Node.js",
174
- "NodeJS",
175
- "c++",
176
- "std",
177
- "C++ STL",
178
- "c++stl",
179
- "C++ std",
180
- "stl",
181
- "std::",
182
- "Python",
183
- "collections",
184
- "Python Collections",
185
- "pythoncollections",
186
- "python-collections",
187
- "C#",
188
- "System.Collections.Generic",
189
- "collection",
190
- "java.util",
191
- "Java",
192
- "util",
127
+ "data structures typescript",
128
+ "data structures javascript",
129
+ "typescript data structures",
130
+ "javascript data structures",
131
+ "data-structure library",
132
+ "algorithm library",
193
133
  "binary search tree",
194
- "binarysearchtree",
195
- "binary-search-tree",
196
- "BST",
197
- "binary tree",
198
- "binarytree",
199
- "binary-tree",
134
+ "AVL tree",
200
135
  "red black tree",
201
- "redblacktree",
202
- "redblack tree",
203
- "red-black-tree",
204
- "redblack-tree",
205
- "trie",
206
- "prefix tree",
207
- "prefixtree",
208
- "prefix-tree",
209
- "avl tree",
210
- "avltree",
211
- "avl-tree",
212
- "tree set",
213
- "treeset",
214
- "tree-set",
215
- "tree multiset",
216
- "treemultiset",
217
- "tree-multiset",
218
- "tree map",
219
- "treemap",
220
- "tree-map",
221
- "tree multimap",
222
- "treemultimap",
223
- "tree-multimap",
224
- "binary indexed tree",
225
- "binaryindexedtree",
226
- "binary-indexed-tree",
227
- "segment tree",
228
- "segmenttree",
229
- "segment-tree",
230
- "sort",
231
- "sorted",
232
- "order",
233
- "ordered",
234
- "algorithm",
235
- "morris",
236
- "Morris",
237
- "bellman ford",
238
- "bellmanford",
239
- "bellman-ford",
240
- "dijkstra",
241
- "Dijkstra",
242
- "floyd warshall",
243
- "floydwarshall",
244
- "floyd-warshall",
245
- "tarjan",
246
- "tarjan's",
247
- "dfs",
248
- "depth first Search",
249
- "depthfirstSearch",
250
- "depth-first-Search",
251
- "bfs",
252
- "breadth first search",
253
- "breadthfirstsearch",
254
- "dfs iterative",
255
- "recursive",
256
- "iterative",
136
+ "balanced tree",
137
+ "binary tree",
138
+ "BST",
139
+ "graph algorithm",
257
140
  "directed graph",
258
- "directedgraph",
259
- "directed-graph",
260
141
  "undirected graph",
261
- "undirectedgraph",
262
- "undirected-graph",
142
+ "heap",
143
+ "priority queue",
263
144
  "min heap",
264
- "minheap",
265
- "min-heap",
266
145
  "max heap",
267
- "maxheap",
268
- "max-heap",
269
- "priority queue",
270
- "priorityqueue",
271
- "priority-queue",
272
- "max priority queue",
273
- "maxpriorityqueue",
274
- "max-priority-queue",
275
- "min priority queue",
276
- "minpriorityqueue",
277
- "min-priority-queue",
278
- "hash",
279
- "map",
280
- "hash map",
281
- "hashmap",
282
- "hash-map",
146
+ "queue",
283
147
  "deque",
148
+ "stack",
284
149
  "linked list",
285
- "linkedlist",
286
- "linked-list",
287
150
  "singly linked list",
288
- "singlylinkedlist",
289
- "singly-linked-list",
290
151
  "doubly linked list",
291
- "doublylinkedlist",
292
- "doubly-linked-list",
293
- "stack",
152
+ "trie",
153
+ "hash map",
154
+ "hash table",
155
+ "tree multimap",
156
+ "tree multiset",
157
+ "tree map",
158
+ "tree set",
159
+ "ordered set",
160
+ "ordered map",
161
+ "depth first search",
162
+ "breadth first search",
163
+ "DFS",
164
+ "BFS",
165
+ "dijkstra algorithm",
166
+ "bellman ford",
167
+ "floyd warshall",
168
+ "tarjan algorithm",
169
+ "topological sort",
170
+ "leetcode",
171
+ "coding interview",
172
+ "algorithm practice",
173
+ "collection",
174
+ "ES6 modules",
294
175
  "CommonJS",
295
- "ES6",
296
- "UMD",
297
- "ES Modules",
298
- "ESModules",
299
- "ESModule"
176
+ "type-safe"
300
177
  ]
301
178
  }
@@ -200,7 +200,7 @@ export class AVLTreeCounter<K = any, V = any, R = any> extends AVLTree<K, V, R>
200
200
  options?: AVLTreeCounterOptions<K, V, R>
201
201
  ) {
202
202
  super([], options);
203
- if (keysNodesEntriesOrRaws) this.addMany(keysNodesEntriesOrRaws);
203
+ if (keysNodesEntriesOrRaws) this.setMany(keysNodesEntriesOrRaws);
204
204
  }
205
205
 
206
206
  protected _count = 0;
@@ -243,7 +243,7 @@ export class AVLTreeCounter<K = any, V = any, R = any> extends AVLTree<K, V, R>
243
243
  * @param [count] - How much to increase the node's count (default 1).
244
244
  * @returns True if inserted/updated; false if ignored.
245
245
  */
246
- override add(
246
+ override set(
247
247
  keyNodeOrEntry: K | AVLTreeCounterNode<K, V> | [K | null | undefined, V | undefined] | null | undefined,
248
248
  value?: V,
249
249
  count = 1
@@ -252,7 +252,7 @@ export class AVLTreeCounter<K = any, V = any, R = any> extends AVLTree<K, V, R>
252
252
  if (newNode === undefined) return false;
253
253
 
254
254
  const orgNodeCount = newNode?.count || 0;
255
- const inserted = super.add(newNode, newValue);
255
+ const inserted = super.set(newNode, newValue);
256
256
  if (inserted) {
257
257
  this._count += orgNodeCount;
258
258
  }
@@ -380,9 +380,9 @@ export class AVLTreeCounter<K = any, V = any, R = any> extends AVLTree<K, V, R>
380
380
  const out = this._createInstance();
381
381
 
382
382
  if (this._isMapMode) {
383
- this.bfs(node => out.add(node.key, undefined, node.count));
383
+ this.bfs(node => out.set(node.key, undefined, node.count));
384
384
  } else {
385
- this.bfs(node => out.add(node.key, node.value, node.count));
385
+ this.bfs(node => out.set(node.key, node.value, node.count));
386
386
  }
387
387
 
388
388
  if (this._isMapMode) out._store = this._store;
@@ -410,7 +410,7 @@ export class AVLTreeCounter<K = any, V = any, R = any> extends AVLTree<K, V, R>
410
410
 
411
411
  let index = 0;
412
412
  for (const [key, value] of this) {
413
- out.add(callback.call(thisArg, value, key, index++, this));
413
+ out.set(callback.call(thisArg, value, key, index++, this));
414
414
  }
415
415
  return out;
416
416
  }
@@ -199,7 +199,7 @@ export class AVLTreeMultiMap<K = any, V = any, R = any> extends AVLTree<K, V[],
199
199
  ) {
200
200
  super([], { ...options, isMapMode: true });
201
201
  if (keysNodesEntriesOrRaws) {
202
- this.addMany(keysNodesEntriesOrRaws);
202
+ this.setMany(keysNodesEntriesOrRaws);
203
203
  }
204
204
  }
205
205
 
@@ -220,29 +220,29 @@ export class AVLTreeMultiMap<K = any, V = any, R = any> extends AVLTree<K, V[],
220
220
  return keyNodeOrEntry instanceof AVLTreeMultiMapNode;
221
221
  }
222
222
 
223
- override add(
223
+ override set(
224
224
  keyNodeOrEntry: K | AVLTreeMultiMapNode<K, V> | [K | null | undefined, V[] | undefined] | null | undefined
225
225
  ): boolean;
226
226
 
227
- override add(key: K, value: V): boolean;
227
+ override set(key: K, value: V): boolean;
228
228
 
229
229
  /**
230
230
  * Insert a value or a list of values into the multimap. If the key exists, values are appended.
231
231
  * @remarks Time O(log N + M), Space O(1)
232
232
  * @param keyNodeOrEntry - Key, node, or [key, values] entry.
233
- * @param [value] - Single value to add when a bare key is provided.
233
+ * @param [value] - Single value to set when a bare key is provided.
234
234
  * @returns True if inserted or appended; false if ignored.
235
235
  */
236
- override add(
236
+ override set(
237
237
  keyNodeOrEntry: K | AVLTreeMultiMapNode<K, V> | [K | null | undefined, V[] | undefined] | null | undefined,
238
238
  value?: V
239
239
  ): boolean {
240
- if (this.isRealNode(keyNodeOrEntry)) return super.add(keyNodeOrEntry);
240
+ if (this.isRealNode(keyNodeOrEntry)) return super.set(keyNodeOrEntry);
241
241
 
242
242
  const _commonAdd = (key?: BTNOptKeyOrNull<K>, values?: V[]) => {
243
243
  if (key === undefined || key === null) return false;
244
244
 
245
- const _addToValues = () => {
245
+ const _setToValues = () => {
246
246
  const existingValues = this.get(key);
247
247
  if (existingValues !== undefined && values !== undefined) {
248
248
  for (const value of values) existingValues.push(value);
@@ -251,12 +251,12 @@ export class AVLTreeMultiMap<K = any, V = any, R = any> extends AVLTree<K, V[],
251
251
  return false;
252
252
  };
253
253
 
254
- const _addByNode = () => {
254
+ const _setByNode = () => {
255
255
  const existingNode = this.getNode(key);
256
256
  if (this.isRealNode(existingNode)) {
257
257
  const existingValues = this.get(existingNode);
258
258
  if (existingValues === undefined) {
259
- super.add(key, values);
259
+ super.set(key, values);
260
260
  return true;
261
261
  }
262
262
  if (values !== undefined) {
@@ -266,14 +266,14 @@ export class AVLTreeMultiMap<K = any, V = any, R = any> extends AVLTree<K, V[],
266
266
  return false;
267
267
  }
268
268
  } else {
269
- return super.add(key, values);
269
+ return super.set(key, values);
270
270
  }
271
271
  };
272
272
 
273
273
  if (this._isMapMode) {
274
- return _addByNode() || _addToValues();
274
+ return _setByNode() || _setToValues();
275
275
  }
276
- return _addToValues() || _addByNode();
276
+ return _setToValues() || _setByNode();
277
277
  };
278
278
 
279
279
  if (this.isEntry(keyNodeOrEntry)) {
@@ -392,7 +392,7 @@ export class AVLTreeMultiMap<K = any, V = any, R = any> extends AVLTree<K, V[],
392
392
  ): AVLTree<MK, MV, MR> {
393
393
  const out = this._createLike<MK, MV, MR>([], options);
394
394
  let i = 0;
395
- for (const [k, v] of this) out.add(callback.call(thisArg, v, k, i++, this));
395
+ for (const [k, v] of this) out.set(callback.call(thisArg, v, k, i++, this));
396
396
  return out;
397
397
  }
398
398
 
@@ -182,7 +182,7 @@ export class AVLTreeNode<K = any, V = any> {
182
182
 
183
183
  /**
184
184
  * Represents a self-balancing AVL (Adelson-Velsky and Landis) Tree.
185
- * This tree extends BST and performs rotations on add/delete to maintain balance.
185
+ * This tree extends BST and performs rotations on set/delete to maintain balance.
186
186
  *
187
187
  * @template K - The type of the key.
188
188
  * @template V - The type of the value.
@@ -215,7 +215,7 @@ export class AVLTreeNode<K = any, V = any> {
215
215
  * console.log(tree.size); // 5;
216
216
  *
217
217
  * // Add a new element
218
- * tree.add(3);
218
+ * tree.set(3);
219
219
  * console.log(tree.size); // 6;
220
220
  * console.log([...tree.keys()]); // [1, 2, 3, 5, 8, 9];
221
221
  * @example
@@ -278,7 +278,7 @@ export class AVLTreeNode<K = any, V = any> {
278
278
  * console.log(universityTree.isAVLBalanced()); // true;
279
279
  *
280
280
  * // Add more universities
281
- * universityTree.add(6, { name: 'Oxford', rank: 6, students: 2000 });
281
+ * universityTree.set(6, { name: 'Oxford', rank: 6, students: 2000 });
282
282
  * console.log(universityTree.isAVLBalanced()); // true;
283
283
  *
284
284
  * // Delete and verify balance is maintained
@@ -358,9 +358,9 @@ export class AVLTreeNode<K = any, V = any> {
358
358
  export class AVLTree<K = any, V = any, R = any> extends BST<K, V, R> implements IBinaryTree<K, V, R> {
359
359
  /**
360
360
  * Creates an instance of AVLTree.
361
- * @remarks Time O(N log N) (from `addMany` with balanced add). Space O(N).
361
+ * @remarks Time O(N log N) (from `setMany` with balanced set). Space O(N).
362
362
  *
363
- * @param [keysNodesEntriesOrRaws=[]] - An iterable of items to add.
363
+ * @param [keysNodesEntriesOrRaws=[]] - An iterable of items to set.
364
364
  * @param [options] - Configuration options for the AVL tree.
365
365
  */
366
366
  constructor(
@@ -370,8 +370,8 @@ export class AVLTree<K = any, V = any, R = any> extends BST<K, V, R> implements
370
370
  options?: AVLTreeOptions<K, V, R>
371
371
  ) {
372
372
  super([], options);
373
- // Note: super.addMany is called, which in BST defaults to balanced add.
374
- if (keysNodesEntriesOrRaws) super.addMany(keysNodesEntriesOrRaws);
373
+ // Note: super.setMany is called, which in BST defaults to balanced set.
374
+ if (keysNodesEntriesOrRaws) super.setMany(keysNodesEntriesOrRaws);
375
375
  }
376
376
 
377
377
  /**
@@ -400,19 +400,19 @@ export class AVLTree<K = any, V = any, R = any> extends BST<K, V, R> implements
400
400
  }
401
401
 
402
402
  /**
403
- * Adds a new node to the AVL tree and balances the tree path.
404
- * @remarks Time O(log N) (O(H) for BST add + O(H) for `_balancePath`). Space O(H) for path/recursion.
403
+ * Sets a new node to the AVL tree and balances the tree path.
404
+ * @remarks Time O(log N) (O(H) for BST set + O(H) for `_balancePath`). Space O(H) for path/recursion.
405
405
  *
406
- * @param keyNodeOrEntry - The key, node, or entry to add.
406
+ * @param keyNodeOrEntry - The key, node, or entry to set.
407
407
  * @param [value] - The value, if providing just a key.
408
408
  * @returns True if the addition was successful, false otherwise.
409
409
  */
410
- override add(
410
+ override set(
411
411
  keyNodeOrEntry: K | AVLTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined,
412
412
  value?: V
413
413
  ): boolean {
414
414
  if (keyNodeOrEntry === null) return false;
415
- const inserted = super.add(keyNodeOrEntry, value);
415
+ const inserted = super.set(keyNodeOrEntry, value);
416
416
  // If insertion was successful, balance the path from the new node up to the root.
417
417
  if (inserted) this._balancePath(keyNodeOrEntry);
418
418
  return inserted;
@@ -477,7 +477,7 @@ export class AVLTree<K = any, V = any, R = any> extends BST<K, V, R> implements
477
477
 
478
478
  /**
479
479
  * Creates a new AVLTree by mapping each [key, value] pair.
480
- * @remarks Time O(N log N) (O(N) iteration + O(log M) `add` for each item into the new tree). Space O(N) for the new tree.
480
+ * @remarks Time O(N log N) (O(N) iteration + O(log M) `set` for each item into the new tree). Space O(N) for the new tree.
481
481
  *
482
482
  * @template MK - New key type.
483
483
  * @template MV - New value type.
@@ -497,8 +497,8 @@ export class AVLTree<K = any, V = any, R = any> extends BST<K, V, R> implements
497
497
  let index = 0;
498
498
  // Iterates in-order
499
499
  for (const [key, value] of this) {
500
- // `add` on the new tree will be O(log N) and will self-balance.
501
- out.add(callback.call(thisArg, value, key, index++, this));
500
+ // `set` on the new tree will be O(log N) and will self-balance.
501
+ out.set(callback.call(thisArg, value, key, index++, this));
502
502
  }
503
503
  return out;
504
504
  }