queue-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.
@@ -185,4 +185,14 @@ export declare class TreeMap<K = any, V = any, R = [K, V]> implements Iterable<[
185
185
  * @param options Inclusive/exclusive bounds (defaults to inclusive).
186
186
  */
187
187
  rangeSearch(range: [K, K], options?: TreeMapRangeOptions): Array<[K, V | undefined]>;
188
+ /**
189
+ * Creates a shallow clone of this map.
190
+ * @remarks Time O(n log n), Space O(n)
191
+ * @example
192
+ * const original = new TreeMap([['a', 1], ['b', 2]]);
193
+ * const copy = original.clone();
194
+ * copy.set('c', 3);
195
+ * original.has('c'); // false (original unchanged)
196
+ */
197
+ clone(): TreeMap<K, V>;
188
198
  }
@@ -178,4 +178,14 @@ export declare class TreeSet<K = any, R = K> implements Iterable<K> {
178
178
  * @param options Inclusive/exclusive bounds (defaults to inclusive).
179
179
  */
180
180
  rangeSearch(range: [K, K], options?: TreeSetRangeOptions): K[];
181
+ /**
182
+ * Creates a shallow clone of this set.
183
+ * @remarks Time O(n log n), Space O(n)
184
+ * @example
185
+ * const original = new TreeSet([1, 2, 3]);
186
+ * const copy = original.clone();
187
+ * copy.add(4);
188
+ * original.has(4); // false (original unchanged)
189
+ */
190
+ clone(): TreeSet<K>;
181
191
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "queue-typed",
3
- "version": "2.4.1",
3
+ "version": "2.4.3",
4
4
  "description": "Queue data structure",
5
5
  "browser": "dist/umd/queue-typed.min.js",
6
6
  "umd:main": "dist/umd/queue-typed.min.js",
@@ -153,6 +153,6 @@
153
153
  "typescript": "^4.9.5"
154
154
  },
155
155
  "dependencies": {
156
- "data-structure-typed": "^2.4.1"
156
+ "data-structure-typed": "^2.4.3"
157
157
  }
158
158
  }
@@ -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