data-structure-typed 1.33.6 → 1.33.8
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/.github/workflows/ci.yml +1 -0
- package/CHANGELOG.md +1 -1
- package/README.md +42 -38
- package/coverage/coverage-final.json +64 -63
- package/coverage/coverage-summary.json +8 -7
- package/dist/data-structures/binary-tree/segment-tree.js +24 -6
- package/dist/data-structures/binary-tree/segment-tree.js.map +1 -1
- package/dist/data-structures/hash/hash-map.js +306 -0
- package/dist/data-structures/hash/hash-map.js.map +1 -0
- package/dist/data-structures/hash/hash-table.js +128 -38
- package/dist/data-structures/hash/hash-table.js.map +1 -1
- package/dist/data-structures/hash/index.js +1 -0
- package/dist/data-structures/hash/index.js.map +1 -1
- package/dist/data-structures/linked-list/skip-linked-list.js +122 -5
- package/dist/data-structures/linked-list/skip-linked-list.js.map +1 -1
- package/dist/types/data-structures/hash.js +3 -0
- package/dist/types/data-structures/hash.js.map +1 -0
- package/dist/types/data-structures/index.js +1 -0
- package/dist/types/data-structures/index.js.map +1 -1
- package/docs/index.html +35 -37
- package/docs/modules.html +10 -4
- package/lib/data-structures/binary-tree/segment-tree.d.ts +4 -4
- package/lib/data-structures/binary-tree/segment-tree.js +30 -14
- package/lib/data-structures/hash/hash-map.d.ts +56 -0
- package/lib/data-structures/hash/hash-map.js +167 -0
- package/lib/data-structures/hash/hash-table.d.ts +67 -23
- package/lib/data-structures/hash/hash-table.js +154 -52
- package/lib/data-structures/hash/index.d.ts +1 -0
- package/lib/data-structures/hash/index.js +1 -0
- package/lib/data-structures/linked-list/skip-linked-list.d.ts +60 -1
- package/lib/data-structures/linked-list/skip-linked-list.js +136 -1
- package/lib/types/data-structures/hash.d.ts +1 -0
- package/lib/types/data-structures/hash.js +1 -0
- package/lib/types/data-structures/index.d.ts +1 -0
- package/lib/types/data-structures/index.js +1 -0
- package/package.json +22 -22
- package/src/data-structures/binary-tree/segment-tree.ts +32 -14
- package/src/data-structures/hash/hash-map.ts +203 -0
- package/src/data-structures/hash/hash-table.ts +176 -56
- package/src/data-structures/hash/index.ts +1 -0
- package/src/data-structures/linked-list/skip-linked-list.ts +166 -1
- package/src/types/data-structures/hash.ts +1 -0
- package/src/types/data-structures/index.ts +1 -0
- package/test/integration/index.html +26 -18
- package/test/unit/data-structures/binary-tree/segment-tree.test.ts +50 -0
- package/test/unit/data-structures/hash/hash-map.test.ts +104 -0
- package/test/unit/data-structures/hash/hash-table.test.ts +97 -10
- package/test/unit/data-structures/linked-list/skip-list.test.ts +55 -0
- package/umd/bundle.min.js +1 -1
- package/umd/bundle.min.js.map +1 -1
- package/tsconfig.prod.json +0 -25
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
{"total": {"lines":{"total":
|
|
1
|
+
{"total": {"lines":{"total":3373,"covered":2314,"skipped":0,"pct":68.6},"statements":{"total":3694,"covered":2475,"skipped":0,"pct":67},"functions":{"total":708,"covered":470,"skipped":0,"pct":66.38},"branches":{"total":1718,"covered":953,"skipped":0,"pct":55.47},"branchesTrue":{"total":0,"covered":0,"skipped":0,"pct":100}}
|
|
2
2
|
,"/Users/revone/projects/data-structure-typed/src/index.ts": {"lines":{"total":4,"covered":4,"skipped":0,"pct":100},"functions":{"total":0,"covered":0,"skipped":0,"pct":100},"statements":{"total":4,"covered":4,"skipped":0,"pct":100},"branches":{"total":0,"covered":0,"skipped":0,"pct":100}}
|
|
3
3
|
,"/Users/revone/projects/data-structure-typed/src/data-structures/index.ts": {"lines":{"total":11,"covered":11,"skipped":0,"pct":100},"functions":{"total":0,"covered":0,"skipped":0,"pct":100},"statements":{"total":11,"covered":11,"skipped":0,"pct":100},"branches":{"total":0,"covered":0,"skipped":0,"pct":100}}
|
|
4
4
|
,"/Users/revone/projects/data-structure-typed/src/data-structures/binary-tree/aa-tree.ts": {"lines":{"total":1,"covered":1,"skipped":0,"pct":100},"functions":{"total":0,"covered":0,"skipped":0,"pct":100},"statements":{"total":1,"covered":1,"skipped":0,"pct":100},"branches":{"total":0,"covered":0,"skipped":0,"pct":100}}
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
,"/Users/revone/projects/data-structure-typed/src/data-structures/binary-tree/bst.ts": {"lines":{"total":256,"covered":131,"skipped":0,"pct":51.17},"functions":{"total":31,"covered":13,"skipped":0,"pct":41.93},"statements":{"total":308,"covered":144,"skipped":0,"pct":46.75},"branches":{"total":230,"covered":88,"skipped":0,"pct":38.26}}
|
|
11
11
|
,"/Users/revone/projects/data-structure-typed/src/data-structures/binary-tree/index.ts": {"lines":{"total":12,"covered":12,"skipped":0,"pct":100},"functions":{"total":0,"covered":0,"skipped":0,"pct":100},"statements":{"total":12,"covered":12,"skipped":0,"pct":100},"branches":{"total":0,"covered":0,"skipped":0,"pct":100}}
|
|
12
12
|
,"/Users/revone/projects/data-structure-typed/src/data-structures/binary-tree/rb-tree.ts": {"lines":{"total":10,"covered":4,"skipped":0,"pct":40},"functions":{"total":5,"covered":0,"skipped":0,"pct":0},"statements":{"total":10,"covered":4,"skipped":0,"pct":40},"branches":{"total":0,"covered":0,"skipped":0,"pct":100}}
|
|
13
|
-
,"/Users/revone/projects/data-structure-typed/src/data-structures/binary-tree/segment-tree.ts": {"lines":{"total":
|
|
13
|
+
,"/Users/revone/projects/data-structure-typed/src/data-structures/binary-tree/segment-tree.ts": {"lines":{"total":98,"covered":84,"skipped":0,"pct":85.71},"functions":{"total":27,"covered":17,"skipped":0,"pct":62.96},"statements":{"total":100,"covered":85,"skipped":0,"pct":85},"branches":{"total":44,"covered":38,"skipped":0,"pct":86.36}}
|
|
14
14
|
,"/Users/revone/projects/data-structure-typed/src/data-structures/binary-tree/splay-tree.ts": {"lines":{"total":1,"covered":1,"skipped":0,"pct":100},"functions":{"total":0,"covered":0,"skipped":0,"pct":100},"statements":{"total":1,"covered":1,"skipped":0,"pct":100},"branches":{"total":0,"covered":0,"skipped":0,"pct":100}}
|
|
15
15
|
,"/Users/revone/projects/data-structure-typed/src/data-structures/binary-tree/tree-multiset.ts": {"lines":{"total":299,"covered":162,"skipped":0,"pct":54.18},"functions":{"total":39,"covered":17,"skipped":0,"pct":43.58},"statements":{"total":344,"covered":172,"skipped":0,"pct":50},"branches":{"total":194,"covered":79,"skipped":0,"pct":40.72}}
|
|
16
16
|
,"/Users/revone/projects/data-structure-typed/src/data-structures/binary-tree/two-three-tree.ts": {"lines":{"total":1,"covered":1,"skipped":0,"pct":100},"functions":{"total":0,"covered":0,"skipped":0,"pct":100},"statements":{"total":1,"covered":1,"skipped":0,"pct":100},"branches":{"total":0,"covered":0,"skipped":0,"pct":100}}
|
|
@@ -21,8 +21,9 @@
|
|
|
21
21
|
,"/Users/revone/projects/data-structure-typed/src/data-structures/graph/undirected-graph.ts": {"lines":{"total":74,"covered":53,"skipped":0,"pct":71.62},"functions":{"total":24,"covered":16,"skipped":0,"pct":66.66},"statements":{"total":79,"covered":57,"skipped":0,"pct":72.15},"branches":{"total":52,"covered":30,"skipped":0,"pct":57.69}}
|
|
22
22
|
,"/Users/revone/projects/data-structure-typed/src/data-structures/hash/coordinate-map.ts": {"lines":{"total":10,"covered":8,"skipped":0,"pct":80},"functions":{"total":7,"covered":5,"skipped":0,"pct":71.42},"statements":{"total":11,"covered":8,"skipped":0,"pct":72.72},"branches":{"total":1,"covered":0,"skipped":0,"pct":0}}
|
|
23
23
|
,"/Users/revone/projects/data-structure-typed/src/data-structures/hash/coordinate-set.ts": {"lines":{"total":9,"covered":7,"skipped":0,"pct":77.77},"functions":{"total":6,"covered":4,"skipped":0,"pct":66.66},"statements":{"total":10,"covered":7,"skipped":0,"pct":70},"branches":{"total":1,"covered":0,"skipped":0,"pct":0}}
|
|
24
|
-
,"/Users/revone/projects/data-structure-typed/src/data-structures/hash/hash-
|
|
25
|
-
,"/Users/revone/projects/data-structure-typed/src/data-structures/hash/
|
|
24
|
+
,"/Users/revone/projects/data-structure-typed/src/data-structures/hash/hash-map.ts": {"lines":{"total":72,"covered":63,"skipped":0,"pct":87.5},"functions":{"total":23,"covered":18,"skipped":0,"pct":78.26},"statements":{"total":75,"covered":66,"skipped":0,"pct":88},"branches":{"total":15,"covered":12,"skipped":0,"pct":80}}
|
|
25
|
+
,"/Users/revone/projects/data-structure-typed/src/data-structures/hash/hash-table.ts": {"lines":{"total":95,"covered":80,"skipped":0,"pct":84.21},"functions":{"total":19,"covered":15,"skipped":0,"pct":78.94},"statements":{"total":98,"covered":82,"skipped":0,"pct":83.67},"branches":{"total":16,"covered":15,"skipped":0,"pct":93.75}}
|
|
26
|
+
,"/Users/revone/projects/data-structure-typed/src/data-structures/hash/index.ts": {"lines":{"total":7,"covered":7,"skipped":0,"pct":100},"functions":{"total":0,"covered":0,"skipped":0,"pct":100},"statements":{"total":7,"covered":7,"skipped":0,"pct":100},"branches":{"total":0,"covered":0,"skipped":0,"pct":100}}
|
|
26
27
|
,"/Users/revone/projects/data-structure-typed/src/data-structures/hash/pair.ts": {"lines":{"total":1,"covered":1,"skipped":0,"pct":100},"functions":{"total":0,"covered":0,"skipped":0,"pct":100},"statements":{"total":1,"covered":1,"skipped":0,"pct":100},"branches":{"total":0,"covered":0,"skipped":0,"pct":100}}
|
|
27
28
|
,"/Users/revone/projects/data-structure-typed/src/data-structures/hash/tree-map.ts": {"lines":{"total":1,"covered":1,"skipped":0,"pct":100},"functions":{"total":0,"covered":0,"skipped":0,"pct":100},"statements":{"total":1,"covered":1,"skipped":0,"pct":100},"branches":{"total":0,"covered":0,"skipped":0,"pct":100}}
|
|
28
29
|
,"/Users/revone/projects/data-structure-typed/src/data-structures/hash/tree-set.ts": {"lines":{"total":1,"covered":1,"skipped":0,"pct":100},"functions":{"total":0,"covered":0,"skipped":0,"pct":100},"statements":{"total":1,"covered":1,"skipped":0,"pct":100},"branches":{"total":0,"covered":0,"skipped":0,"pct":100}}
|
|
@@ -30,10 +31,10 @@
|
|
|
30
31
|
,"/Users/revone/projects/data-structure-typed/src/data-structures/heap/index.ts": {"lines":{"total":3,"covered":3,"skipped":0,"pct":100},"functions":{"total":0,"covered":0,"skipped":0,"pct":100},"statements":{"total":3,"covered":3,"skipped":0,"pct":100},"branches":{"total":0,"covered":0,"skipped":0,"pct":100}}
|
|
31
32
|
,"/Users/revone/projects/data-structure-typed/src/data-structures/heap/max-heap.ts": {"lines":{"total":6,"covered":6,"skipped":0,"pct":100},"functions":{"total":2,"covered":2,"skipped":0,"pct":100},"statements":{"total":6,"covered":6,"skipped":0,"pct":100},"branches":{"total":0,"covered":0,"skipped":0,"pct":100}}
|
|
32
33
|
,"/Users/revone/projects/data-structure-typed/src/data-structures/heap/min-heap.ts": {"lines":{"total":6,"covered":6,"skipped":0,"pct":100},"functions":{"total":2,"covered":2,"skipped":0,"pct":100},"statements":{"total":6,"covered":6,"skipped":0,"pct":100},"branches":{"total":0,"covered":0,"skipped":0,"pct":100}}
|
|
33
|
-
,"/Users/revone/projects/data-structure-typed/src/data-structures/linked-list/doubly-linked-list.ts": {"lines":{"total":218,"covered":195,"skipped":0,"pct":89.44},"functions":{"total":45,"covered":43,"skipped":0,"pct":95.55},"statements":{"total":228,"covered":
|
|
34
|
+
,"/Users/revone/projects/data-structure-typed/src/data-structures/linked-list/doubly-linked-list.ts": {"lines":{"total":218,"covered":195,"skipped":0,"pct":89.44},"functions":{"total":45,"covered":43,"skipped":0,"pct":95.55},"statements":{"total":228,"covered":200,"skipped":0,"pct":87.71},"branches":{"total":56,"covered":44,"skipped":0,"pct":78.57}}
|
|
34
35
|
,"/Users/revone/projects/data-structure-typed/src/data-structures/linked-list/index.ts": {"lines":{"total":3,"covered":3,"skipped":0,"pct":100},"functions":{"total":0,"covered":0,"skipped":0,"pct":100},"statements":{"total":3,"covered":3,"skipped":0,"pct":100},"branches":{"total":0,"covered":0,"skipped":0,"pct":100}}
|
|
35
36
|
,"/Users/revone/projects/data-structure-typed/src/data-structures/linked-list/singly-linked-list.ts": {"lines":{"total":184,"covered":165,"skipped":0,"pct":89.67},"functions":{"total":33,"covered":29,"skipped":0,"pct":87.87},"statements":{"total":195,"covered":174,"skipped":0,"pct":89.23},"branches":{"total":43,"covered":34,"skipped":0,"pct":79.06}}
|
|
36
|
-
,"/Users/revone/projects/data-structure-typed/src/data-structures/linked-list/skip-linked-list.ts": {"lines":{"total":
|
|
37
|
+
,"/Users/revone/projects/data-structure-typed/src/data-structures/linked-list/skip-linked-list.ts": {"lines":{"total":57,"covered":51,"skipped":0,"pct":89.47},"functions":{"total":14,"covered":11,"skipped":0,"pct":78.57},"statements":{"total":62,"covered":56,"skipped":0,"pct":90.32},"branches":{"total":20,"covered":19,"skipped":0,"pct":95}}
|
|
37
38
|
,"/Users/revone/projects/data-structure-typed/src/data-structures/matrix/index.ts": {"lines":{"total":4,"covered":4,"skipped":0,"pct":100},"functions":{"total":0,"covered":0,"skipped":0,"pct":100},"statements":{"total":4,"covered":4,"skipped":0,"pct":100},"branches":{"total":0,"covered":0,"skipped":0,"pct":100}}
|
|
38
39
|
,"/Users/revone/projects/data-structure-typed/src/data-structures/matrix/matrix.ts": {"lines":{"total":4,"covered":4,"skipped":0,"pct":100},"functions":{"total":3,"covered":3,"skipped":0,"pct":100},"statements":{"total":5,"covered":5,"skipped":0,"pct":100},"branches":{"total":2,"covered":2,"skipped":0,"pct":100}}
|
|
39
40
|
,"/Users/revone/projects/data-structure-typed/src/data-structures/matrix/matrix2d.ts": {"lines":{"total":49,"covered":33,"skipped":0,"pct":67.34},"functions":{"total":14,"covered":9,"skipped":0,"pct":64.28},"statements":{"total":58,"covered":42,"skipped":0,"pct":72.41},"branches":{"total":4,"covered":3,"skipped":0,"pct":75}}
|
|
@@ -57,7 +58,7 @@
|
|
|
57
58
|
,"/Users/revone/projects/data-structure-typed/src/types/data-structures/abstract-binary-tree.ts": {"lines":{"total":11,"covered":11,"skipped":0,"pct":100},"functions":{"total":2,"covered":2,"skipped":0,"pct":100},"statements":{"total":11,"covered":11,"skipped":0,"pct":100},"branches":{"total":4,"covered":4,"skipped":0,"pct":100}}
|
|
58
59
|
,"/Users/revone/projects/data-structure-typed/src/types/data-structures/bst.ts": {"lines":{"total":1,"covered":1,"skipped":0,"pct":100},"functions":{"total":1,"covered":1,"skipped":0,"pct":100},"statements":{"total":4,"covered":4,"skipped":0,"pct":100},"branches":{"total":2,"covered":2,"skipped":0,"pct":100}}
|
|
59
60
|
,"/Users/revone/projects/data-structure-typed/src/types/data-structures/directed-graph.ts": {"lines":{"total":4,"covered":4,"skipped":0,"pct":100},"functions":{"total":1,"covered":1,"skipped":0,"pct":100},"statements":{"total":4,"covered":4,"skipped":0,"pct":100},"branches":{"total":2,"covered":2,"skipped":0,"pct":100}}
|
|
60
|
-
,"/Users/revone/projects/data-structure-typed/src/types/data-structures/index.ts": {"lines":{"total":
|
|
61
|
+
,"/Users/revone/projects/data-structure-typed/src/types/data-structures/index.ts": {"lines":{"total":16,"covered":16,"skipped":0,"pct":100},"functions":{"total":0,"covered":0,"skipped":0,"pct":100},"statements":{"total":16,"covered":16,"skipped":0,"pct":100},"branches":{"total":0,"covered":0,"skipped":0,"pct":100}}
|
|
61
62
|
,"/Users/revone/projects/data-structure-typed/src/types/data-structures/rb-tree.ts": {"lines":{"total":1,"covered":1,"skipped":0,"pct":100},"functions":{"total":1,"covered":1,"skipped":0,"pct":100},"statements":{"total":3,"covered":3,"skipped":0,"pct":100},"branches":{"total":2,"covered":2,"skipped":0,"pct":100}}
|
|
62
63
|
,"/Users/revone/projects/data-structure-typed/src/types/utils/index.ts": {"lines":{"total":2,"covered":2,"skipped":0,"pct":100},"functions":{"total":0,"covered":0,"skipped":0,"pct":100},"statements":{"total":2,"covered":2,"skipped":0,"pct":100},"branches":{"total":0,"covered":0,"skipped":0,"pct":100}}
|
|
63
64
|
,"/Users/revone/projects/data-structure-typed/src/utils/index.ts": {"lines":{"total":1,"covered":1,"skipped":0,"pct":100},"functions":{"total":0,"covered":0,"skipped":0,"pct":100},"statements":{"total":1,"covered":1,"skipped":0,"pct":100},"branches":{"total":0,"covered":0,"skipped":0,"pct":100}}
|
|
@@ -81,12 +81,21 @@ var SegmentTree = (function () {
|
|
|
81
81
|
function SegmentTree(values, start, end) {
|
|
82
82
|
this._values = [];
|
|
83
83
|
this._start = 0;
|
|
84
|
+
console.log('values.length:', values.length);
|
|
84
85
|
start = start || 0;
|
|
85
86
|
end = end || values.length - 1;
|
|
86
87
|
this._values = values;
|
|
87
88
|
this._start = start;
|
|
88
89
|
this._end = end;
|
|
89
|
-
|
|
90
|
+
if (values.length > 0) {
|
|
91
|
+
console.log('Initializing with non-empty array');
|
|
92
|
+
this._root = this.build(start, end);
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
console.log('Initializing with empty array');
|
|
96
|
+
this._root = null;
|
|
97
|
+
this._values = [];
|
|
98
|
+
}
|
|
90
99
|
}
|
|
91
100
|
Object.defineProperty(SegmentTree.prototype, "values", {
|
|
92
101
|
get: function () {
|
|
@@ -117,6 +126,9 @@ var SegmentTree = (function () {
|
|
|
117
126
|
configurable: true
|
|
118
127
|
});
|
|
119
128
|
SegmentTree.prototype.build = function (start, end) {
|
|
129
|
+
if (start > end) {
|
|
130
|
+
return new SegmentTreeNode(start, end, 0);
|
|
131
|
+
}
|
|
120
132
|
if (start === end)
|
|
121
133
|
return new SegmentTreeNode(start, end, this._values[start]);
|
|
122
134
|
var mid = start + Math.floor((end - start) / 2);
|
|
@@ -161,8 +173,11 @@ var SegmentTree = (function () {
|
|
|
161
173
|
if (!root) {
|
|
162
174
|
return 0;
|
|
163
175
|
}
|
|
176
|
+
if (indexA < 0 || indexB >= this.values.length || indexA > indexB) {
|
|
177
|
+
return NaN;
|
|
178
|
+
}
|
|
164
179
|
var dfs = function (cur, i, j) {
|
|
165
|
-
if (cur.start
|
|
180
|
+
if (i <= cur.start && j >= cur.end) {
|
|
166
181
|
return cur.sum;
|
|
167
182
|
}
|
|
168
183
|
var mid = cur.start + Math.floor((cur.end - cur.start) / 2);
|
|
@@ -183,12 +198,15 @@ var SegmentTree = (function () {
|
|
|
183
198
|
}
|
|
184
199
|
}
|
|
185
200
|
else {
|
|
186
|
-
|
|
187
|
-
|
|
201
|
+
var leftSum = 0;
|
|
202
|
+
var rightSum = 0;
|
|
203
|
+
if (cur.left) {
|
|
204
|
+
leftSum = dfs(cur.left, i, mid);
|
|
188
205
|
}
|
|
189
|
-
|
|
190
|
-
|
|
206
|
+
if (cur.right) {
|
|
207
|
+
rightSum = dfs(cur.right, mid + 1, j);
|
|
191
208
|
}
|
|
209
|
+
return leftSum + rightSum;
|
|
192
210
|
}
|
|
193
211
|
};
|
|
194
212
|
return dfs(root, indexA, indexB);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"segment-tree.js","sourceRoot":"","sources":["../../../src/data-structures/binary-tree/segment-tree.ts"],"names":[],"mappings":";;;AAUA;IACE,yBAAY,KAAa,EAAE,GAAW,EAAE,GAAW,EAAE,GAA+B;QAO5E,WAAM,GAAG,CAAC,CAAC;QASX,SAAI,GAAG,CAAC,CAAC;QAUT,SAAI,GAA8B,IAAI,CAAC;QAUvC,SAAI,GAAG,CAAC,CAAC;QAUT,UAAK,GAA2B,IAAI,CAAC;QAUrC,WAAM,GAA2B,IAAI,CAAC;QAvD5C,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;QACpB,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC;QAChB,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC;QAChB,IAAI,CAAC,IAAI,GAAG,GAAG,IAAI,IAAI,CAAC;IAC1B,CAAC;IAGD,sBAAI,kCAAK;aAAT;YACE,OAAO,IAAI,CAAC,MAAM,CAAC;QACrB,CAAC;aAED,UAAU,CAAS;YACjB,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC;QAClB,CAAC;;;OAJA;IAQD,sBAAI,gCAAG;aAAP;YACE,OAAO,IAAI,CAAC,IAAI,CAAC;QACnB,CAAC;aAED,UAAQ,CAAS;YACf,IAAI,CAAC,IAAI,GAAG,CAAC,CAAC;QAChB,CAAC;;;OAJA;IAQD,sBAAI,gCAAG;aAAP;YACE,OAAO,IAAI,CAAC,IAAI,CAAC;QACnB,CAAC;aAED,UAAQ,CAA4B;YAClC,IAAI,CAAC,IAAI,GAAG,CAAC,CAAC;QAChB,CAAC;;;OAJA;IAQD,sBAAI,gCAAG;aAAP;YACE,OAAO,IAAI,CAAC,IAAI,CAAC;QACnB,CAAC;aAED,UAAQ,CAAS;YACf,IAAI,CAAC,IAAI,GAAG,CAAC,CAAC;QAChB,CAAC;;;OAJA;IAQD,sBAAI,iCAAI;aAAR;YACE,OAAO,IAAI,CAAC,KAAK,CAAC;QACpB,CAAC;aAED,UAAS,CAAyB;YAChC,IAAI,CAAC,KAAK,GAAG,CAAC,CAAC;QACjB,CAAC;;;OAJA;IAQD,sBAAI,kCAAK;aAAT;YACE,OAAO,IAAI,CAAC,MAAM,CAAC;QACrB,CAAC;aAED,UAAU,CAAyB;YACjC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC;QAClB,CAAC;;;OAJA;IAKH,sBAAC;AAAD,CAAC,AAlED,IAkEC;AAlEY,0CAAe;AAoE5B;IAUE,qBAAY,MAAgB,EAAE,KAAc,EAAE,GAAY;
|
|
1
|
+
{"version":3,"file":"segment-tree.js","sourceRoot":"","sources":["../../../src/data-structures/binary-tree/segment-tree.ts"],"names":[],"mappings":";;;AAUA;IACE,yBAAY,KAAa,EAAE,GAAW,EAAE,GAAW,EAAE,GAA+B;QAO5E,WAAM,GAAG,CAAC,CAAC;QASX,SAAI,GAAG,CAAC,CAAC;QAUT,SAAI,GAA8B,IAAI,CAAC;QAUvC,SAAI,GAAG,CAAC,CAAC;QAUT,UAAK,GAA2B,IAAI,CAAC;QAUrC,WAAM,GAA2B,IAAI,CAAC;QAvD5C,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;QACpB,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC;QAChB,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC;QAChB,IAAI,CAAC,IAAI,GAAG,GAAG,IAAI,IAAI,CAAC;IAC1B,CA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ACZ;aACF;iBAAM,IAAI,CAAC,GAAG,GAAG,EAAE;gBAClB,IAAI,GAAG,CAAC,KAAK,EAAE;oBACb,OAAO,GAAG,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;iBAC7B;qBAAM;oBACL,OAAO,GAAG,CAAC;iBACZ;aACF;iBAAM;gBAEL,IAAI,OAAO,GAAG,CAAC,CAAC;gBAChB,IAAI,QAAQ,GAAG,CAAC,CAAC;gBACjB,IAAI,GAAG,CAAC,IAAI,EAAE;oBACZ,OAAO,GAAG,GAAG,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,EAAE,GAAG,CAAC,CAAC;iBACjC;gBACD,IAAI,GAAG,CAAC,KAAK,EAAE;oBACb,QAAQ,GAAG,GAAG,CAAC,GAAG,CAAC,KAAK,EAAE,GAAG,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC;iBACvC;gBACD,OAAO,OAAO,GAAG,QAAQ,CAAC;aAC3B;QACH,CAAC,CAAC;QACF,OAAO,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;IACnC,CAAC;IAES,gCAAU,GAApB,UAAqB,KAAe;QAClC,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC;IACvB,CAAC;IAES,+BAAS,GAAnB,UAAoB,KAAa;QAC/B,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;IACtB,CAAC;IAES,6BAAO,GAAjB,UAAkB,KAAa;QAC7B,IAAI,CAAC,IAAI,GAAG,KAAK,CAAC;IACpB,CAAC;IAES,8BAAQ,GAAlB,UAAmB,CAAyB;QAC1C,IAAI,CAAC,KAAK,GAAG,CAAC,CAAC;IACjB,CAAC;IACH,kBAAC;AAAD,CAAC,AArLD,IAqLC;AArLY,kCAAW"}
|
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
3
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
4
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
5
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
6
|
+
function step(op) {
|
|
7
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
8
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
9
|
+
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;
|
|
10
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
11
|
+
switch (op[0]) {
|
|
12
|
+
case 0: case 1: t = op; break;
|
|
13
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
14
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
15
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
16
|
+
default:
|
|
17
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
18
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
19
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
20
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
21
|
+
if (t[2]) _.ops.pop();
|
|
22
|
+
_.trys.pop(); continue;
|
|
23
|
+
}
|
|
24
|
+
op = body.call(thisArg, _);
|
|
25
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
26
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
var __values = (this && this.__values) || function(o) {
|
|
30
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
31
|
+
if (m) return m.call(o);
|
|
32
|
+
if (o && typeof o.length === "number") return {
|
|
33
|
+
next: function () {
|
|
34
|
+
if (o && i >= o.length) o = void 0;
|
|
35
|
+
return { value: o && o[i++], done: !o };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
39
|
+
};
|
|
40
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
41
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
42
|
+
if (!m) return o;
|
|
43
|
+
var i = m.call(o), r, ar = [], e;
|
|
44
|
+
try {
|
|
45
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
46
|
+
}
|
|
47
|
+
catch (error) { e = { error: error }; }
|
|
48
|
+
finally {
|
|
49
|
+
try {
|
|
50
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
51
|
+
}
|
|
52
|
+
finally { if (e) throw e.error; }
|
|
53
|
+
}
|
|
54
|
+
return ar;
|
|
55
|
+
};
|
|
56
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
57
|
+
exports.HashMap = void 0;
|
|
58
|
+
var HashMap = (function () {
|
|
59
|
+
function HashMap(initialCapacity, loadFactor, hashFn) {
|
|
60
|
+
if (initialCapacity === void 0) { initialCapacity = 16; }
|
|
61
|
+
if (loadFactor === void 0) { loadFactor = 0.75; }
|
|
62
|
+
var _this = this;
|
|
63
|
+
this._initialCapacity = initialCapacity;
|
|
64
|
+
this._loadFactor = loadFactor;
|
|
65
|
+
this._capacityMultiplier = 2;
|
|
66
|
+
this._size = 0;
|
|
67
|
+
this._table = new Array(initialCapacity);
|
|
68
|
+
this._hashFn =
|
|
69
|
+
hashFn ||
|
|
70
|
+
(function (key) {
|
|
71
|
+
var strKey = String(key);
|
|
72
|
+
var hash = 0;
|
|
73
|
+
for (var i = 0; i < strKey.length; i++) {
|
|
74
|
+
hash += strKey.charCodeAt(i);
|
|
75
|
+
}
|
|
76
|
+
return hash % _this.table.length;
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
Object.defineProperty(HashMap.prototype, "hashFn", {
|
|
80
|
+
get: function () {
|
|
81
|
+
return this._hashFn;
|
|
82
|
+
},
|
|
83
|
+
set: function (value) {
|
|
84
|
+
this._hashFn = value;
|
|
85
|
+
},
|
|
86
|
+
enumerable: false,
|
|
87
|
+
configurable: true
|
|
88
|
+
});
|
|
89
|
+
Object.defineProperty(HashMap.prototype, "table", {
|
|
90
|
+
get: function () {
|
|
91
|
+
return this._table;
|
|
92
|
+
},
|
|
93
|
+
set: function (value) {
|
|
94
|
+
this._table = value;
|
|
95
|
+
},
|
|
96
|
+
enumerable: false,
|
|
97
|
+
configurable: true
|
|
98
|
+
});
|
|
99
|
+
Object.defineProperty(HashMap.prototype, "capacityMultiplier", {
|
|
100
|
+
get: function () {
|
|
101
|
+
return this._capacityMultiplier;
|
|
102
|
+
},
|
|
103
|
+
set: function (value) {
|
|
104
|
+
this._capacityMultiplier = value;
|
|
105
|
+
},
|
|
106
|
+
enumerable: false,
|
|
107
|
+
configurable: true
|
|
108
|
+
});
|
|
109
|
+
Object.defineProperty(HashMap.prototype, "loadFactor", {
|
|
110
|
+
get: function () {
|
|
111
|
+
return this._loadFactor;
|
|
112
|
+
},
|
|
113
|
+
set: function (value) {
|
|
114
|
+
this._loadFactor = value;
|
|
115
|
+
},
|
|
116
|
+
enumerable: false,
|
|
117
|
+
configurable: true
|
|
118
|
+
});
|
|
119
|
+
Object.defineProperty(HashMap.prototype, "initialCapacity", {
|
|
120
|
+
get: function () {
|
|
121
|
+
return this._initialCapacity;
|
|
122
|
+
},
|
|
123
|
+
set: function (value) {
|
|
124
|
+
this._initialCapacity = value;
|
|
125
|
+
},
|
|
126
|
+
enumerable: false,
|
|
127
|
+
configurable: true
|
|
128
|
+
});
|
|
129
|
+
Object.defineProperty(HashMap.prototype, "size", {
|
|
130
|
+
get: function () {
|
|
131
|
+
return this._size;
|
|
132
|
+
},
|
|
133
|
+
set: function (value) {
|
|
134
|
+
this._size = value;
|
|
135
|
+
},
|
|
136
|
+
enumerable: false,
|
|
137
|
+
configurable: true
|
|
138
|
+
});
|
|
139
|
+
HashMap.prototype._hash = function (key) {
|
|
140
|
+
return this._hashFn(key);
|
|
141
|
+
};
|
|
142
|
+
HashMap.prototype.resizeTable = function (newCapacity) {
|
|
143
|
+
var e_1, _a, e_2, _b;
|
|
144
|
+
var newTable = new Array(newCapacity);
|
|
145
|
+
try {
|
|
146
|
+
for (var _c = __values(this._table), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
147
|
+
var bucket = _d.value;
|
|
148
|
+
if (bucket) {
|
|
149
|
+
try {
|
|
150
|
+
for (var bucket_1 = (e_2 = void 0, __values(bucket)), bucket_1_1 = bucket_1.next(); !bucket_1_1.done; bucket_1_1 = bucket_1.next()) {
|
|
151
|
+
var _e = __read(bucket_1_1.value, 2), key = _e[0], value = _e[1];
|
|
152
|
+
var newIndex = this._hash(key) % newCapacity;
|
|
153
|
+
if (!newTable[newIndex]) {
|
|
154
|
+
newTable[newIndex] = [];
|
|
155
|
+
}
|
|
156
|
+
newTable[newIndex].push([key, value]);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
160
|
+
finally {
|
|
161
|
+
try {
|
|
162
|
+
if (bucket_1_1 && !bucket_1_1.done && (_b = bucket_1.return)) _b.call(bucket_1);
|
|
163
|
+
}
|
|
164
|
+
finally { if (e_2) throw e_2.error; }
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
170
|
+
finally {
|
|
171
|
+
try {
|
|
172
|
+
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
|
|
173
|
+
}
|
|
174
|
+
finally { if (e_1) throw e_1.error; }
|
|
175
|
+
}
|
|
176
|
+
this._table = newTable;
|
|
177
|
+
};
|
|
178
|
+
HashMap.prototype.set = function (key, value) {
|
|
179
|
+
var loadFactor = this.size / this.table.length;
|
|
180
|
+
if (loadFactor >= this.loadFactor) {
|
|
181
|
+
this.resizeTable(this.table.length * this.capacityMultiplier);
|
|
182
|
+
}
|
|
183
|
+
var index = this._hash(key);
|
|
184
|
+
if (!this.table[index]) {
|
|
185
|
+
this.table[index] = [];
|
|
186
|
+
}
|
|
187
|
+
for (var i = 0; i < this.table[index].length; i++) {
|
|
188
|
+
if (this.table[index][i][0] === key) {
|
|
189
|
+
this.table[index][i][1] = value;
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
this.table[index].push([key, value]);
|
|
194
|
+
this.size++;
|
|
195
|
+
};
|
|
196
|
+
HashMap.prototype.get = function (key) {
|
|
197
|
+
var e_3, _a;
|
|
198
|
+
var index = this._hash(key);
|
|
199
|
+
if (!this.table[index]) {
|
|
200
|
+
return undefined;
|
|
201
|
+
}
|
|
202
|
+
try {
|
|
203
|
+
for (var _b = __values(this.table[index]), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
204
|
+
var _d = __read(_c.value, 2), k = _d[0], v = _d[1];
|
|
205
|
+
if (k === key) {
|
|
206
|
+
return v;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
211
|
+
finally {
|
|
212
|
+
try {
|
|
213
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
214
|
+
}
|
|
215
|
+
finally { if (e_3) throw e_3.error; }
|
|
216
|
+
}
|
|
217
|
+
return undefined;
|
|
218
|
+
};
|
|
219
|
+
HashMap.prototype.remove = function (key) {
|
|
220
|
+
var index = this._hash(key);
|
|
221
|
+
if (!this.table[index]) {
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
for (var i = 0; i < this.table[index].length; i++) {
|
|
225
|
+
if (this.table[index][i][0] === key) {
|
|
226
|
+
this.table[index].splice(i, 1);
|
|
227
|
+
this.size--;
|
|
228
|
+
var loadFactor = this.size / this.table.length;
|
|
229
|
+
if (loadFactor < this.loadFactor / this.capacityMultiplier) {
|
|
230
|
+
this.resizeTable(this.table.length / this.capacityMultiplier);
|
|
231
|
+
}
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
};
|
|
236
|
+
HashMap.prototype.entries = function () {
|
|
237
|
+
var _a, _b, bucket, bucket_2, bucket_2_1, _c, key, value, e_4_1, e_5_1;
|
|
238
|
+
var e_5, _d, e_4, _e;
|
|
239
|
+
return __generator(this, function (_f) {
|
|
240
|
+
switch (_f.label) {
|
|
241
|
+
case 0:
|
|
242
|
+
_f.trys.push([0, 11, 12, 13]);
|
|
243
|
+
_a = __values(this.table), _b = _a.next();
|
|
244
|
+
_f.label = 1;
|
|
245
|
+
case 1:
|
|
246
|
+
if (!!_b.done) return [3, 10];
|
|
247
|
+
bucket = _b.value;
|
|
248
|
+
if (!bucket) return [3, 9];
|
|
249
|
+
_f.label = 2;
|
|
250
|
+
case 2:
|
|
251
|
+
_f.trys.push([2, 7, 8, 9]);
|
|
252
|
+
bucket_2 = (e_4 = void 0, __values(bucket)), bucket_2_1 = bucket_2.next();
|
|
253
|
+
_f.label = 3;
|
|
254
|
+
case 3:
|
|
255
|
+
if (!!bucket_2_1.done) return [3, 6];
|
|
256
|
+
_c = __read(bucket_2_1.value, 2), key = _c[0], value = _c[1];
|
|
257
|
+
return [4, [key, value]];
|
|
258
|
+
case 4:
|
|
259
|
+
_f.sent();
|
|
260
|
+
_f.label = 5;
|
|
261
|
+
case 5:
|
|
262
|
+
bucket_2_1 = bucket_2.next();
|
|
263
|
+
return [3, 3];
|
|
264
|
+
case 6: return [3, 9];
|
|
265
|
+
case 7:
|
|
266
|
+
e_4_1 = _f.sent();
|
|
267
|
+
e_4 = { error: e_4_1 };
|
|
268
|
+
return [3, 9];
|
|
269
|
+
case 8:
|
|
270
|
+
try {
|
|
271
|
+
if (bucket_2_1 && !bucket_2_1.done && (_e = bucket_2.return)) _e.call(bucket_2);
|
|
272
|
+
}
|
|
273
|
+
finally { if (e_4) throw e_4.error; }
|
|
274
|
+
return [7];
|
|
275
|
+
case 9:
|
|
276
|
+
_b = _a.next();
|
|
277
|
+
return [3, 1];
|
|
278
|
+
case 10: return [3, 13];
|
|
279
|
+
case 11:
|
|
280
|
+
e_5_1 = _f.sent();
|
|
281
|
+
e_5 = { error: e_5_1 };
|
|
282
|
+
return [3, 13];
|
|
283
|
+
case 12:
|
|
284
|
+
try {
|
|
285
|
+
if (_b && !_b.done && (_d = _a.return)) _d.call(_a);
|
|
286
|
+
}
|
|
287
|
+
finally { if (e_5) throw e_5.error; }
|
|
288
|
+
return [7];
|
|
289
|
+
case 13: return [2];
|
|
290
|
+
}
|
|
291
|
+
});
|
|
292
|
+
};
|
|
293
|
+
HashMap.prototype[Symbol.iterator] = function () {
|
|
294
|
+
return this.entries();
|
|
295
|
+
};
|
|
296
|
+
HashMap.prototype.clear = function () {
|
|
297
|
+
this.size = 0;
|
|
298
|
+
this.table = new Array(this.initialCapacity);
|
|
299
|
+
};
|
|
300
|
+
HashMap.prototype.isEmpty = function () {
|
|
301
|
+
return this.size === 0;
|
|
302
|
+
};
|
|
303
|
+
return HashMap;
|
|
304
|
+
}());
|
|
305
|
+
exports.HashMap = HashMap;
|
|
306
|
+
//# sourceMappingURL=hash-map.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hash-map.js","sourceRoot":"","sources":["../../../src/data-structures/hash/hash-map.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AASA;IAmEE,iBAAY,eAAoB,EAAE,UAAiB,EAAE,MAAwB;QAAjE,gCAAA,EAAA,oBAAoB;QAAE,2BAAA,EAAA,iBA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