data-structure-typed 1.19.3 → 1.19.5

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 +3 -2
  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
@@ -8,8 +8,8 @@
8
8
  */
9
9
  Object.defineProperty(exports, "__esModule", { value: true });
10
10
  exports.SegmentTree = exports.SegmentTreeNode = void 0;
11
- var SegmentTreeNode = /** @class */ (function () {
12
- function SegmentTreeNode(start, end, sum, val) {
11
+ class SegmentTreeNode {
12
+ constructor(start, end, sum, val) {
13
13
  this._start = 0;
14
14
  this._end = 0;
15
15
  this._val = null;
@@ -21,70 +21,45 @@ var SegmentTreeNode = /** @class */ (function () {
21
21
  this._sum = sum;
22
22
  this._val = val || null;
23
23
  }
24
- Object.defineProperty(SegmentTreeNode.prototype, "start", {
25
- get: function () {
26
- return this._start;
27
- },
28
- set: function (v) {
29
- this._start = v;
30
- },
31
- enumerable: false,
32
- configurable: true
33
- });
34
- Object.defineProperty(SegmentTreeNode.prototype, "end", {
35
- get: function () {
36
- return this._end;
37
- },
38
- set: function (v) {
39
- this._end = v;
40
- },
41
- enumerable: false,
42
- configurable: true
43
- });
44
- Object.defineProperty(SegmentTreeNode.prototype, "val", {
45
- get: function () {
46
- return this._val;
47
- },
48
- set: function (v) {
49
- this._val = v;
50
- },
51
- enumerable: false,
52
- configurable: true
53
- });
54
- Object.defineProperty(SegmentTreeNode.prototype, "sum", {
55
- get: function () {
56
- return this._sum;
57
- },
58
- set: function (v) {
59
- this._sum = v;
60
- },
61
- enumerable: false,
62
- configurable: true
63
- });
64
- Object.defineProperty(SegmentTreeNode.prototype, "left", {
65
- get: function () {
66
- return this._left;
67
- },
68
- set: function (v) {
69
- this._left = v;
70
- },
71
- enumerable: false,
72
- configurable: true
73
- });
74
- Object.defineProperty(SegmentTreeNode.prototype, "right", {
75
- get: function () {
76
- return this._right;
77
- },
78
- set: function (v) {
79
- this._right = v;
80
- },
81
- enumerable: false,
82
- configurable: true
83
- });
84
- return SegmentTreeNode;
85
- }());
24
+ get start() {
25
+ return this._start;
26
+ }
27
+ set start(v) {
28
+ this._start = v;
29
+ }
30
+ get end() {
31
+ return this._end;
32
+ }
33
+ set end(v) {
34
+ this._end = v;
35
+ }
36
+ get val() {
37
+ return this._val;
38
+ }
39
+ set val(v) {
40
+ this._val = v;
41
+ }
42
+ get sum() {
43
+ return this._sum;
44
+ }
45
+ set sum(v) {
46
+ this._sum = v;
47
+ }
48
+ get left() {
49
+ return this._left;
50
+ }
51
+ set left(v) {
52
+ this._left = v;
53
+ }
54
+ get right() {
55
+ return this._right;
56
+ }
57
+ set right(v) {
58
+ this._right = v;
59
+ }
60
+ }
86
61
  exports.SegmentTreeNode = SegmentTreeNode;
87
- var SegmentTree = /** @class */ (function () {
62
+ class SegmentTree {
88
63
  /**
89
64
  * The constructor initializes the values, start, end, and root properties of an object.
90
65
  * @param {number[]} values - An array of numbers that will be used to build a binary search tree.
@@ -94,7 +69,7 @@ var SegmentTree = /** @class */ (function () {
94
69
  * @param {number} [end] - The "end" parameter is the index of the last element in the "values" array that should be
95
70
  * included in the range. If not provided, it defaults to the index of the last element in the "values" array.
96
71
  */
97
- function SegmentTree(values, start, end) {
72
+ constructor(values, start, end) {
98
73
  this._values = [];
99
74
  this._start = 0;
100
75
  start = start || 0;
@@ -104,34 +79,18 @@ var SegmentTree = /** @class */ (function () {
104
79
  this._end = end;
105
80
  this._root = this.build(start, end);
106
81
  }
107
- Object.defineProperty(SegmentTree.prototype, "values", {
108
- get: function () {
109
- return this._values;
110
- },
111
- enumerable: false,
112
- configurable: true
113
- });
114
- Object.defineProperty(SegmentTree.prototype, "start", {
115
- get: function () {
116
- return this._start;
117
- },
118
- enumerable: false,
119
- configurable: true
120
- });
121
- Object.defineProperty(SegmentTree.prototype, "end", {
122
- get: function () {
123
- return this._end;
124
- },
125
- enumerable: false,
126
- configurable: true
127
- });
128
- Object.defineProperty(SegmentTree.prototype, "root", {
129
- get: function () {
130
- return this._root;
131
- },
132
- enumerable: false,
133
- configurable: true
134
- });
82
+ get values() {
83
+ return this._values;
84
+ }
85
+ get start() {
86
+ return this._start;
87
+ }
88
+ get end() {
89
+ return this._end;
90
+ }
91
+ get root() {
92
+ return this._root;
93
+ }
135
94
  /**
136
95
  * The function builds a segment tree by recursively dividing the given range into smaller segments and creating nodes
137
96
  * for each segment.
@@ -141,17 +100,17 @@ var SegmentTree = /** @class */ (function () {
141
100
  * building the segment tree.
142
101
  * @returns a SegmentTreeNode object.
143
102
  */
144
- SegmentTree.prototype.build = function (start, end) {
103
+ build(start, end) {
145
104
  if (start === end)
146
105
  return new SegmentTreeNode(start, end, this._values[start]);
147
- var mid = start + Math.floor((end - start) / 2);
148
- var left = this.build(start, mid);
149
- var right = this.build(mid + 1, end);
150
- var cur = new SegmentTreeNode(start, end, left.sum + right.sum);
106
+ const mid = start + Math.floor((end - start) / 2);
107
+ const left = this.build(start, mid);
108
+ const right = this.build(mid + 1, end);
109
+ const cur = new SegmentTreeNode(start, end, left.sum + right.sum);
151
110
  cur.left = left;
152
111
  cur.right = right;
153
112
  return cur;
154
- };
113
+ }
155
114
  /**
156
115
  * The function updates the value of a node in a segment tree and recalculates the sum of its children if they exist.
157
116
  * @param {number} index - The index parameter represents the index of the node in the segment tree that needs to be
@@ -163,18 +122,18 @@ var SegmentTree = /** @class */ (function () {
163
122
  * cur.val = val;` and pass a value for `val` in the
164
123
  * @returns The function does not return anything.
165
124
  */
166
- SegmentTree.prototype.updateNode = function (index, sum, val) {
167
- var root = this.root || null;
125
+ updateNode(index, sum, val) {
126
+ const root = this.root || null;
168
127
  if (!root) {
169
128
  return;
170
129
  }
171
- var dfs = function (cur, index, sum, val) {
130
+ const dfs = (cur, index, sum, val) => {
172
131
  if (cur.start === cur.end && cur.start === index) {
173
132
  cur.sum = sum;
174
133
  // cur.val = val;
175
134
  return;
176
135
  }
177
- var mid = cur.start + Math.floor((cur.end - cur.start) / 2);
136
+ const mid = cur.start + Math.floor((cur.end - cur.start) / 2);
178
137
  if (index <= mid) {
179
138
  if (cur.left) {
180
139
  dfs(cur.left, index, sum, val);
@@ -190,7 +149,7 @@ var SegmentTree = /** @class */ (function () {
190
149
  }
191
150
  };
192
151
  dfs(root, index, sum);
193
- };
152
+ }
194
153
  /**
195
154
  * The function `querySumByRange` calculates the sum of values within a given range in a segment tree.
196
155
  * @param {number} indexA - The starting index of the range for which you want to calculate the sum.
@@ -198,16 +157,16 @@ var SegmentTree = /** @class */ (function () {
198
157
  * calculate the sum.
199
158
  * @returns The function `querySumByRange` returns a number.
200
159
  */
201
- SegmentTree.prototype.querySumByRange = function (indexA, indexB) {
202
- var root = this.root || null;
160
+ querySumByRange(indexA, indexB) {
161
+ const root = this.root || null;
203
162
  if (!root) {
204
163
  return 0;
205
164
  }
206
- var dfs = function (cur, i, j) {
165
+ const dfs = (cur, i, j) => {
207
166
  if (cur.start === i && cur.end === j) {
208
167
  return cur.sum;
209
168
  }
210
- var mid = cur.start + Math.floor((cur.end - cur.start) / 2);
169
+ const mid = cur.start + Math.floor((cur.end - cur.start) / 2);
211
170
  if (j <= mid) {
212
171
  // TODO after no-non-null-assertion not ensure the logic
213
172
  if (cur.left) {
@@ -238,19 +197,18 @@ var SegmentTree = /** @class */ (function () {
238
197
  }
239
198
  };
240
199
  return dfs(root, indexA, indexB);
241
- };
242
- SegmentTree.prototype._setValues = function (value) {
200
+ }
201
+ _setValues(value) {
243
202
  this._values = value;
244
- };
245
- SegmentTree.prototype._setStart = function (value) {
203
+ }
204
+ _setStart(value) {
246
205
  this._start = value;
247
- };
248
- SegmentTree.prototype._setEnd = function (value) {
206
+ }
207
+ _setEnd(value) {
249
208
  this._end = value;
250
- };
251
- SegmentTree.prototype._setRoot = function (v) {
209
+ }
210
+ _setRoot(v) {
252
211
  this._root = v;
253
- };
254
- return SegmentTree;
255
- }());
212
+ }
213
+ }
256
214
  exports.SegmentTree = SegmentTree;
@@ -1,9 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SplayTree = void 0;
4
- var SplayTree = /** @class */ (function () {
5
- function SplayTree() {
6
- }
7
- return SplayTree;
8
- }());
4
+ class SplayTree {
5
+ }
9
6
  exports.SplayTree = SplayTree;