tree-multimap-typed 2.4.1 → 2.4.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tree-multimap-typed",
3
- "version": "2.4.1",
3
+ "version": "2.4.3",
4
4
  "description": "TreeMultiMap - A sorted map that allows multiple values per key",
5
5
  "browser": "dist/umd/tree-multimap-typed.min.js",
6
6
  "umd:main": "dist/umd/tree-multimap-typed.min.js",
@@ -217,6 +217,6 @@
217
217
  "typescript": "^4.9.5"
218
218
  },
219
219
  "dependencies": {
220
- "data-structure-typed": "^2.4.1"
220
+ "data-structure-typed": "^2.4.3"
221
221
  }
222
222
  }
@@ -436,4 +436,20 @@ export class TreeMap<K = any, V = any, R = [K, V]> implements Iterable<[K, V | u
436
436
 
437
437
  return out;
438
438
  }
439
+
440
+ /**
441
+ * Creates a shallow clone of this map.
442
+ * @remarks Time O(n log n), Space O(n)
443
+ * @example
444
+ * const original = new TreeMap([['a', 1], ['b', 2]]);
445
+ * const copy = original.clone();
446
+ * copy.set('c', 3);
447
+ * original.has('c'); // false (original unchanged)
448
+ */
449
+ clone(): TreeMap<K, V> {
450
+ return new TreeMap<K, V>(this, {
451
+ comparator: this.#isDefaultComparator ? undefined : this.#userComparator,
452
+ isMapMode: this.#core.isMapMode
453
+ });
454
+ }
439
455
  }
@@ -404,4 +404,20 @@ export class TreeSet<K = any, R = K> implements Iterable<K> {
404
404
 
405
405
  return out;
406
406
  }
407
+
408
+ /**
409
+ * Creates a shallow clone of this set.
410
+ * @remarks Time O(n log n), Space O(n)
411
+ * @example
412
+ * const original = new TreeSet([1, 2, 3]);
413
+ * const copy = original.clone();
414
+ * copy.add(4);
415
+ * original.has(4); // false (original unchanged)
416
+ */
417
+ clone(): TreeSet<K> {
418
+ return new TreeSet<K>(this, {
419
+ comparator: this.#isDefaultComparator ? undefined : this.#userComparator,
420
+ isMapMode: this.#core.isMapMode
421
+ });
422
+ }
407
423
  }
@@ -564,19 +564,17 @@ export class Trie<R = any> extends IterableElementBase<string, R> {
564
564
  const words: string[] = [];
565
565
  let found = 0;
566
566
 
567
- function dfs(node: TrieNode, word: string) {
568
- for (const char of node.children.keys()) {
569
- const charNode = node.children.get(char);
570
- if (charNode !== undefined) {
571
- dfs(charNode, word.concat(char));
572
- }
567
+ const dfs = (node: TrieNode, word: string): void => {
568
+ for (const [char, childNode] of node.children) {
569
+ if (found >= max) return;
570
+ dfs(childNode, word + char);
573
571
  }
574
572
  if (node.isEnd) {
575
- if (found > max - 1) return;
573
+ if (found >= max) return;
576
574
  words.push(word);
577
575
  found++;
578
576
  }
579
- }
577
+ };
580
578
 
581
579
  let startNode = this.root;
582
580