trie-typed 2.5.0 → 2.5.2
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/dist/cjs/index.cjs +323 -52
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs-legacy/index.cjs +322 -51
- package/dist/cjs-legacy/index.cjs.map +1 -1
- package/dist/esm/index.mjs +323 -53
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm-legacy/index.mjs +322 -52
- package/dist/esm-legacy/index.mjs.map +1 -1
- package/dist/types/common/error.d.ts +9 -0
- package/dist/types/common/index.d.ts +1 -1
- package/dist/types/data-structures/base/index.d.ts +1 -0
- package/dist/types/data-structures/base/iterable-entry-base.d.ts +8 -8
- package/dist/types/data-structures/base/linear-base.d.ts +3 -3
- package/dist/types/data-structures/binary-tree/avl-tree.d.ts +288 -0
- package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +336 -0
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +618 -18
- package/dist/types/data-structures/binary-tree/bst.d.ts +676 -1
- package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +456 -0
- package/dist/types/data-structures/binary-tree/segment-tree.d.ts +144 -1
- package/dist/types/data-structures/binary-tree/tree-map.d.ts +3307 -399
- package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +3285 -360
- package/dist/types/data-structures/binary-tree/tree-multi-set.d.ts +2674 -325
- package/dist/types/data-structures/binary-tree/tree-set.d.ts +3072 -287
- package/dist/types/data-structures/graph/abstract-graph.d.ts +4 -4
- package/dist/types/data-structures/graph/directed-graph.d.ts +240 -0
- package/dist/types/data-structures/graph/undirected-graph.d.ts +216 -0
- package/dist/types/data-structures/hash/hash-map.d.ts +274 -10
- package/dist/types/data-structures/heap/heap.d.ts +336 -0
- package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +411 -3
- package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +363 -3
- package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +434 -2
- package/dist/types/data-structures/matrix/matrix.d.ts +192 -0
- package/dist/types/data-structures/queue/deque.d.ts +364 -4
- package/dist/types/data-structures/queue/queue.d.ts +288 -0
- package/dist/types/data-structures/stack/stack.d.ts +240 -0
- package/dist/types/data-structures/trie/trie.d.ts +292 -4
- package/dist/types/interfaces/graph.d.ts +1 -1
- package/dist/types/types/common.d.ts +2 -2
- package/dist/types/types/data-structures/binary-tree/bst.d.ts +1 -0
- package/dist/types/types/data-structures/binary-tree/tree-map.d.ts +5 -0
- package/dist/types/types/data-structures/binary-tree/tree-multi-set.d.ts +4 -0
- package/dist/types/types/data-structures/binary-tree/tree-set.d.ts +4 -0
- package/dist/types/types/data-structures/heap/heap.d.ts +1 -0
- package/dist/types/types/data-structures/priority-queue/priority-queue.d.ts +1 -0
- package/dist/types/types/utils/validate-type.d.ts +4 -4
- package/dist/umd/trie-typed.js +320 -50
- package/dist/umd/trie-typed.js.map +1 -1
- package/dist/umd/trie-typed.min.js +1 -1
- package/dist/umd/trie-typed.min.js.map +1 -1
- package/package.json +2 -2
- package/src/common/error.ts +19 -1
- package/src/common/index.ts +1 -1
- package/src/data-structures/base/index.ts +1 -0
- package/src/data-structures/base/iterable-element-base.ts +3 -2
- package/src/data-structures/base/iterable-entry-base.ts +8 -8
- package/src/data-structures/base/linear-base.ts +3 -3
- package/src/data-structures/binary-tree/avl-tree.ts +299 -0
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +341 -5
- package/src/data-structures/binary-tree/binary-tree.ts +606 -6
- package/src/data-structures/binary-tree/bst.ts +946 -7
- package/src/data-structures/binary-tree/red-black-tree.ts +472 -0
- package/src/data-structures/binary-tree/segment-tree.ts +145 -2
- package/src/data-structures/binary-tree/tree-map.ts +3423 -499
- package/src/data-structures/binary-tree/tree-multi-map.ts +3537 -596
- package/src/data-structures/binary-tree/tree-multi-set.ts +2855 -495
- package/src/data-structures/binary-tree/tree-set.ts +3209 -413
- package/src/data-structures/graph/abstract-graph.ts +6 -6
- package/src/data-structures/graph/directed-graph.ts +240 -0
- package/src/data-structures/graph/undirected-graph.ts +216 -0
- package/src/data-structures/hash/hash-map.ts +281 -19
- package/src/data-structures/heap/heap.ts +340 -4
- package/src/data-structures/heap/max-heap.ts +2 -2
- package/src/data-structures/linked-list/doubly-linked-list.ts +411 -3
- package/src/data-structures/linked-list/singly-linked-list.ts +363 -3
- package/src/data-structures/linked-list/skip-linked-list.ts +439 -7
- package/src/data-structures/matrix/matrix.ts +202 -10
- package/src/data-structures/priority-queue/max-priority-queue.ts +2 -2
- package/src/data-structures/queue/deque.ts +365 -5
- package/src/data-structures/queue/queue.ts +288 -0
- package/src/data-structures/stack/stack.ts +240 -0
- package/src/data-structures/trie/trie.ts +295 -7
- package/src/interfaces/graph.ts +1 -1
- package/src/types/common.ts +2 -2
- package/src/types/data-structures/binary-tree/bst.ts +1 -0
- package/src/types/data-structures/binary-tree/tree-map.ts +6 -0
- package/src/types/data-structures/binary-tree/tree-multi-set.ts +5 -0
- package/src/types/data-structures/binary-tree/tree-set.ts +5 -0
- package/src/types/data-structures/heap/heap.ts +1 -0
- package/src/types/data-structures/priority-queue/priority-queue.ts +1 -0
- package/src/types/utils/validate-type.ts +4 -4
|
@@ -5,6 +5,60 @@ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { en
|
|
|
5
5
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
6
6
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
7
7
|
|
|
8
|
+
// src/common/error.ts
|
|
9
|
+
function raise(ErrorClass, message) {
|
|
10
|
+
throw new ErrorClass(message);
|
|
11
|
+
}
|
|
12
|
+
__name(raise, "raise");
|
|
13
|
+
var ERR = {
|
|
14
|
+
// Range / index
|
|
15
|
+
indexOutOfRange: /* @__PURE__ */ __name((index, min, max, ctx) => `${ctx ? ctx + ": " : ""}Index ${index} is out of range [${min}, ${max}].`, "indexOutOfRange"),
|
|
16
|
+
invalidIndex: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Index must be an integer.`, "invalidIndex"),
|
|
17
|
+
// Type / argument
|
|
18
|
+
invalidArgument: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidArgument"),
|
|
19
|
+
comparatorRequired: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Comparator is required for non-number/non-string/non-Date keys.`, "comparatorRequired"),
|
|
20
|
+
invalidKey: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidKey"),
|
|
21
|
+
notAFunction: /* @__PURE__ */ __name((name, ctx) => `${ctx ? ctx + ": " : ""}${name} must be a function.`, "notAFunction"),
|
|
22
|
+
invalidEntry: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Each entry must be a [key, value] tuple.`, "invalidEntry"),
|
|
23
|
+
invalidNaN: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}NaN is not a valid key.`, "invalidNaN"),
|
|
24
|
+
invalidDate: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Invalid Date key.`, "invalidDate"),
|
|
25
|
+
reduceEmpty: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Reduce of empty structure with no initial value.`, "reduceEmpty"),
|
|
26
|
+
callbackReturnType: /* @__PURE__ */ __name((expected, got, ctx) => `${ctx ? ctx + ": " : ""}Callback must return ${expected}; got ${got}.`, "callbackReturnType"),
|
|
27
|
+
// State / operation
|
|
28
|
+
invalidOperation: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidOperation"),
|
|
29
|
+
// Matrix
|
|
30
|
+
matrixDimensionMismatch: /* @__PURE__ */ __name((op) => `Matrix: Dimensions must be compatible for ${op}.`, "matrixDimensionMismatch"),
|
|
31
|
+
matrixSingular: /* @__PURE__ */ __name(() => "Matrix: Singular matrix, inverse does not exist.", "matrixSingular"),
|
|
32
|
+
matrixNotSquare: /* @__PURE__ */ __name(() => "Matrix: Must be square for inversion.", "matrixNotSquare"),
|
|
33
|
+
matrixNotRectangular: /* @__PURE__ */ __name(() => "Matrix: Must be rectangular for transposition.", "matrixNotRectangular"),
|
|
34
|
+
matrixRowMismatch: /* @__PURE__ */ __name((expected, got) => `Matrix: Expected row length ${expected}, but got ${got}.`, "matrixRowMismatch"),
|
|
35
|
+
// Order statistic
|
|
36
|
+
orderStatisticNotEnabled: /* @__PURE__ */ __name((method, ctx) => `${ctx ? ctx + ": " : ""}${method}() requires enableOrderStatistic: true.`, "orderStatisticNotEnabled")
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
// src/common/index.ts
|
|
40
|
+
var DFSOperation = /* @__PURE__ */ ((DFSOperation2) => {
|
|
41
|
+
DFSOperation2[DFSOperation2["VISIT"] = 0] = "VISIT";
|
|
42
|
+
DFSOperation2[DFSOperation2["PROCESS"] = 1] = "PROCESS";
|
|
43
|
+
return DFSOperation2;
|
|
44
|
+
})(DFSOperation || {});
|
|
45
|
+
var _Range = class _Range {
|
|
46
|
+
constructor(low, high, includeLow = true, includeHigh = true) {
|
|
47
|
+
this.low = low;
|
|
48
|
+
this.high = high;
|
|
49
|
+
this.includeLow = includeLow;
|
|
50
|
+
this.includeHigh = includeHigh;
|
|
51
|
+
}
|
|
52
|
+
// Determine whether a key is within the range
|
|
53
|
+
isInRange(key, comparator) {
|
|
54
|
+
const lowCheck = this.includeLow ? comparator(key, this.low) >= 0 : comparator(key, this.low) > 0;
|
|
55
|
+
const highCheck = this.includeHigh ? comparator(key, this.high) <= 0 : comparator(key, this.high) < 0;
|
|
56
|
+
return lowCheck && highCheck;
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
__name(_Range, "Range");
|
|
60
|
+
var Range = _Range;
|
|
61
|
+
|
|
8
62
|
// src/data-structures/base/iterable-element-base.ts
|
|
9
63
|
var _IterableElementBase = class _IterableElementBase {
|
|
10
64
|
/**
|
|
@@ -27,7 +81,7 @@ var _IterableElementBase = class _IterableElementBase {
|
|
|
27
81
|
if (options) {
|
|
28
82
|
const { toElementFn } = options;
|
|
29
83
|
if (typeof toElementFn === "function") this._toElementFn = toElementFn;
|
|
30
|
-
else if (toElementFn)
|
|
84
|
+
else if (toElementFn) raise(TypeError, "toElementFn must be a function type");
|
|
31
85
|
}
|
|
32
86
|
}
|
|
33
87
|
/**
|
|
@@ -183,7 +237,7 @@ var _IterableElementBase = class _IterableElementBase {
|
|
|
183
237
|
acc = initialValue;
|
|
184
238
|
} else {
|
|
185
239
|
const first = iter.next();
|
|
186
|
-
if (first.done)
|
|
240
|
+
if (first.done) raise(TypeError, "Reduce of empty structure with no initial value");
|
|
187
241
|
acc = first.value;
|
|
188
242
|
index = 1;
|
|
189
243
|
}
|
|
@@ -227,54 +281,6 @@ var _IterableElementBase = class _IterableElementBase {
|
|
|
227
281
|
__name(_IterableElementBase, "IterableElementBase");
|
|
228
282
|
var IterableElementBase = _IterableElementBase;
|
|
229
283
|
|
|
230
|
-
// src/common/error.ts
|
|
231
|
-
var ERR = {
|
|
232
|
-
// Range / index
|
|
233
|
-
indexOutOfRange: /* @__PURE__ */ __name((index, min, max, ctx) => `${ctx ? ctx + ": " : ""}Index ${index} is out of range [${min}, ${max}].`, "indexOutOfRange"),
|
|
234
|
-
invalidIndex: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Index must be an integer.`, "invalidIndex"),
|
|
235
|
-
// Type / argument
|
|
236
|
-
invalidArgument: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidArgument"),
|
|
237
|
-
comparatorRequired: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Comparator is required for non-number/non-string/non-Date keys.`, "comparatorRequired"),
|
|
238
|
-
invalidKey: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidKey"),
|
|
239
|
-
notAFunction: /* @__PURE__ */ __name((name, ctx) => `${ctx ? ctx + ": " : ""}${name} must be a function.`, "notAFunction"),
|
|
240
|
-
invalidEntry: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Each entry must be a [key, value] tuple.`, "invalidEntry"),
|
|
241
|
-
invalidNaN: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}NaN is not a valid key.`, "invalidNaN"),
|
|
242
|
-
invalidDate: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Invalid Date key.`, "invalidDate"),
|
|
243
|
-
reduceEmpty: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Reduce of empty structure with no initial value.`, "reduceEmpty"),
|
|
244
|
-
callbackReturnType: /* @__PURE__ */ __name((expected, got, ctx) => `${ctx ? ctx + ": " : ""}Callback must return ${expected}; got ${got}.`, "callbackReturnType"),
|
|
245
|
-
// State / operation
|
|
246
|
-
invalidOperation: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidOperation"),
|
|
247
|
-
// Matrix
|
|
248
|
-
matrixDimensionMismatch: /* @__PURE__ */ __name((op) => `Matrix: Dimensions must be compatible for ${op}.`, "matrixDimensionMismatch"),
|
|
249
|
-
matrixSingular: /* @__PURE__ */ __name(() => "Matrix: Singular matrix, inverse does not exist.", "matrixSingular"),
|
|
250
|
-
matrixNotSquare: /* @__PURE__ */ __name(() => "Matrix: Must be square for inversion.", "matrixNotSquare"),
|
|
251
|
-
matrixNotRectangular: /* @__PURE__ */ __name(() => "Matrix: Must be rectangular for transposition.", "matrixNotRectangular"),
|
|
252
|
-
matrixRowMismatch: /* @__PURE__ */ __name((expected, got) => `Matrix: Expected row length ${expected}, but got ${got}.`, "matrixRowMismatch")
|
|
253
|
-
};
|
|
254
|
-
|
|
255
|
-
// src/common/index.ts
|
|
256
|
-
var DFSOperation = /* @__PURE__ */ ((DFSOperation2) => {
|
|
257
|
-
DFSOperation2[DFSOperation2["VISIT"] = 0] = "VISIT";
|
|
258
|
-
DFSOperation2[DFSOperation2["PROCESS"] = 1] = "PROCESS";
|
|
259
|
-
return DFSOperation2;
|
|
260
|
-
})(DFSOperation || {});
|
|
261
|
-
var _Range = class _Range {
|
|
262
|
-
constructor(low, high, includeLow = true, includeHigh = true) {
|
|
263
|
-
this.low = low;
|
|
264
|
-
this.high = high;
|
|
265
|
-
this.includeLow = includeLow;
|
|
266
|
-
this.includeHigh = includeHigh;
|
|
267
|
-
}
|
|
268
|
-
// Determine whether a key is within the range
|
|
269
|
-
isInRange(key, comparator) {
|
|
270
|
-
const lowCheck = this.includeLow ? comparator(key, this.low) >= 0 : comparator(key, this.low) > 0;
|
|
271
|
-
const highCheck = this.includeHigh ? comparator(key, this.high) <= 0 : comparator(key, this.high) < 0;
|
|
272
|
-
return lowCheck && highCheck;
|
|
273
|
-
}
|
|
274
|
-
};
|
|
275
|
-
__name(_Range, "Range");
|
|
276
|
-
var Range = _Range;
|
|
277
|
-
|
|
278
284
|
// src/data-structures/trie/trie.ts
|
|
279
285
|
var _TrieNode = class _TrieNode {
|
|
280
286
|
/**
|
|
@@ -413,6 +419,30 @@ var _Trie = class _Trie extends IterableElementBase {
|
|
|
413
419
|
|
|
414
420
|
|
|
415
421
|
|
|
422
|
+
|
|
423
|
+
|
|
424
|
+
|
|
425
|
+
|
|
426
|
+
|
|
427
|
+
|
|
428
|
+
|
|
429
|
+
|
|
430
|
+
|
|
431
|
+
|
|
432
|
+
|
|
433
|
+
|
|
434
|
+
|
|
435
|
+
|
|
436
|
+
|
|
437
|
+
|
|
438
|
+
|
|
439
|
+
|
|
440
|
+
|
|
441
|
+
|
|
442
|
+
|
|
443
|
+
|
|
444
|
+
|
|
445
|
+
|
|
416
446
|
* @example
|
|
417
447
|
* // basic Trie creation and add words
|
|
418
448
|
* // Create a simple Trie with initial words
|
|
@@ -461,6 +491,30 @@ var _Trie = class _Trie extends IterableElementBase {
|
|
|
461
491
|
|
|
462
492
|
|
|
463
493
|
|
|
494
|
+
|
|
495
|
+
|
|
496
|
+
|
|
497
|
+
|
|
498
|
+
|
|
499
|
+
|
|
500
|
+
|
|
501
|
+
|
|
502
|
+
|
|
503
|
+
|
|
504
|
+
|
|
505
|
+
|
|
506
|
+
|
|
507
|
+
|
|
508
|
+
|
|
509
|
+
|
|
510
|
+
|
|
511
|
+
|
|
512
|
+
|
|
513
|
+
|
|
514
|
+
|
|
515
|
+
|
|
516
|
+
|
|
517
|
+
|
|
464
518
|
* @example
|
|
465
519
|
* // Add multiple words
|
|
466
520
|
* const trie = new Trie();
|
|
@@ -496,6 +550,30 @@ var _Trie = class _Trie extends IterableElementBase {
|
|
|
496
550
|
|
|
497
551
|
|
|
498
552
|
|
|
553
|
+
|
|
554
|
+
|
|
555
|
+
|
|
556
|
+
|
|
557
|
+
|
|
558
|
+
|
|
559
|
+
|
|
560
|
+
|
|
561
|
+
|
|
562
|
+
|
|
563
|
+
|
|
564
|
+
|
|
565
|
+
|
|
566
|
+
|
|
567
|
+
|
|
568
|
+
|
|
569
|
+
|
|
570
|
+
|
|
571
|
+
|
|
572
|
+
|
|
573
|
+
|
|
574
|
+
|
|
575
|
+
|
|
576
|
+
|
|
499
577
|
* @example
|
|
500
578
|
* // Check if a word exists
|
|
501
579
|
* const dict = new Trie(['apple', 'app', 'application']);
|
|
@@ -526,6 +604,30 @@ var _Trie = class _Trie extends IterableElementBase {
|
|
|
526
604
|
|
|
527
605
|
|
|
528
606
|
|
|
607
|
+
|
|
608
|
+
|
|
609
|
+
|
|
610
|
+
|
|
611
|
+
|
|
612
|
+
|
|
613
|
+
|
|
614
|
+
|
|
615
|
+
|
|
616
|
+
|
|
617
|
+
|
|
618
|
+
|
|
619
|
+
|
|
620
|
+
|
|
621
|
+
|
|
622
|
+
|
|
623
|
+
|
|
624
|
+
|
|
625
|
+
|
|
626
|
+
|
|
627
|
+
|
|
628
|
+
|
|
629
|
+
|
|
630
|
+
|
|
529
631
|
* @example
|
|
530
632
|
* // Check if empty
|
|
531
633
|
* const trie = new Trie();
|
|
@@ -548,6 +650,30 @@ var _Trie = class _Trie extends IterableElementBase {
|
|
|
548
650
|
|
|
549
651
|
|
|
550
652
|
|
|
653
|
+
|
|
654
|
+
|
|
655
|
+
|
|
656
|
+
|
|
657
|
+
|
|
658
|
+
|
|
659
|
+
|
|
660
|
+
|
|
661
|
+
|
|
662
|
+
|
|
663
|
+
|
|
664
|
+
|
|
665
|
+
|
|
666
|
+
|
|
667
|
+
|
|
668
|
+
|
|
669
|
+
|
|
670
|
+
|
|
671
|
+
|
|
672
|
+
|
|
673
|
+
|
|
674
|
+
|
|
675
|
+
|
|
676
|
+
|
|
551
677
|
* @example
|
|
552
678
|
* // Remove all words
|
|
553
679
|
* const trie = new Trie(['a', 'b', 'c']);
|
|
@@ -574,6 +700,30 @@ var _Trie = class _Trie extends IterableElementBase {
|
|
|
574
700
|
|
|
575
701
|
|
|
576
702
|
|
|
703
|
+
|
|
704
|
+
|
|
705
|
+
|
|
706
|
+
|
|
707
|
+
|
|
708
|
+
|
|
709
|
+
|
|
710
|
+
|
|
711
|
+
|
|
712
|
+
|
|
713
|
+
|
|
714
|
+
|
|
715
|
+
|
|
716
|
+
|
|
717
|
+
|
|
718
|
+
|
|
719
|
+
|
|
720
|
+
|
|
721
|
+
|
|
722
|
+
|
|
723
|
+
|
|
724
|
+
|
|
725
|
+
|
|
726
|
+
|
|
577
727
|
* @example
|
|
578
728
|
* // Trie delete and iteration
|
|
579
729
|
* const trie = new Trie(['car', 'card', 'care', 'careful', 'can', 'cat']);
|
|
@@ -682,6 +832,30 @@ var _Trie = class _Trie extends IterableElementBase {
|
|
|
682
832
|
|
|
683
833
|
|
|
684
834
|
|
|
835
|
+
|
|
836
|
+
|
|
837
|
+
|
|
838
|
+
|
|
839
|
+
|
|
840
|
+
|
|
841
|
+
|
|
842
|
+
|
|
843
|
+
|
|
844
|
+
|
|
845
|
+
|
|
846
|
+
|
|
847
|
+
|
|
848
|
+
|
|
849
|
+
|
|
850
|
+
|
|
851
|
+
|
|
852
|
+
|
|
853
|
+
|
|
854
|
+
|
|
855
|
+
|
|
856
|
+
|
|
857
|
+
|
|
858
|
+
|
|
685
859
|
* @example
|
|
686
860
|
* // Check if a prefix exists
|
|
687
861
|
* const trie = new Trie(['hello', 'help', 'world']);
|
|
@@ -734,6 +908,30 @@ var _Trie = class _Trie extends IterableElementBase {
|
|
|
734
908
|
|
|
735
909
|
|
|
736
910
|
|
|
911
|
+
|
|
912
|
+
|
|
913
|
+
|
|
914
|
+
|
|
915
|
+
|
|
916
|
+
|
|
917
|
+
|
|
918
|
+
|
|
919
|
+
|
|
920
|
+
|
|
921
|
+
|
|
922
|
+
|
|
923
|
+
|
|
924
|
+
|
|
925
|
+
|
|
926
|
+
|
|
927
|
+
|
|
928
|
+
|
|
929
|
+
|
|
930
|
+
|
|
931
|
+
|
|
932
|
+
|
|
933
|
+
|
|
934
|
+
|
|
737
935
|
* @example
|
|
738
936
|
* // Find shared prefix
|
|
739
937
|
* const trie = new Trie(['flower', 'flow', 'flight']);
|
|
@@ -769,6 +967,30 @@ var _Trie = class _Trie extends IterableElementBase {
|
|
|
769
967
|
|
|
770
968
|
|
|
771
969
|
|
|
970
|
+
|
|
971
|
+
|
|
972
|
+
|
|
973
|
+
|
|
974
|
+
|
|
975
|
+
|
|
976
|
+
|
|
977
|
+
|
|
978
|
+
|
|
979
|
+
|
|
980
|
+
|
|
981
|
+
|
|
982
|
+
|
|
983
|
+
|
|
984
|
+
|
|
985
|
+
|
|
986
|
+
|
|
987
|
+
|
|
988
|
+
|
|
989
|
+
|
|
990
|
+
|
|
991
|
+
|
|
992
|
+
|
|
993
|
+
|
|
772
994
|
* @example
|
|
773
995
|
* // Trie getWords and prefix search
|
|
774
996
|
* const trie = new Trie(['apple', 'app', 'apply', 'application', 'apricot']);
|
|
@@ -822,6 +1044,30 @@ var _Trie = class _Trie extends IterableElementBase {
|
|
|
822
1044
|
|
|
823
1045
|
|
|
824
1046
|
|
|
1047
|
+
|
|
1048
|
+
|
|
1049
|
+
|
|
1050
|
+
|
|
1051
|
+
|
|
1052
|
+
|
|
1053
|
+
|
|
1054
|
+
|
|
1055
|
+
|
|
1056
|
+
|
|
1057
|
+
|
|
1058
|
+
|
|
1059
|
+
|
|
1060
|
+
|
|
1061
|
+
|
|
1062
|
+
|
|
1063
|
+
|
|
1064
|
+
|
|
1065
|
+
|
|
1066
|
+
|
|
1067
|
+
|
|
1068
|
+
|
|
1069
|
+
|
|
1070
|
+
|
|
825
1071
|
* @example
|
|
826
1072
|
* // Create independent copy
|
|
827
1073
|
* const trie = new Trie(['hello', 'world']);
|
|
@@ -848,6 +1094,30 @@ var _Trie = class _Trie extends IterableElementBase {
|
|
|
848
1094
|
|
|
849
1095
|
|
|
850
1096
|
|
|
1097
|
+
|
|
1098
|
+
|
|
1099
|
+
|
|
1100
|
+
|
|
1101
|
+
|
|
1102
|
+
|
|
1103
|
+
|
|
1104
|
+
|
|
1105
|
+
|
|
1106
|
+
|
|
1107
|
+
|
|
1108
|
+
|
|
1109
|
+
|
|
1110
|
+
|
|
1111
|
+
|
|
1112
|
+
|
|
1113
|
+
|
|
1114
|
+
|
|
1115
|
+
|
|
1116
|
+
|
|
1117
|
+
|
|
1118
|
+
|
|
1119
|
+
|
|
1120
|
+
|
|
851
1121
|
* @example
|
|
852
1122
|
* // Filter words
|
|
853
1123
|
* const trie = new Trie(['cat', 'car', 'dog', 'card']);
|
|
@@ -871,7 +1141,7 @@ var _Trie = class _Trie extends IterableElementBase {
|
|
|
871
1141
|
for (const x of this) {
|
|
872
1142
|
const v = thisArg === void 0 ? callback(x, i++, this) : callback.call(thisArg, x, i++, this);
|
|
873
1143
|
if (typeof v !== "string") {
|
|
874
|
-
|
|
1144
|
+
raise(TypeError, ERR.callbackReturnType("string", typeof v, "Trie.map"));
|
|
875
1145
|
}
|
|
876
1146
|
newTrie.add(v);
|
|
877
1147
|
}
|
|
@@ -974,5 +1244,6 @@ exports.ERR = ERR;
|
|
|
974
1244
|
exports.Range = Range;
|
|
975
1245
|
exports.Trie = Trie;
|
|
976
1246
|
exports.TrieNode = TrieNode;
|
|
1247
|
+
exports.raise = raise;
|
|
977
1248
|
//# sourceMappingURL=index.cjs.map
|
|
978
1249
|
//# sourceMappingURL=index.cjs.map
|