data-structure-typed 1.19.2 → 1.19.4

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 (155) hide show
  1. package/dist/data-structures/binary-tree/aa-tree.js +2 -5
  2. package/dist/data-structures/binary-tree/abstract-binary-tree.js +361 -488
  3. package/dist/data-structures/binary-tree/avl-tree.js +46 -90
  4. package/dist/data-structures/binary-tree/b-tree.js +2 -5
  5. package/dist/data-structures/binary-tree/binary-indexed-tree.js +17 -22
  6. package/dist/data-structures/binary-tree/binary-tree.js +9 -31
  7. package/dist/data-structures/binary-tree/bst.js +96 -139
  8. package/dist/data-structures/binary-tree/rb-tree.js +32 -56
  9. package/dist/data-structures/binary-tree/segment-tree.js +78 -120
  10. package/dist/data-structures/binary-tree/splay-tree.js +2 -5
  11. package/dist/data-structures/binary-tree/tree-multiset.js +176 -253
  12. package/dist/data-structures/binary-tree/two-three-tree.js +2 -5
  13. package/dist/data-structures/graph/abstract-graph.js +340 -574
  14. package/dist/data-structures/graph/directed-graph.js +146 -276
  15. package/dist/data-structures/graph/undirected-graph.js +87 -176
  16. package/dist/data-structures/hash/coordinate-map.js +23 -45
  17. package/dist/data-structures/hash/coordinate-set.js +20 -42
  18. package/dist/data-structures/hash/hash-table.js +2 -5
  19. package/dist/data-structures/hash/pair.js +2 -5
  20. package/dist/data-structures/hash/tree-map.js +2 -5
  21. package/dist/data-structures/hash/tree-set.js +2 -5
  22. package/dist/data-structures/heap/heap.js +53 -77
  23. package/dist/data-structures/heap/max-heap.js +8 -26
  24. package/dist/data-structures/heap/min-heap.js +8 -26
  25. package/dist/data-structures/linked-list/doubly-linked-list.js +132 -197
  26. package/dist/data-structures/linked-list/singly-linked-list.js +112 -173
  27. package/dist/data-structures/linked-list/skip-linked-list.js +2 -5
  28. package/dist/data-structures/matrix/matrix.js +7 -8
  29. package/dist/data-structures/matrix/matrix2d.js +76 -93
  30. package/dist/data-structures/matrix/navigator.js +18 -37
  31. package/dist/data-structures/matrix/vector2d.js +80 -101
  32. package/dist/data-structures/priority-queue/max-priority-queue.js +11 -39
  33. package/dist/data-structures/priority-queue/min-priority-queue.js +11 -39
  34. package/dist/data-structures/priority-queue/priority-queue.js +93 -139
  35. package/dist/data-structures/queue/deque.js +82 -128
  36. package/dist/data-structures/queue/queue.js +24 -25
  37. package/dist/data-structures/stack/stack.js +21 -22
  38. package/dist/data-structures/tree/tree.js +32 -45
  39. package/dist/data-structures/trie/trie.js +93 -200
  40. package/dist/utils/utils.js +22 -107
  41. package/dist/utils/validate-type.js +2 -2
  42. package/package.json +1 -1
  43. package/src/assets/complexities-diff.jpg +0 -0
  44. package/src/assets/data-structure-complexities.jpg +0 -0
  45. package/src/assets/logo.png +0 -0
  46. package/src/assets/overview-diagram-of-data-structures.png +0 -0
  47. package/src/data-structures/binary-tree/aa-tree.ts +3 -0
  48. package/src/data-structures/binary-tree/abstract-binary-tree.ts +1528 -0
  49. package/src/data-structures/binary-tree/avl-tree.ts +297 -0
  50. package/src/data-structures/binary-tree/b-tree.ts +3 -0
  51. package/src/data-structures/binary-tree/binary-indexed-tree.ts +78 -0
  52. package/src/data-structures/binary-tree/binary-tree.ts +40 -0
  53. package/src/data-structures/binary-tree/bst.ts +435 -0
  54. package/src/data-structures/binary-tree/diagrams/avl-tree-inserting.gif +0 -0
  55. package/src/data-structures/binary-tree/diagrams/bst-rotation.gif +0 -0
  56. package/src/data-structures/binary-tree/diagrams/segment-tree.png +0 -0
  57. package/src/data-structures/binary-tree/index.ts +12 -0
  58. package/src/data-structures/binary-tree/rb-tree.ts +102 -0
  59. package/src/data-structures/binary-tree/segment-tree.ts +243 -0
  60. package/src/data-structures/binary-tree/splay-tree.ts +3 -0
  61. package/src/data-structures/binary-tree/tree-multiset.ts +694 -0
  62. package/src/data-structures/binary-tree/two-three-tree.ts +3 -0
  63. package/src/data-structures/diagrams/README.md +5 -0
  64. package/src/data-structures/graph/abstract-graph.ts +1032 -0
  65. package/src/data-structures/graph/diagrams/adjacency-list-pros-cons.jpg +0 -0
  66. package/src/data-structures/graph/diagrams/adjacency-list.jpg +0 -0
  67. package/src/data-structures/graph/diagrams/adjacency-matrix-pros-cons.jpg +0 -0
  68. package/src/data-structures/graph/diagrams/adjacency-matrix.jpg +0 -0
  69. package/src/data-structures/graph/diagrams/dfs-can-do.jpg +0 -0
  70. package/src/data-structures/graph/diagrams/edge-list-pros-cons.jpg +0 -0
  71. package/src/data-structures/graph/diagrams/edge-list.jpg +0 -0
  72. package/src/data-structures/graph/diagrams/max-flow.jpg +0 -0
  73. package/src/data-structures/graph/diagrams/mst.jpg +0 -0
  74. package/src/data-structures/graph/diagrams/tarjan-articulation-point-bridge.png +0 -0
  75. package/src/data-structures/graph/diagrams/tarjan-complicate-simple.png +0 -0
  76. package/src/data-structures/graph/diagrams/tarjan-strongly-connected-component.png +0 -0
  77. package/src/data-structures/graph/diagrams/tarjan.mp4 +0 -0
  78. package/src/data-structures/graph/diagrams/tarjan.webp +0 -0
  79. package/src/data-structures/graph/directed-graph.ts +472 -0
  80. package/src/data-structures/graph/index.ts +3 -0
  81. package/src/data-structures/graph/undirected-graph.ts +270 -0
  82. package/src/data-structures/hash/coordinate-map.ts +67 -0
  83. package/src/data-structures/hash/coordinate-set.ts +56 -0
  84. package/src/data-structures/hash/hash-table.ts +3 -0
  85. package/src/data-structures/hash/index.ts +6 -0
  86. package/src/data-structures/hash/pair.ts +3 -0
  87. package/src/data-structures/hash/tree-map.ts +3 -0
  88. package/src/data-structures/hash/tree-set.ts +3 -0
  89. package/src/data-structures/heap/heap.ts +183 -0
  90. package/src/data-structures/heap/index.ts +3 -0
  91. package/src/data-structures/heap/max-heap.ts +31 -0
  92. package/src/data-structures/heap/min-heap.ts +34 -0
  93. package/src/data-structures/index.ts +15 -0
  94. package/src/data-structures/interfaces/abstract-binary-tree.ts +231 -0
  95. package/src/data-structures/interfaces/abstract-graph.ts +40 -0
  96. package/src/data-structures/interfaces/avl-tree.ts +28 -0
  97. package/src/data-structures/interfaces/binary-tree.ts +8 -0
  98. package/src/data-structures/interfaces/bst.ts +32 -0
  99. package/src/data-structures/interfaces/directed-graph.ts +20 -0
  100. package/src/data-structures/interfaces/doubly-linked-list.ts +1 -0
  101. package/src/data-structures/interfaces/heap.ts +1 -0
  102. package/src/data-structures/interfaces/index.ts +15 -0
  103. package/src/data-structures/interfaces/navigator.ts +1 -0
  104. package/src/data-structures/interfaces/priority-queue.ts +1 -0
  105. package/src/data-structures/interfaces/rb-tree.ts +11 -0
  106. package/src/data-structures/interfaces/segment-tree.ts +1 -0
  107. package/src/data-structures/interfaces/singly-linked-list.ts +1 -0
  108. package/src/data-structures/interfaces/tree-multiset.ts +12 -0
  109. package/src/data-structures/interfaces/undirected-graph.ts +6 -0
  110. package/src/data-structures/linked-list/doubly-linked-list.ts +573 -0
  111. package/src/data-structures/linked-list/index.ts +3 -0
  112. package/src/data-structures/linked-list/singly-linked-list.ts +490 -0
  113. package/src/data-structures/linked-list/skip-linked-list.ts +3 -0
  114. package/src/data-structures/matrix/index.ts +4 -0
  115. package/src/data-structures/matrix/matrix.ts +27 -0
  116. package/src/data-structures/matrix/matrix2d.ts +208 -0
  117. package/src/data-structures/matrix/navigator.ts +122 -0
  118. package/src/data-structures/matrix/vector2d.ts +316 -0
  119. package/src/data-structures/priority-queue/index.ts +3 -0
  120. package/src/data-structures/priority-queue/max-priority-queue.ts +49 -0
  121. package/src/data-structures/priority-queue/min-priority-queue.ts +50 -0
  122. package/src/data-structures/priority-queue/priority-queue.ts +354 -0
  123. package/src/data-structures/queue/deque.ts +251 -0
  124. package/src/data-structures/queue/index.ts +2 -0
  125. package/src/data-structures/queue/queue.ts +120 -0
  126. package/src/data-structures/stack/index.ts +1 -0
  127. package/src/data-structures/stack/stack.ts +98 -0
  128. package/src/data-structures/tree/index.ts +1 -0
  129. package/src/data-structures/tree/tree.ts +69 -0
  130. package/src/data-structures/trie/index.ts +1 -0
  131. package/src/data-structures/trie/trie.ts +227 -0
  132. package/src/data-structures/types/abstract-binary-tree.ts +42 -0
  133. package/src/data-structures/types/abstract-graph.ts +5 -0
  134. package/src/data-structures/types/avl-tree.ts +5 -0
  135. package/src/data-structures/types/binary-tree.ts +9 -0
  136. package/src/data-structures/types/bst.ts +12 -0
  137. package/src/data-structures/types/directed-graph.ts +8 -0
  138. package/src/data-structures/types/doubly-linked-list.ts +1 -0
  139. package/src/data-structures/types/heap.ts +5 -0
  140. package/src/data-structures/types/helpers.ts +1 -0
  141. package/src/data-structures/types/index.ts +15 -0
  142. package/src/data-structures/types/navigator.ts +13 -0
  143. package/src/data-structures/types/priority-queue.ts +9 -0
  144. package/src/data-structures/types/rb-tree.ts +8 -0
  145. package/src/data-structures/types/segment-tree.ts +1 -0
  146. package/src/data-structures/types/singly-linked-list.ts +1 -0
  147. package/src/data-structures/types/tree-multiset.ts +8 -0
  148. package/src/index.ts +2 -0
  149. package/src/utils/index.ts +3 -0
  150. package/src/utils/types/index.ts +2 -0
  151. package/src/utils/types/utils.ts +6 -0
  152. package/src/utils/types/validate-type.ts +25 -0
  153. package/src/utils/utils.ts +78 -0
  154. package/src/utils/validate-type.ts +69 -0
  155. package/tsconfig.json +1 -1
@@ -1,43 +1,31 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.TreeNode = void 0;
4
- var TreeNode = /** @class */ (function () {
5
- function TreeNode(id, value, children) {
4
+ class TreeNode {
5
+ constructor(id, value, children) {
6
6
  this._id = id;
7
7
  this._value = value || undefined;
8
8
  this._children = children || [];
9
9
  }
10
- Object.defineProperty(TreeNode.prototype, "id", {
11
- get: function () {
12
- return this._id;
13
- },
14
- set: function (value) {
15
- this._id = value;
16
- },
17
- enumerable: false,
18
- configurable: true
19
- });
20
- Object.defineProperty(TreeNode.prototype, "value", {
21
- get: function () {
22
- return this._value;
23
- },
24
- set: function (value) {
25
- this._value = value;
26
- },
27
- enumerable: false,
28
- configurable: true
29
- });
30
- Object.defineProperty(TreeNode.prototype, "children", {
31
- get: function () {
32
- return this._children;
33
- },
34
- set: function (value) {
35
- this._children = value;
36
- },
37
- enumerable: false,
38
- configurable: true
39
- });
40
- TreeNode.prototype.addChildren = function (children) {
10
+ get id() {
11
+ return this._id;
12
+ }
13
+ set id(value) {
14
+ this._id = value;
15
+ }
16
+ get value() {
17
+ return this._value;
18
+ }
19
+ set value(value) {
20
+ this._value = value;
21
+ }
22
+ get children() {
23
+ return this._children;
24
+ }
25
+ set children(value) {
26
+ this._children = value;
27
+ }
28
+ addChildren(children) {
41
29
  if (!this.children) {
42
30
  this.children = [];
43
31
  }
@@ -47,27 +35,26 @@ var TreeNode = /** @class */ (function () {
47
35
  else {
48
36
  this.children = this.children.concat(children);
49
37
  }
50
- };
51
- TreeNode.prototype.getHeight = function () {
38
+ }
39
+ getHeight() {
52
40
  // eslint-disable-next-line @typescript-eslint/no-this-alias
53
- var beginRoot = this;
54
- var maxDepth = 1;
41
+ const beginRoot = this;
42
+ let maxDepth = 1;
55
43
  if (beginRoot) {
56
- var bfs_1 = function (node, level) {
44
+ const bfs = (node, level) => {
57
45
  if (level > maxDepth) {
58
46
  maxDepth = level;
59
47
  }
60
- var children = node.children;
48
+ const { children } = node;
61
49
  if (children) {
62
- for (var i = 0, len = children.length; i < len; i++) {
63
- bfs_1(children[i], level + 1);
50
+ for (let i = 0, len = children.length; i < len; i++) {
51
+ bfs(children[i], level + 1);
64
52
  }
65
53
  }
66
54
  };
67
- bfs_1(beginRoot, 1);
55
+ bfs(beginRoot, 1);
68
56
  }
69
57
  return maxDepth;
70
- };
71
- return TreeNode;
72
- }());
58
+ }
59
+ }
73
60
  exports.TreeNode = TreeNode;
@@ -1,15 +1,4 @@
1
1
  "use strict";
2
- var __values = (this && this.__values) || function(o) {
3
- var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
4
- if (m) return m.call(o);
5
- if (o && typeof o.length === "number") return {
6
- next: function () {
7
- if (o && i >= o.length) o = void 0;
8
- return { value: o && o[i++], done: !o };
9
- }
10
- };
11
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
12
- };
13
2
  Object.defineProperty(exports, "__esModule", { value: true });
14
3
  exports.Trie = exports.TrieNode = void 0;
15
4
  /**
@@ -19,125 +8,75 @@ exports.Trie = exports.TrieNode = void 0;
19
8
  * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
20
9
  * @license MIT License
21
10
  */
22
- var TrieNode = /** @class */ (function () {
23
- function TrieNode(v) {
11
+ class TrieNode {
12
+ constructor(v) {
24
13
  this._val = v;
25
14
  this._isEnd = false;
26
15
  this._children = new Map();
27
16
  }
28
- Object.defineProperty(TrieNode.prototype, "val", {
29
- get: function () {
30
- return this._val;
31
- },
32
- set: function (v) {
33
- this._val = v;
34
- },
35
- enumerable: false,
36
- configurable: true
37
- });
38
- Object.defineProperty(TrieNode.prototype, "children", {
39
- get: function () {
40
- return this._children;
41
- },
42
- set: function (v) {
43
- this._children = v;
44
- },
45
- enumerable: false,
46
- configurable: true
47
- });
48
- Object.defineProperty(TrieNode.prototype, "isEnd", {
49
- get: function () {
50
- return this._isEnd;
51
- },
52
- set: function (v) {
53
- this._isEnd = v;
54
- },
55
- enumerable: false,
56
- configurable: true
57
- });
58
- return TrieNode;
59
- }());
17
+ get val() {
18
+ return this._val;
19
+ }
20
+ set val(v) {
21
+ this._val = v;
22
+ }
23
+ get children() {
24
+ return this._children;
25
+ }
26
+ set children(v) {
27
+ this._children = v;
28
+ }
29
+ get isEnd() {
30
+ return this._isEnd;
31
+ }
32
+ set isEnd(v) {
33
+ this._isEnd = v;
34
+ }
35
+ }
60
36
  exports.TrieNode = TrieNode;
61
- var Trie = /** @class */ (function () {
62
- function Trie(words) {
63
- var e_1, _a;
37
+ class Trie {
38
+ constructor(words) {
64
39
  this._root = new TrieNode('');
65
40
  if (words) {
66
- try {
67
- for (var words_1 = __values(words), words_1_1 = words_1.next(); !words_1_1.done; words_1_1 = words_1.next()) {
68
- var i = words_1_1.value;
69
- this.add(i);
70
- }
71
- }
72
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
73
- finally {
74
- try {
75
- if (words_1_1 && !words_1_1.done && (_a = words_1.return)) _a.call(words_1);
76
- }
77
- finally { if (e_1) throw e_1.error; }
41
+ for (const i of words) {
42
+ this.add(i);
78
43
  }
79
44
  }
80
45
  }
81
- Object.defineProperty(Trie.prototype, "root", {
82
- get: function () {
83
- return this._root;
84
- },
85
- set: function (v) {
86
- this._root = v;
87
- },
88
- enumerable: false,
89
- configurable: true
90
- });
91
- Trie.prototype.add = function (word) {
92
- var e_2, _a;
93
- var cur = this._root;
94
- try {
95
- for (var word_1 = __values(word), word_1_1 = word_1.next(); !word_1_1.done; word_1_1 = word_1.next()) {
96
- var c = word_1_1.value;
97
- var nodeC = cur.children.get(c);
98
- if (!nodeC) {
99
- nodeC = new TrieNode(c);
100
- cur.children.set(c, nodeC);
101
- }
102
- cur = nodeC;
103
- }
104
- }
105
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
106
- finally {
107
- try {
108
- if (word_1_1 && !word_1_1.done && (_a = word_1.return)) _a.call(word_1);
109
- }
110
- finally { if (e_2) throw e_2.error; }
46
+ get root() {
47
+ return this._root;
48
+ }
49
+ set root(v) {
50
+ this._root = v;
51
+ }
52
+ add(word) {
53
+ let cur = this._root;
54
+ for (const c of word) {
55
+ let nodeC = cur.children.get(c);
56
+ if (!nodeC) {
57
+ nodeC = new TrieNode(c);
58
+ cur.children.set(c, nodeC);
59
+ }
60
+ cur = nodeC;
111
61
  }
112
62
  cur.isEnd = true;
113
63
  return true;
114
- };
115
- Trie.prototype.has = function (input) {
116
- var e_3, _a;
117
- var cur = this._root;
118
- try {
119
- for (var input_1 = __values(input), input_1_1 = input_1.next(); !input_1_1.done; input_1_1 = input_1.next()) {
120
- var c = input_1_1.value;
121
- var nodeC = cur.children.get(c);
122
- if (!nodeC)
123
- return false;
124
- cur = nodeC;
125
- }
126
- }
127
- catch (e_3_1) { e_3 = { error: e_3_1 }; }
128
- finally {
129
- try {
130
- if (input_1_1 && !input_1_1.done && (_a = input_1.return)) _a.call(input_1);
131
- }
132
- finally { if (e_3) throw e_3.error; }
64
+ }
65
+ has(input) {
66
+ let cur = this._root;
67
+ for (const c of input) {
68
+ const nodeC = cur.children.get(c);
69
+ if (!nodeC)
70
+ return false;
71
+ cur = nodeC;
133
72
  }
134
73
  return cur.isEnd;
135
- };
136
- Trie.prototype.remove = function (word) {
137
- var isDeleted = false;
138
- var dfs = function (cur, i) {
139
- var char = word[i];
140
- var child = cur.children.get(char);
74
+ }
75
+ remove(word) {
76
+ let isDeleted = false;
77
+ const dfs = (cur, i) => {
78
+ const char = word[i];
79
+ const child = cur.children.get(char);
141
80
  if (child) {
142
81
  if (i === word.length - 1) {
143
82
  if (child.isEnd) {
@@ -152,7 +91,7 @@ var Trie = /** @class */ (function () {
152
91
  }
153
92
  return false;
154
93
  }
155
- var res = dfs(child, i + 1);
94
+ const res = dfs(child, i + 1);
156
95
  if (res && !cur.isEnd && child.children.size === 0) {
157
96
  cur.children.delete(char);
158
97
  return true;
@@ -163,69 +102,47 @@ var Trie = /** @class */ (function () {
163
102
  };
164
103
  dfs(this.root, 0);
165
104
  return isDeleted;
166
- };
105
+ }
167
106
  // --- start additional methods ---
168
107
  /**
169
108
  * The function checks if a given input string has an absolute prefix in a tree data structure.Only can present as a prefix, not a word
170
109
  * @param {string} input - The input parameter is a string that represents the input value for the function.
171
110
  * @returns a boolean value.
172
111
  */
173
- Trie.prototype.isAbsPrefix = function (input) {
174
- var e_4, _a;
175
- var cur = this._root;
176
- try {
177
- for (var input_2 = __values(input), input_2_1 = input_2.next(); !input_2_1.done; input_2_1 = input_2.next()) {
178
- var c = input_2_1.value;
179
- var nodeC = cur.children.get(c);
180
- if (!nodeC)
181
- return false;
182
- cur = nodeC;
183
- }
184
- }
185
- catch (e_4_1) { e_4 = { error: e_4_1 }; }
186
- finally {
187
- try {
188
- if (input_2_1 && !input_2_1.done && (_a = input_2.return)) _a.call(input_2);
189
- }
190
- finally { if (e_4) throw e_4.error; }
112
+ isAbsPrefix(input) {
113
+ let cur = this._root;
114
+ for (const c of input) {
115
+ const nodeC = cur.children.get(c);
116
+ if (!nodeC)
117
+ return false;
118
+ cur = nodeC;
191
119
  }
192
120
  return !cur.isEnd;
193
- };
121
+ }
194
122
  /**
195
123
  * The function checks if a given input string is a prefix of any existing string in a tree structure.Can present as a abs prefix or word
196
124
  * @param {string} input - The input parameter is a string that represents the prefix we want to check.
197
125
  * @returns a boolean value.
198
126
  */
199
- Trie.prototype.isPrefix = function (input) {
200
- var e_5, _a;
201
- var cur = this._root;
202
- try {
203
- for (var input_3 = __values(input), input_3_1 = input_3.next(); !input_3_1.done; input_3_1 = input_3.next()) {
204
- var c = input_3_1.value;
205
- var nodeC = cur.children.get(c);
206
- if (!nodeC)
207
- return false;
208
- cur = nodeC;
209
- }
210
- }
211
- catch (e_5_1) { e_5 = { error: e_5_1 }; }
212
- finally {
213
- try {
214
- if (input_3_1 && !input_3_1.done && (_a = input_3.return)) _a.call(input_3);
215
- }
216
- finally { if (e_5) throw e_5.error; }
127
+ isPrefix(input) {
128
+ let cur = this._root;
129
+ for (const c of input) {
130
+ const nodeC = cur.children.get(c);
131
+ if (!nodeC)
132
+ return false;
133
+ cur = nodeC;
217
134
  }
218
135
  return true;
219
- };
136
+ }
220
137
  /**
221
138
  * The function checks if the input string is a common prefix in a Trie data structure.Check if the input string is the common prefix of all the words
222
139
  * @param {string} input - The input parameter is a string that represents the common prefix that we want to check for
223
140
  * in the Trie data structure.
224
141
  * @returns a boolean value indicating whether the input string is a common prefix in the Trie data structure.
225
142
  */
226
- Trie.prototype.isCommonPrefix = function (input) {
227
- var commonPre = '';
228
- var dfs = function (cur) {
143
+ isCommonPrefix(input) {
144
+ let commonPre = '';
145
+ const dfs = (cur) => {
229
146
  commonPre += cur.val;
230
147
  if (commonPre === input)
231
148
  return;
@@ -238,16 +155,16 @@ var Trie = /** @class */ (function () {
238
155
  };
239
156
  dfs(this._root);
240
157
  return commonPre === input;
241
- };
158
+ }
242
159
  /**
243
160
  * The function `getLongestCommonPrefix` returns the longest common prefix among all the words stored in a Trie data
244
161
  * structure.
245
162
  * @returns The function `getLongestCommonPrefix` returns a string, which is the longest common prefix found in the
246
163
  * Trie.
247
164
  */
248
- Trie.prototype.getLongestCommonPrefix = function () {
249
- var commonPre = '';
250
- var dfs = function (cur) {
165
+ getLongestCommonPrefix() {
166
+ let commonPre = '';
167
+ const dfs = (cur) => {
251
168
  commonPre += cur.val;
252
169
  if (cur.isEnd)
253
170
  return;
@@ -258,60 +175,36 @@ var Trie = /** @class */ (function () {
258
175
  };
259
176
  dfs(this._root);
260
177
  return commonPre;
261
- };
178
+ }
262
179
  /**
263
180
  * The `getAll` function returns an array of all words in a Trie data structure that start with a given prefix.
264
181
  * @param [prefix] - The `prefix` parameter is a string that represents the prefix that we want to search for in the
265
182
  * trie. It is an optional parameter, so if no prefix is provided, it will default to an empty string.
266
183
  * @returns an array of strings.
267
184
  */
268
- Trie.prototype.getAll = function (prefix) {
269
- var e_6, _a;
270
- if (prefix === void 0) { prefix = ''; }
271
- var words = [];
185
+ getAll(prefix = '') {
186
+ const words = [];
272
187
  function dfs(node, word) {
273
- var e_7, _a;
274
- try {
275
- for (var _b = __values(node.children.keys()), _c = _b.next(); !_c.done; _c = _b.next()) {
276
- var char = _c.value;
277
- var charNode = node.children.get(char);
278
- if (charNode !== undefined) {
279
- dfs(charNode, word.concat(char));
280
- }
188
+ for (const char of node.children.keys()) {
189
+ const charNode = node.children.get(char);
190
+ if (charNode !== undefined) {
191
+ dfs(charNode, word.concat(char));
281
192
  }
282
193
  }
283
- catch (e_7_1) { e_7 = { error: e_7_1 }; }
284
- finally {
285
- try {
286
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
287
- }
288
- finally { if (e_7) throw e_7.error; }
289
- }
290
194
  if (node.isEnd) {
291
195
  words.push(word);
292
196
  }
293
197
  }
294
- var startNode = this._root;
198
+ let startNode = this._root;
295
199
  if (prefix) {
296
- try {
297
- for (var prefix_1 = __values(prefix), prefix_1_1 = prefix_1.next(); !prefix_1_1.done; prefix_1_1 = prefix_1.next()) {
298
- var c = prefix_1_1.value;
299
- var nodeC = startNode.children.get(c);
300
- if (nodeC)
301
- startNode = nodeC;
302
- }
303
- }
304
- catch (e_6_1) { e_6 = { error: e_6_1 }; }
305
- finally {
306
- try {
307
- if (prefix_1_1 && !prefix_1_1.done && (_a = prefix_1.return)) _a.call(prefix_1);
308
- }
309
- finally { if (e_6) throw e_6.error; }
200
+ for (const c of prefix) {
201
+ const nodeC = startNode.children.get(c);
202
+ if (nodeC)
203
+ startNode = nodeC;
310
204
  }
311
205
  }
312
206
  dfs(startNode, prefix);
313
207
  return words;
314
- };
315
- return Trie;
316
- }());
208
+ }
209
+ }
317
210
  exports.Trie = Trie;
@@ -8,72 +8,20 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
- var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
- function verb(n) { return function (v) { return step([n, v]); }; }
15
- function step(op) {
16
- if (f) throw new TypeError("Generator is already executing.");
17
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
- if (y = 0, t) op = [op[0] & 2, t.value];
20
- switch (op[0]) {
21
- case 0: case 1: t = op; break;
22
- case 4: _.label++; return { value: op[1], done: false };
23
- case 5: _.label++; y = op[1]; op = [0]; continue;
24
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
- default:
26
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
- if (t[2]) _.ops.pop();
31
- _.trys.pop(); continue;
32
- }
33
- op = body.call(thisArg, _);
34
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
- }
37
- };
38
- var __read = (this && this.__read) || function (o, n) {
39
- var m = typeof Symbol === "function" && o[Symbol.iterator];
40
- if (!m) return o;
41
- var i = m.call(o), r, ar = [], e;
42
- try {
43
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
44
- }
45
- catch (error) { e = { error: error }; }
46
- finally {
47
- try {
48
- if (r && !r.done && (m = i["return"])) m.call(i);
49
- }
50
- finally { if (e) throw e.error; }
51
- }
52
- return ar;
53
- };
54
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
55
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
56
- if (ar || !(i in from)) {
57
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
58
- ar[i] = from[i];
59
- }
60
- }
61
- return to.concat(ar || Array.prototype.slice.call(from));
62
- };
63
11
  Object.defineProperty(exports, "__esModule", { value: true });
64
12
  exports.trampolineAsync = exports.trampoline = exports.toThunk = exports.isThunk = exports.THUNK_SYMBOL = exports.arrayRemove = exports.uuidV4 = void 0;
65
- var uuidV4 = function () {
13
+ const uuidV4 = function () {
66
14
  return 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'.replace(/[x]/g, function (c) {
67
- var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
15
+ const r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
68
16
  return v.toString(16);
69
17
  });
70
18
  };
71
19
  exports.uuidV4 = uuidV4;
72
- var arrayRemove = function (array, predicate) {
73
- var i = -1, len = array ? array.length : 0;
74
- var result = [];
20
+ const arrayRemove = function (array, predicate) {
21
+ let i = -1, len = array ? array.length : 0;
22
+ const result = [];
75
23
  while (++i < len) {
76
- var value = array[i];
24
+ const value = array[i];
77
25
  if (predicate(value, i, array)) {
78
26
  result.push(value);
79
27
  Array.prototype.splice.call(array, i--, 1);
@@ -84,68 +32,35 @@ var arrayRemove = function (array, predicate) {
84
32
  };
85
33
  exports.arrayRemove = arrayRemove;
86
34
  exports.THUNK_SYMBOL = Symbol('thunk');
87
- var isThunk = function (fnOrValue) {
35
+ const isThunk = (fnOrValue) => {
88
36
  return typeof fnOrValue === 'function' && fnOrValue.__THUNK__ === exports.THUNK_SYMBOL;
89
37
  };
90
38
  exports.isThunk = isThunk;
91
- var toThunk = function (fn) {
92
- var thunk = function () { return fn(); };
39
+ const toThunk = (fn) => {
40
+ const thunk = () => fn();
93
41
  thunk.__THUNK__ = exports.THUNK_SYMBOL;
94
42
  return thunk;
95
43
  };
96
44
  exports.toThunk = toThunk;
97
- var trampoline = function (fn) {
98
- var cont = function () {
99
- var args = [];
100
- for (var _i = 0; _i < arguments.length; _i++) {
101
- args[_i] = arguments[_i];
102
- }
103
- return (0, exports.toThunk)(function () { return fn.apply(void 0, __spreadArray([], __read(args), false)); });
104
- };
105
- return Object.assign(function () {
106
- var args = [];
107
- for (var _i = 0; _i < arguments.length; _i++) {
108
- args[_i] = arguments[_i];
109
- }
110
- var result = fn.apply(void 0, __spreadArray([], __read(args), false));
45
+ const trampoline = (fn) => {
46
+ const cont = (...args) => (0, exports.toThunk)(() => fn(...args));
47
+ return Object.assign((...args) => {
48
+ let result = fn(...args);
111
49
  while ((0, exports.isThunk)(result) && typeof result === 'function') {
112
50
  result = result();
113
51
  }
114
52
  return result;
115
- }, { cont: cont });
53
+ }, { cont });
116
54
  };
117
55
  exports.trampoline = trampoline;
118
- var trampolineAsync = function (fn) {
119
- var cont = function () {
120
- var args = [];
121
- for (var _i = 0; _i < arguments.length; _i++) {
122
- args[_i] = arguments[_i];
123
- }
124
- return (0, exports.toThunk)(function () { return fn.apply(void 0, __spreadArray([], __read(args), false)); });
125
- };
126
- return Object.assign(function () {
127
- var args = [];
128
- for (var _i = 0; _i < arguments.length; _i++) {
129
- args[_i] = arguments[_i];
56
+ const trampolineAsync = (fn) => {
57
+ const cont = (...args) => (0, exports.toThunk)(() => fn(...args));
58
+ return Object.assign((...args) => __awaiter(void 0, void 0, void 0, function* () {
59
+ let result = yield fn(...args);
60
+ while ((0, exports.isThunk)(result) && typeof result === 'function') {
61
+ result = yield result();
130
62
  }
131
- return __awaiter(void 0, void 0, void 0, function () {
132
- var result;
133
- return __generator(this, function (_a) {
134
- switch (_a.label) {
135
- case 0: return [4 /*yield*/, fn.apply(void 0, __spreadArray([], __read(args), false))];
136
- case 1:
137
- result = _a.sent();
138
- _a.label = 2;
139
- case 2:
140
- if (!((0, exports.isThunk)(result) && typeof result === 'function')) return [3 /*break*/, 4];
141
- return [4 /*yield*/, result()];
142
- case 3:
143
- result = _a.sent();
144
- return [3 /*break*/, 2];
145
- case 4: return [2 /*return*/, result];
146
- }
147
- });
148
- });
149
- }, { cont: cont });
63
+ return result;
64
+ }), { cont });
150
65
  };
151
66
  exports.trampolineAsync = trampolineAsync;
@@ -1,12 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.isNumber = exports.isObjectWithNumberId = exports.isObjectWithNonNumberId = exports.isObjectWithoutId = exports.isNonNumberNonObjectButDefined = exports.parseBySchema = exports.binaryTreeNodeValWithId = exports.objectWithNumberIdSchema = exports.objectWithNonNumberIdSchema = exports.keyValueObjectWithIdSchema = exports.objectWithoutIdSchema = exports.keyValueObjectSchema = exports.nonNumberNonObjectButDefinedSchema = void 0;
4
- var zod_1 = require("zod");
4
+ const zod_1 = require("zod");
5
5
  exports.nonNumberNonObjectButDefinedSchema = zod_1.z.union([zod_1.z.string(),
6
6
  zod_1.z.boolean(), zod_1.z.any()])
7
7
  .nullable();
8
8
  exports.keyValueObjectSchema = zod_1.z.record(zod_1.z.unknown());
9
- exports.objectWithoutIdSchema = exports.keyValueObjectSchema.refine(function (obj) { return !('id' in obj); }, {
9
+ exports.objectWithoutIdSchema = exports.keyValueObjectSchema.refine(obj => !('id' in obj), {
10
10
  message: 'Object cannot contain the \'id\' field',
11
11
  });
12
12
  exports.keyValueObjectWithIdSchema = zod_1.z.record(zod_1.z.any()).and(zod_1.z.object({