@calcit/ternary-tree 0.0.16 → 0.0.19-a1
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/lib/{hash.d.ts → hash.d.mts} +0 -0
- package/lib/{hash.js → hash.mjs} +0 -0
- package/lib/index.d.mts +4 -0
- package/lib/index.mjs +4 -0
- package/lib/{list.d.ts → list.d.mts} +2 -1
- package/lib/{list.js → list.mjs} +12 -4
- package/lib/main.d.mts +2 -0
- package/lib/{main.js → main.mjs} +6 -6
- package/lib/{map.d.ts → map.d.mts} +3 -2
- package/lib/{map.js → map.mjs} +62 -29
- package/lib/{test-list.d.ts → test-list.d.mts} +0 -0
- package/lib/{test-list.js → test-list.mjs} +24 -3
- package/lib/{test-map.d.ts → test-map.d.mts} +0 -0
- package/lib/{test-map.js → test-map.mjs} +18 -18
- package/lib/{types.d.ts → types.d.mts} +0 -0
- package/lib/{types.js → types.mjs} +0 -0
- package/lib/{utils.d.ts → utils.d.mts} +2 -2
- package/lib/{utils.js → utils.mjs} +3 -3
- package/package.json +9 -7
- package/assets/index.html +0 -2
- package/lib/bundle.js +0 -2979
- package/lib/bundle.js.map +0 -1
- package/lib/index.d.ts +0 -4
- package/lib/index.js +0 -4
- package/lib/main.d.ts +0 -2
- package/src/costs.nim +0 -62
- package/src/hash.ts +0 -78
- package/src/index.ts +0 -5
- package/src/list.ts +0 -987
- package/src/main.ts +0 -20
- package/src/map.ts +0 -1307
- package/src/shape.nim +0 -62
- package/src/test-list.ts +0 -264
- package/src/test-map.ts +0 -287
- package/src/types.ts +0 -87
- package/src/utils.ts +0 -124
package/lib/bundle.js
DELETED
@@ -1,2979 +0,0 @@
|
|
1
|
-
/******/ (() => { // webpackBootstrap
|
2
|
-
/******/ "use strict";
|
3
|
-
/******/ var __webpack_modules__ = ({
|
4
|
-
|
5
|
-
/***/ "./lib/list.js":
|
6
|
-
/*!*********************!*\
|
7
|
-
!*** ./lib/list.js ***!
|
8
|
-
\*********************/
|
9
|
-
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
10
|
-
|
11
|
-
__webpack_require__.r(__webpack_exports__);
|
12
|
-
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
13
|
-
/* harmony export */ "getDepth": () => /* binding */ getDepth,
|
14
|
-
/* harmony export */ "makeTernaryTreeList": () => /* binding */ makeTernaryTreeList,
|
15
|
-
/* harmony export */ "initTernaryTreeList": () => /* binding */ initTernaryTreeList,
|
16
|
-
/* harmony export */ "initEmptyTernaryTreeList": () => /* binding */ initEmptyTernaryTreeList,
|
17
|
-
/* harmony export */ "listToString": () => /* binding */ listToString,
|
18
|
-
/* harmony export */ "listLen": () => /* binding */ listLen,
|
19
|
-
/* harmony export */ "formatListInline": () => /* binding */ formatListInline,
|
20
|
-
/* harmony export */ "listToItems": () => /* binding */ listToItems,
|
21
|
-
/* harmony export */ "findIndex": () => /* binding */ findIndex,
|
22
|
-
/* harmony export */ "indexOf": () => /* binding */ indexOf,
|
23
|
-
/* harmony export */ "indexToItems": () => /* binding */ indexToItems,
|
24
|
-
/* harmony export */ "listToPairs": () => /* binding */ listToPairs,
|
25
|
-
/* harmony export */ "listGet": () => /* binding */ listGet,
|
26
|
-
/* harmony export */ "first": () => /* binding */ first,
|
27
|
-
/* harmony export */ "last": () => /* binding */ last,
|
28
|
-
/* harmony export */ "assocList": () => /* binding */ assocList,
|
29
|
-
/* harmony export */ "dissocList": () => /* binding */ dissocList,
|
30
|
-
/* harmony export */ "rest": () => /* binding */ rest,
|
31
|
-
/* harmony export */ "butlast": () => /* binding */ butlast,
|
32
|
-
/* harmony export */ "insert": () => /* binding */ insert,
|
33
|
-
/* harmony export */ "assocBefore": () => /* binding */ assocBefore,
|
34
|
-
/* harmony export */ "assocAfter": () => /* binding */ assocAfter,
|
35
|
-
/* harmony export */ "forceListInplaceBalancing": () => /* binding */ forceListInplaceBalancing,
|
36
|
-
/* harmony export */ "prepend": () => /* binding */ prepend,
|
37
|
-
/* harmony export */ "append": () => /* binding */ append,
|
38
|
-
/* harmony export */ "concat": () => /* binding */ concat,
|
39
|
-
/* harmony export */ "sameListShape": () => /* binding */ sameListShape,
|
40
|
-
/* harmony export */ "listEqual": () => /* binding */ listEqual,
|
41
|
-
/* harmony export */ "checkListStructure": () => /* binding */ checkListStructure,
|
42
|
-
/* harmony export */ "slice": () => /* binding */ slice,
|
43
|
-
/* harmony export */ "reverse": () => /* binding */ reverse,
|
44
|
-
/* harmony export */ "listMapValues": () => /* binding */ listMapValues
|
45
|
-
/* harmony export */ });
|
46
|
-
/* harmony import */ var _types__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./types */ "./lib/types.js");
|
47
|
-
/* harmony import */ var _map__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./map */ "./lib/map.js");
|
48
|
-
/* harmony import */ var _utils__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./utils */ "./lib/utils.js");
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
// just get, will not compute recursively
|
53
|
-
function getDepth(tree) {
|
54
|
-
if (tree == null)
|
55
|
-
return 0;
|
56
|
-
switch (tree.kind) {
|
57
|
-
case _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeLeaf:
|
58
|
-
return 1;
|
59
|
-
case _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeBranch:
|
60
|
-
return tree.depth;
|
61
|
-
}
|
62
|
-
}
|
63
|
-
let emptyBranch = null;
|
64
|
-
let isEmptyBranch = (x) => {
|
65
|
-
if (x == null) {
|
66
|
-
return true;
|
67
|
-
}
|
68
|
-
return x.size == 0;
|
69
|
-
};
|
70
|
-
function decideParentDepth(...xs) {
|
71
|
-
let depth = 0;
|
72
|
-
for (let i = 0; i < xs.length; i++) {
|
73
|
-
let x = xs[i];
|
74
|
-
let y = getDepth(x);
|
75
|
-
if (y > depth) {
|
76
|
-
depth = y;
|
77
|
-
}
|
78
|
-
}
|
79
|
-
return depth + 1;
|
80
|
-
}
|
81
|
-
function makeTernaryTreeList(size, offset, xs) {
|
82
|
-
switch (size) {
|
83
|
-
case 0: {
|
84
|
-
return { kind: _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeBranch, size: 0, depth: 1, left: emptyBranch, middle: emptyBranch, right: emptyBranch };
|
85
|
-
}
|
86
|
-
case 1:
|
87
|
-
return xs[offset];
|
88
|
-
case 2: {
|
89
|
-
let left = xs[offset];
|
90
|
-
let middle = xs[offset + 1];
|
91
|
-
let result = {
|
92
|
-
kind: _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeBranch,
|
93
|
-
size: listLen(left) + listLen(middle),
|
94
|
-
left: left,
|
95
|
-
middle: middle,
|
96
|
-
right: emptyBranch,
|
97
|
-
depth: decideParentDepth(left, middle),
|
98
|
-
};
|
99
|
-
return result;
|
100
|
-
}
|
101
|
-
case 3: {
|
102
|
-
let left = xs[offset];
|
103
|
-
let middle = xs[offset + 1];
|
104
|
-
let right = xs[offset + 2];
|
105
|
-
let result = {
|
106
|
-
kind: _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeBranch,
|
107
|
-
size: listLen(left) + listLen(middle) + listLen(right),
|
108
|
-
left: left,
|
109
|
-
middle: middle,
|
110
|
-
right: right,
|
111
|
-
depth: decideParentDepth(left, middle, right),
|
112
|
-
};
|
113
|
-
return result;
|
114
|
-
}
|
115
|
-
default: {
|
116
|
-
let divided = (0,_utils__WEBPACK_IMPORTED_MODULE_2__.divideTernarySizes)(size);
|
117
|
-
let left = makeTernaryTreeList(divided.left, offset, xs);
|
118
|
-
let middle = makeTernaryTreeList(divided.middle, offset + divided.left, xs);
|
119
|
-
let right = makeTernaryTreeList(divided.right, offset + divided.left + divided.middle, xs);
|
120
|
-
let result = {
|
121
|
-
kind: _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeBranch,
|
122
|
-
size: listLen(left) + listLen(middle) + listLen(right),
|
123
|
-
depth: decideParentDepth(left, middle, right),
|
124
|
-
left: left,
|
125
|
-
middle: middle,
|
126
|
-
right: right,
|
127
|
-
};
|
128
|
-
return result;
|
129
|
-
}
|
130
|
-
}
|
131
|
-
}
|
132
|
-
function initTernaryTreeList(xs) {
|
133
|
-
let ys = new Array(xs.length);
|
134
|
-
let size = xs.length;
|
135
|
-
for (let idx = 0; idx < size; idx++) {
|
136
|
-
let x = xs[idx];
|
137
|
-
ys[idx] = { kind: _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeLeaf, size: 1, value: x };
|
138
|
-
}
|
139
|
-
return makeTernaryTreeList(xs.length, 0, ys);
|
140
|
-
}
|
141
|
-
function initEmptyTernaryTreeList() {
|
142
|
-
return { kind: _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeBranch, size: 0, depth: 1, middle: emptyBranch, left: emptyBranch, right: emptyBranch };
|
143
|
-
}
|
144
|
-
function listToString(tree) {
|
145
|
-
return `TernaryTreeList[${tree.size}, ...]`;
|
146
|
-
}
|
147
|
-
function listLen(tree) {
|
148
|
-
if (tree == null) {
|
149
|
-
return 0;
|
150
|
-
}
|
151
|
-
else {
|
152
|
-
return tree.size;
|
153
|
-
}
|
154
|
-
}
|
155
|
-
function isLeaf(tree) {
|
156
|
-
return tree.kind === _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeLeaf;
|
157
|
-
}
|
158
|
-
function isBranch(tree) {
|
159
|
-
return tree.kind === _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeBranch;
|
160
|
-
}
|
161
|
-
function formatListInline(tree) {
|
162
|
-
if (tree == null) {
|
163
|
-
return "_";
|
164
|
-
}
|
165
|
-
switch (tree.kind) {
|
166
|
-
case _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeLeaf:
|
167
|
-
return `${tree.value}`;
|
168
|
-
case _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeBranch:
|
169
|
-
return "(" + formatListInline(tree.left) + " " + formatListInline(tree.middle) + " " + formatListInline(tree.right) + ")";
|
170
|
-
// "(" & tree.left.formatListInline & " " & tree.middle.formatListInline & " " & tree.right.formatListInline & ")@{tree.depth} " & "{tree.left.getDepth} {tree.middle.getDepth} {tree.right.getDepth}..."
|
171
|
-
}
|
172
|
-
}
|
173
|
-
function* listToItems(tree) {
|
174
|
-
if (tree != null) {
|
175
|
-
switch (tree.kind) {
|
176
|
-
case _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeLeaf: {
|
177
|
-
yield tree.value;
|
178
|
-
break;
|
179
|
-
}
|
180
|
-
case _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeBranch: {
|
181
|
-
if (tree.left != null) {
|
182
|
-
for (let x of listToItems(tree.left)) {
|
183
|
-
yield x;
|
184
|
-
}
|
185
|
-
}
|
186
|
-
if (tree.middle != null) {
|
187
|
-
for (let x of listToItems(tree.middle)) {
|
188
|
-
yield x;
|
189
|
-
}
|
190
|
-
}
|
191
|
-
if (tree.right != null) {
|
192
|
-
for (let x of listToItems(tree.right)) {
|
193
|
-
yield x;
|
194
|
-
}
|
195
|
-
}
|
196
|
-
break;
|
197
|
-
}
|
198
|
-
}
|
199
|
-
}
|
200
|
-
}
|
201
|
-
// returns -1 if (not foun)
|
202
|
-
function findIndex(tree, f) {
|
203
|
-
if (tree == null) {
|
204
|
-
return -1;
|
205
|
-
}
|
206
|
-
switch (tree.kind) {
|
207
|
-
case _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeLeaf: {
|
208
|
-
if (f(tree.value)) {
|
209
|
-
return 0;
|
210
|
-
}
|
211
|
-
else {
|
212
|
-
return -1;
|
213
|
-
}
|
214
|
-
}
|
215
|
-
case _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeBranch: {
|
216
|
-
let tryLeft = findIndex(tree.left, f);
|
217
|
-
if (tryLeft >= 0) {
|
218
|
-
return tryLeft;
|
219
|
-
}
|
220
|
-
let tryMiddle = findIndex(tree.middle, f);
|
221
|
-
if (tryMiddle >= 0) {
|
222
|
-
return tryMiddle + listLen(tree.left);
|
223
|
-
}
|
224
|
-
let tryRight = findIndex(tree.right, f);
|
225
|
-
if (tryRight >= 0) {
|
226
|
-
return tryRight + listLen(tree.left) + listLen(tree.middle);
|
227
|
-
}
|
228
|
-
return -1;
|
229
|
-
}
|
230
|
-
}
|
231
|
-
}
|
232
|
-
// returns -1 if (not foun)
|
233
|
-
function indexOf(tree, item) {
|
234
|
-
if (tree == null) {
|
235
|
-
return -1;
|
236
|
-
}
|
237
|
-
switch (tree.kind) {
|
238
|
-
case _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeLeaf:
|
239
|
-
if ((0,_utils__WEBPACK_IMPORTED_MODULE_2__.dataEqual)(item, tree.value)) {
|
240
|
-
return 0;
|
241
|
-
}
|
242
|
-
default:
|
243
|
-
return -1;
|
244
|
-
case _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeBranch:
|
245
|
-
let tryLeft = indexOf(tree.left, item);
|
246
|
-
if (tryLeft >= 0) {
|
247
|
-
return tryLeft;
|
248
|
-
}
|
249
|
-
let tryMiddle = indexOf(tree.middle, item);
|
250
|
-
if (tryMiddle >= 0) {
|
251
|
-
return tryMiddle + listLen(tree.left);
|
252
|
-
}
|
253
|
-
let tryRight = indexOf(tree.right, item);
|
254
|
-
if (tryRight >= 0) {
|
255
|
-
return tryRight + listLen(tree.left) + listLen(tree.middle);
|
256
|
-
}
|
257
|
-
return -1;
|
258
|
-
}
|
259
|
-
}
|
260
|
-
function writeLeavesArray(tree, acc, idx) {
|
261
|
-
if (tree == null) {
|
262
|
-
//
|
263
|
-
}
|
264
|
-
else {
|
265
|
-
switch (tree.kind) {
|
266
|
-
case _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeLeaf: {
|
267
|
-
acc[idx.value] = tree;
|
268
|
-
idx.value = idx.value + 1;
|
269
|
-
break;
|
270
|
-
}
|
271
|
-
case _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeBranch: {
|
272
|
-
if (tree.left != null) {
|
273
|
-
writeLeavesArray(tree.left, acc, idx);
|
274
|
-
}
|
275
|
-
if (tree.middle != null) {
|
276
|
-
writeLeavesArray(tree.middle, acc, idx);
|
277
|
-
}
|
278
|
-
if (tree.right != null) {
|
279
|
-
writeLeavesArray(tree.right, acc, idx);
|
280
|
-
}
|
281
|
-
break;
|
282
|
-
}
|
283
|
-
default: {
|
284
|
-
throw new Error("Unknown");
|
285
|
-
}
|
286
|
-
}
|
287
|
-
}
|
288
|
-
}
|
289
|
-
function toLeavesArray(tree) {
|
290
|
-
let acc = new Array(listLen(tree));
|
291
|
-
let counter = { value: 0 };
|
292
|
-
writeLeavesArray(tree, acc, counter);
|
293
|
-
return acc;
|
294
|
-
}
|
295
|
-
function* indexToItems(tree) {
|
296
|
-
for (let idx = 0; idx < listLen(tree); idx++) {
|
297
|
-
yield listGet(tree, idx);
|
298
|
-
}
|
299
|
-
}
|
300
|
-
function* listToPairs(tree) {
|
301
|
-
let idx = 0;
|
302
|
-
for (let x of listToItems(tree)) {
|
303
|
-
yield [idx, x];
|
304
|
-
idx = idx + 1;
|
305
|
-
}
|
306
|
-
}
|
307
|
-
function listGet(originalTree, originalIdx) {
|
308
|
-
let tree = originalTree;
|
309
|
-
let idx = originalIdx;
|
310
|
-
while (tree != null) {
|
311
|
-
if (idx < 0) {
|
312
|
-
throw new Error("Cannot index negative number");
|
313
|
-
}
|
314
|
-
if (tree.kind === _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeLeaf) {
|
315
|
-
if (idx === 0) {
|
316
|
-
return tree.value;
|
317
|
-
}
|
318
|
-
else {
|
319
|
-
throw new Error(`Cannot get from leaf with index ${idx}`);
|
320
|
-
}
|
321
|
-
}
|
322
|
-
if (idx > tree.size - 1) {
|
323
|
-
throw new Error("Index too large");
|
324
|
-
}
|
325
|
-
let leftSize = tree.left == null ? 0 : tree.left.size;
|
326
|
-
let middleSize = tree.middle == null ? 0 : tree.middle.size;
|
327
|
-
let rightSize = tree.right == null ? 0 : tree.right.size;
|
328
|
-
if (leftSize + middleSize + rightSize !== tree.size) {
|
329
|
-
throw new Error("tree.size does not match sum case branch sizes");
|
330
|
-
}
|
331
|
-
if (idx <= leftSize - 1) {
|
332
|
-
tree = tree.left;
|
333
|
-
}
|
334
|
-
else if (idx <= leftSize + middleSize - 1) {
|
335
|
-
tree = tree.middle;
|
336
|
-
idx = idx - leftSize;
|
337
|
-
}
|
338
|
-
else {
|
339
|
-
tree = tree.right;
|
340
|
-
idx = idx - leftSize - middleSize;
|
341
|
-
}
|
342
|
-
}
|
343
|
-
throw new Error(`Failed to get ${idx}`);
|
344
|
-
}
|
345
|
-
function first(tree) {
|
346
|
-
if (listLen(tree) > 0) {
|
347
|
-
return listGet(tree, 0);
|
348
|
-
}
|
349
|
-
else {
|
350
|
-
throw new Error("Cannot get from empty list");
|
351
|
-
}
|
352
|
-
}
|
353
|
-
function last(tree) {
|
354
|
-
if (listLen(tree) > 0) {
|
355
|
-
return listGet(tree, listLen(tree) - 1);
|
356
|
-
}
|
357
|
-
else {
|
358
|
-
throw new Error("Cannot get from empty list");
|
359
|
-
}
|
360
|
-
}
|
361
|
-
function assocList(tree, idx, item) {
|
362
|
-
if (idx < 0) {
|
363
|
-
throw new Error("Cannot index negative number");
|
364
|
-
}
|
365
|
-
if (idx > tree.size - 1) {
|
366
|
-
throw new Error("Index too large");
|
367
|
-
}
|
368
|
-
if (tree.kind === _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeLeaf) {
|
369
|
-
if (idx === 0) {
|
370
|
-
return { kind: _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeLeaf, size: 1, value: item };
|
371
|
-
}
|
372
|
-
else {
|
373
|
-
throw new Error(`Cannot get from leaf with index ${idx}`);
|
374
|
-
}
|
375
|
-
}
|
376
|
-
let leftSize = listLen(tree.left);
|
377
|
-
let middleSize = listLen(tree.middle);
|
378
|
-
let rightSize = listLen(tree.right);
|
379
|
-
if (leftSize + middleSize + rightSize !== tree.size)
|
380
|
-
throw new Error("tree.size does not match sum case branch sizes");
|
381
|
-
if (idx <= leftSize - 1) {
|
382
|
-
let changedBranch = assocList(tree.left, idx, item);
|
383
|
-
let result = {
|
384
|
-
kind: _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeBranch,
|
385
|
-
size: tree.size,
|
386
|
-
depth: decideParentDepth(changedBranch, tree.middle, tree.right),
|
387
|
-
left: changedBranch,
|
388
|
-
middle: tree.middle,
|
389
|
-
right: tree.right,
|
390
|
-
};
|
391
|
-
return result;
|
392
|
-
}
|
393
|
-
else if (idx <= leftSize + middleSize - 1) {
|
394
|
-
let changedBranch = assocList(tree.middle, idx - leftSize, item);
|
395
|
-
let result = {
|
396
|
-
kind: _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeBranch,
|
397
|
-
size: tree.size,
|
398
|
-
depth: decideParentDepth(tree.left, changedBranch, tree.right),
|
399
|
-
left: tree.left,
|
400
|
-
middle: changedBranch,
|
401
|
-
right: tree.right,
|
402
|
-
};
|
403
|
-
return result;
|
404
|
-
}
|
405
|
-
else {
|
406
|
-
let changedBranch = assocList(tree.right, idx - leftSize - middleSize, item);
|
407
|
-
let result = {
|
408
|
-
kind: _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeBranch,
|
409
|
-
size: tree.size,
|
410
|
-
depth: decideParentDepth(tree.left, tree.middle, changedBranch),
|
411
|
-
left: tree.left,
|
412
|
-
middle: tree.middle,
|
413
|
-
right: changedBranch,
|
414
|
-
};
|
415
|
-
return result;
|
416
|
-
}
|
417
|
-
}
|
418
|
-
function dissocList(tree, idx) {
|
419
|
-
if (tree == null) {
|
420
|
-
throw new Error("dissoc does not work on null");
|
421
|
-
}
|
422
|
-
if (idx < 0) {
|
423
|
-
throw new Error(`Index is negative ${idx}`);
|
424
|
-
}
|
425
|
-
if (listLen(tree) === 0) {
|
426
|
-
throw new Error("Cannot remove from empty list");
|
427
|
-
}
|
428
|
-
if (idx > listLen(tree) - 1) {
|
429
|
-
throw new Error(`Index too large ${idx}`);
|
430
|
-
}
|
431
|
-
if (listLen(tree) === 1) {
|
432
|
-
return emptyBranch;
|
433
|
-
}
|
434
|
-
if (tree.kind === _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeLeaf) {
|
435
|
-
throw new Error("dissoc should be handled at branches");
|
436
|
-
}
|
437
|
-
let leftSize = listLen(tree.left);
|
438
|
-
let middleSize = listLen(tree.middle);
|
439
|
-
let rightSize = listLen(tree.right);
|
440
|
-
if (leftSize + middleSize + rightSize !== tree.size) {
|
441
|
-
throw new Error("tree.size does not match sum from branch sizes");
|
442
|
-
}
|
443
|
-
let result = emptyBranch;
|
444
|
-
if (idx <= leftSize - 1) {
|
445
|
-
let changedBranch = dissocList(tree.left, idx);
|
446
|
-
if (changedBranch == null || changedBranch.size === 0) {
|
447
|
-
result = {
|
448
|
-
kind: _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeBranch,
|
449
|
-
size: tree.size - 1,
|
450
|
-
depth: decideParentDepth(tree.middle, tree.right),
|
451
|
-
left: tree.middle,
|
452
|
-
middle: tree.right,
|
453
|
-
right: emptyBranch,
|
454
|
-
};
|
455
|
-
}
|
456
|
-
else {
|
457
|
-
result = {
|
458
|
-
kind: _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeBranch,
|
459
|
-
size: tree.size - 1,
|
460
|
-
depth: decideParentDepth(changedBranch, tree.middle, tree.right),
|
461
|
-
left: changedBranch,
|
462
|
-
middle: tree.middle,
|
463
|
-
right: tree.right,
|
464
|
-
};
|
465
|
-
}
|
466
|
-
}
|
467
|
-
else if (idx <= leftSize + middleSize - 1) {
|
468
|
-
let changedBranch = dissocList(tree.middle, idx - leftSize);
|
469
|
-
if (changedBranch == null || changedBranch.size === 0) {
|
470
|
-
result = {
|
471
|
-
kind: _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeBranch,
|
472
|
-
size: tree.size - 1,
|
473
|
-
depth: decideParentDepth(tree.left, changedBranch, tree.right),
|
474
|
-
left: tree.left,
|
475
|
-
middle: tree.right,
|
476
|
-
right: emptyBranch,
|
477
|
-
};
|
478
|
-
}
|
479
|
-
else {
|
480
|
-
result = {
|
481
|
-
kind: _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeBranch,
|
482
|
-
size: tree.size - 1,
|
483
|
-
depth: decideParentDepth(tree.left, changedBranch, tree.right),
|
484
|
-
left: tree.left,
|
485
|
-
middle: changedBranch,
|
486
|
-
right: tree.right,
|
487
|
-
};
|
488
|
-
}
|
489
|
-
}
|
490
|
-
else {
|
491
|
-
let changedBranch = dissocList(tree.right, idx - leftSize - middleSize);
|
492
|
-
if (changedBranch == null || changedBranch.size === 0) {
|
493
|
-
changedBranch = emptyBranch;
|
494
|
-
}
|
495
|
-
result = {
|
496
|
-
kind: _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeBranch,
|
497
|
-
size: tree.size - 1,
|
498
|
-
depth: decideParentDepth(tree.left, tree.middle, changedBranch),
|
499
|
-
left: tree.left,
|
500
|
-
middle: tree.middle,
|
501
|
-
right: changedBranch,
|
502
|
-
};
|
503
|
-
}
|
504
|
-
if (result.middle == null) {
|
505
|
-
return result.left;
|
506
|
-
}
|
507
|
-
return result;
|
508
|
-
}
|
509
|
-
function rest(tree) {
|
510
|
-
if (tree == null) {
|
511
|
-
throw new Error("Cannot call rest on null");
|
512
|
-
}
|
513
|
-
if (listLen(tree) < 1) {
|
514
|
-
throw new Error("Cannot call rest on empty list");
|
515
|
-
}
|
516
|
-
return dissocList(tree, 0);
|
517
|
-
}
|
518
|
-
function butlast(tree) {
|
519
|
-
if (tree == null) {
|
520
|
-
throw new Error("Cannot call butlast on null");
|
521
|
-
}
|
522
|
-
if (listLen(tree) < 1) {
|
523
|
-
throw new Error("Cannot call butlast on empty list");
|
524
|
-
}
|
525
|
-
return dissocList(tree, listLen(tree) - 1);
|
526
|
-
}
|
527
|
-
function insert(tree, idx, item, after = false) {
|
528
|
-
if (tree == null) {
|
529
|
-
throw new Error("Cannot insert into null");
|
530
|
-
}
|
531
|
-
if (listLen(tree) === 0) {
|
532
|
-
throw new Error("Empty node is not a correct position for inserting");
|
533
|
-
}
|
534
|
-
if (tree.kind === _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeLeaf) {
|
535
|
-
if (after) {
|
536
|
-
let result = {
|
537
|
-
kind: _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeBranch,
|
538
|
-
depth: getDepth(tree) + 1,
|
539
|
-
size: 2,
|
540
|
-
left: tree,
|
541
|
-
middle: { kind: _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeLeaf, size: 1, value: item },
|
542
|
-
right: emptyBranch,
|
543
|
-
};
|
544
|
-
return result;
|
545
|
-
}
|
546
|
-
else {
|
547
|
-
let result = {
|
548
|
-
kind: _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeBranch,
|
549
|
-
depth: getDepth(tree) + 1,
|
550
|
-
size: 2,
|
551
|
-
left: { kind: _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeLeaf, size: 1, value: item },
|
552
|
-
middle: tree,
|
553
|
-
right: emptyBranch,
|
554
|
-
};
|
555
|
-
return result;
|
556
|
-
}
|
557
|
-
}
|
558
|
-
if (listLen(tree) === 1) {
|
559
|
-
if (after) {
|
560
|
-
// in compact mode, values placed at left
|
561
|
-
let result = {
|
562
|
-
kind: _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeBranch,
|
563
|
-
size: 2,
|
564
|
-
depth: 2,
|
565
|
-
left: tree.left,
|
566
|
-
middle: { kind: _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeLeaf, size: 1, value: item },
|
567
|
-
right: emptyBranch,
|
568
|
-
};
|
569
|
-
return result;
|
570
|
-
}
|
571
|
-
else {
|
572
|
-
let result = {
|
573
|
-
kind: _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeBranch,
|
574
|
-
size: 2,
|
575
|
-
depth: getDepth(tree.middle) + 1,
|
576
|
-
left: { kind: _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeLeaf, size: 1, value: item },
|
577
|
-
middle: tree.left,
|
578
|
-
right: emptyBranch,
|
579
|
-
};
|
580
|
-
return result;
|
581
|
-
}
|
582
|
-
}
|
583
|
-
if (listLen(tree) === 2 && tree.middle != null) {
|
584
|
-
if (after) {
|
585
|
-
if (idx === 0) {
|
586
|
-
let result = {
|
587
|
-
kind: _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeBranch,
|
588
|
-
size: 3,
|
589
|
-
depth: 2,
|
590
|
-
left: tree.left,
|
591
|
-
middle: { kind: _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeLeaf, size: 1, value: item },
|
592
|
-
right: tree.middle,
|
593
|
-
};
|
594
|
-
return result;
|
595
|
-
}
|
596
|
-
if (idx === 1) {
|
597
|
-
let result = {
|
598
|
-
kind: _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeBranch,
|
599
|
-
size: 3,
|
600
|
-
depth: 2,
|
601
|
-
left: tree.left,
|
602
|
-
middle: tree.middle,
|
603
|
-
right: { kind: _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeLeaf, size: 1, value: item },
|
604
|
-
};
|
605
|
-
return result;
|
606
|
-
}
|
607
|
-
else {
|
608
|
-
throw new Error("cannot insert after position 2 since only 2 elements here");
|
609
|
-
}
|
610
|
-
}
|
611
|
-
else {
|
612
|
-
if (idx === 0) {
|
613
|
-
let result = {
|
614
|
-
kind: _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeBranch,
|
615
|
-
size: 3,
|
616
|
-
depth: 2,
|
617
|
-
left: { kind: _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeLeaf, size: 1, value: item },
|
618
|
-
middle: tree.left,
|
619
|
-
right: tree.middle,
|
620
|
-
};
|
621
|
-
return result;
|
622
|
-
}
|
623
|
-
else if (idx === 1) {
|
624
|
-
let result = {
|
625
|
-
kind: _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeBranch,
|
626
|
-
size: 3,
|
627
|
-
depth: 2,
|
628
|
-
left: tree.left,
|
629
|
-
middle: { kind: _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeLeaf, size: 1, value: item },
|
630
|
-
right: tree.middle,
|
631
|
-
};
|
632
|
-
return result;
|
633
|
-
}
|
634
|
-
else {
|
635
|
-
throw new Error("cannot insert before position 2 since only 2 elements here");
|
636
|
-
}
|
637
|
-
}
|
638
|
-
}
|
639
|
-
let leftSize = listLen(tree.left);
|
640
|
-
let middleSize = listLen(tree.middle);
|
641
|
-
let rightSize = listLen(tree.right);
|
642
|
-
if (leftSize + middleSize + rightSize !== tree.size) {
|
643
|
-
throw new Error("tree.size does not match sum case branch sizes");
|
644
|
-
}
|
645
|
-
// echo "picking: ", idx, " ", leftSize, " ", middleSize, " ", rightSize
|
646
|
-
if (idx === 0 && !after) {
|
647
|
-
if (listLen(tree.left) >= listLen(tree.middle) && listLen(tree.left) >= listLen(tree.right)) {
|
648
|
-
let result = {
|
649
|
-
kind: _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeBranch,
|
650
|
-
size: tree.size + 1,
|
651
|
-
depth: tree.depth + 1,
|
652
|
-
left: { kind: _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeLeaf, size: 1, value: item },
|
653
|
-
middle: tree,
|
654
|
-
right: emptyBranch,
|
655
|
-
};
|
656
|
-
return result;
|
657
|
-
}
|
658
|
-
}
|
659
|
-
if (idx === listLen(tree) - 1 && after) {
|
660
|
-
if (listLen(tree.right) >= listLen(tree.middle) && listLen(tree.right) >= listLen(tree.left)) {
|
661
|
-
let result = {
|
662
|
-
kind: _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeBranch,
|
663
|
-
size: tree.size + 1,
|
664
|
-
depth: tree.depth + 1,
|
665
|
-
left: tree,
|
666
|
-
middle: { kind: _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeLeaf, size: 1, value: item },
|
667
|
-
right: emptyBranch,
|
668
|
-
};
|
669
|
-
return result;
|
670
|
-
}
|
671
|
-
}
|
672
|
-
if (after && idx === listLen(tree) - 1 && rightSize === 0 && middleSize >= leftSize) {
|
673
|
-
let result = {
|
674
|
-
kind: _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeBranch,
|
675
|
-
size: tree.size + 1,
|
676
|
-
depth: tree.depth,
|
677
|
-
left: tree.left,
|
678
|
-
middle: tree.middle,
|
679
|
-
right: { kind: _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeLeaf, size: 1, value: item },
|
680
|
-
};
|
681
|
-
return result;
|
682
|
-
}
|
683
|
-
if (!after && idx === 0 && rightSize === 0 && middleSize >= rightSize) {
|
684
|
-
let result = {
|
685
|
-
kind: _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeBranch,
|
686
|
-
size: tree.size + 1,
|
687
|
-
depth: tree.depth,
|
688
|
-
left: { kind: _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeLeaf, size: 1, value: item },
|
689
|
-
middle: tree.left,
|
690
|
-
right: tree.middle,
|
691
|
-
};
|
692
|
-
return result;
|
693
|
-
}
|
694
|
-
if (idx <= leftSize - 1) {
|
695
|
-
let changedBranch = insert(tree.left, idx, item, after);
|
696
|
-
let result = {
|
697
|
-
kind: _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeBranch,
|
698
|
-
size: tree.size + 1,
|
699
|
-
depth: decideParentDepth(changedBranch, tree.middle, tree.right),
|
700
|
-
left: changedBranch,
|
701
|
-
middle: tree.middle,
|
702
|
-
right: tree.right,
|
703
|
-
};
|
704
|
-
return result;
|
705
|
-
}
|
706
|
-
else if (idx <= leftSize + middleSize - 1) {
|
707
|
-
let changedBranch = insert(tree.middle, idx - leftSize, item, after);
|
708
|
-
let result = {
|
709
|
-
kind: _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeBranch,
|
710
|
-
size: tree.size + 1,
|
711
|
-
depth: decideParentDepth(tree.left, changedBranch, tree.right),
|
712
|
-
left: tree.left,
|
713
|
-
middle: changedBranch,
|
714
|
-
right: tree.right,
|
715
|
-
};
|
716
|
-
return result;
|
717
|
-
}
|
718
|
-
else {
|
719
|
-
let changedBranch = insert(tree.right, idx - leftSize - middleSize, item, after);
|
720
|
-
let result = {
|
721
|
-
kind: _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeBranch,
|
722
|
-
size: tree.size + 1,
|
723
|
-
depth: decideParentDepth(tree.left, tree.middle, changedBranch),
|
724
|
-
left: tree.left,
|
725
|
-
middle: tree.middle,
|
726
|
-
right: changedBranch,
|
727
|
-
};
|
728
|
-
return result;
|
729
|
-
}
|
730
|
-
}
|
731
|
-
function assocBefore(tree, idx, item, after = false) {
|
732
|
-
return insert(tree, idx, item, false);
|
733
|
-
}
|
734
|
-
function assocAfter(tree, idx, item, after = false) {
|
735
|
-
return insert(tree, idx, item, true);
|
736
|
-
}
|
737
|
-
// this function mutates original tree to make it more balanced
|
738
|
-
function forceListInplaceBalancing(tree) {
|
739
|
-
if (tree.kind === _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeBranch) {
|
740
|
-
// echo "Force inplace balancing case list: ", tree.size
|
741
|
-
let ys = toLeavesArray(tree);
|
742
|
-
let newTree = makeTernaryTreeList(ys.length, 0, ys);
|
743
|
-
// let newTree = initTernaryTreeList(ys)
|
744
|
-
tree.left = newTree.left;
|
745
|
-
tree.middle = newTree.middle;
|
746
|
-
tree.right = newTree.right;
|
747
|
-
tree.depth = decideParentDepth(tree.left, tree.middle, tree.right);
|
748
|
-
}
|
749
|
-
else {
|
750
|
-
//
|
751
|
-
}
|
752
|
-
}
|
753
|
-
// TODO, need better strategy for detecting
|
754
|
-
function maybeReblance(tree) {
|
755
|
-
let currentDepth = getDepth(tree);
|
756
|
-
if (currentDepth > 50) {
|
757
|
-
if ((0,_utils__WEBPACK_IMPORTED_MODULE_2__.roughIntPow)(3, currentDepth - 50) > tree.size) {
|
758
|
-
forceListInplaceBalancing(tree);
|
759
|
-
}
|
760
|
-
}
|
761
|
-
}
|
762
|
-
function prepend(tree, item, disableBalancing = false) {
|
763
|
-
if (tree == null || listLen(tree) === 0) {
|
764
|
-
return { kind: _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeLeaf, size: 1, value: item };
|
765
|
-
}
|
766
|
-
let result = insert(tree, 0, item, false);
|
767
|
-
if (!disableBalancing) {
|
768
|
-
maybeReblance(result);
|
769
|
-
}
|
770
|
-
return result;
|
771
|
-
}
|
772
|
-
function append(tree, item, disableBalancing = false) {
|
773
|
-
if (tree == null || listLen(tree) === 0) {
|
774
|
-
return { kind: _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeLeaf, size: 1, value: item };
|
775
|
-
}
|
776
|
-
let result = insert(tree, listLen(tree) - 1, item, true);
|
777
|
-
if (!disableBalancing) {
|
778
|
-
maybeReblance(result);
|
779
|
-
}
|
780
|
-
return result;
|
781
|
-
}
|
782
|
-
function concat(...xsGroups) {
|
783
|
-
xsGroups = xsGroups.filter((xs) => listLen(xs) > 0);
|
784
|
-
let result = makeTernaryTreeList(xsGroups.length, 0, xsGroups);
|
785
|
-
maybeReblance(result);
|
786
|
-
return result;
|
787
|
-
}
|
788
|
-
function sameListShape(xs, ys) {
|
789
|
-
if (xs == null) {
|
790
|
-
if (ys == null) {
|
791
|
-
return true;
|
792
|
-
}
|
793
|
-
else {
|
794
|
-
return false;
|
795
|
-
}
|
796
|
-
}
|
797
|
-
if (ys == null) {
|
798
|
-
return false;
|
799
|
-
}
|
800
|
-
if (listLen(xs) !== listLen(ys)) {
|
801
|
-
return false;
|
802
|
-
}
|
803
|
-
if (xs.kind !== ys.kind) {
|
804
|
-
return false;
|
805
|
-
}
|
806
|
-
if (xs.kind === _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeLeaf && ys.kind === _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeLeaf) {
|
807
|
-
if (!(0,_utils__WEBPACK_IMPORTED_MODULE_2__.dataEqual)(xs.value, ys.value)) {
|
808
|
-
return false;
|
809
|
-
}
|
810
|
-
else {
|
811
|
-
return true;
|
812
|
-
}
|
813
|
-
}
|
814
|
-
if (xs.kind === _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeBranch && ys.kind === _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeBranch) {
|
815
|
-
if (!sameListShape(xs.left, ys.left))
|
816
|
-
return false;
|
817
|
-
if (!sameListShape(xs.middle, ys.middle))
|
818
|
-
return false;
|
819
|
-
if (!sameListShape(xs.right, ys.right))
|
820
|
-
return false;
|
821
|
-
return true;
|
822
|
-
}
|
823
|
-
return false;
|
824
|
-
}
|
825
|
-
function listEqual(xs, ys) {
|
826
|
-
if (xs === ys) {
|
827
|
-
return true;
|
828
|
-
}
|
829
|
-
if (listLen(xs) !== listLen(ys)) {
|
830
|
-
return false;
|
831
|
-
}
|
832
|
-
for (let idx = 0; idx < listLen(xs); idx++) {
|
833
|
-
if (!(0,_utils__WEBPACK_IMPORTED_MODULE_2__.dataEqual)(listGet(xs, idx), listGet(ys, idx))) {
|
834
|
-
return false;
|
835
|
-
}
|
836
|
-
}
|
837
|
-
return true;
|
838
|
-
}
|
839
|
-
function checkListStructure(tree) {
|
840
|
-
if (tree == null) {
|
841
|
-
return true;
|
842
|
-
}
|
843
|
-
else {
|
844
|
-
switch (tree.kind) {
|
845
|
-
case _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeLeaf:
|
846
|
-
if (tree.size !== 1) {
|
847
|
-
throw new Error(`Bad size at node ${formatListInline(tree)}`);
|
848
|
-
}
|
849
|
-
break;
|
850
|
-
case _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeBranch: {
|
851
|
-
if (tree.size !== listLen(tree.left) + listLen(tree.middle) + listLen(tree.right)) {
|
852
|
-
throw new Error(`Bad size at branch ${formatListInline(tree)}`);
|
853
|
-
}
|
854
|
-
if (tree.depth !== decideParentDepth(tree.left, tree.middle, tree.right)) {
|
855
|
-
let x = decideParentDepth(tree.left, tree.middle, tree.right);
|
856
|
-
throw new Error(`Bad depth at branch ${formatListInline(tree)}`);
|
857
|
-
}
|
858
|
-
checkListStructure(tree.left);
|
859
|
-
checkListStructure(tree.middle);
|
860
|
-
checkListStructure(tree.right);
|
861
|
-
break;
|
862
|
-
}
|
863
|
-
}
|
864
|
-
return true;
|
865
|
-
}
|
866
|
-
}
|
867
|
-
// excludes value at endIdx, kept aligned with JS & Clojure
|
868
|
-
function slice(tree, startIdx, endIdx) {
|
869
|
-
// echo "slice {tree.formatListInline}: {startIdx}..{endIdx}"
|
870
|
-
if (endIdx > listLen(tree)) {
|
871
|
-
throw new Error("Slice range too large {endIdx} for {tree}");
|
872
|
-
}
|
873
|
-
if (startIdx < 0) {
|
874
|
-
throw new Error("Slice range too small {startIdx} for {tree}");
|
875
|
-
}
|
876
|
-
if (startIdx > endIdx) {
|
877
|
-
throw new Error("Invalid slice range {startIdx}..{endIdx} for {tree}");
|
878
|
-
}
|
879
|
-
if (startIdx === endIdx) {
|
880
|
-
return { kind: _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeBranch, size: 0, depth: 0 };
|
881
|
-
}
|
882
|
-
if (tree.kind === _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeLeaf)
|
883
|
-
if (startIdx === 0 && endIdx === 1) {
|
884
|
-
return tree;
|
885
|
-
}
|
886
|
-
else {
|
887
|
-
throw new Error(`Invalid slice range for a leaf: ${startIdx} ${endIdx}`);
|
888
|
-
}
|
889
|
-
if (startIdx === 0 && endIdx === listLen(tree)) {
|
890
|
-
return tree;
|
891
|
-
}
|
892
|
-
let leftSize = listLen(tree.left);
|
893
|
-
let middleSize = listLen(tree.middle);
|
894
|
-
let rightSize = listLen(tree.right);
|
895
|
-
// echo "sizes: {leftSize} {middleSize} {rightSize}"
|
896
|
-
if (startIdx >= leftSize + middleSize) {
|
897
|
-
return slice(tree.right, startIdx - leftSize - middleSize, endIdx - leftSize - middleSize);
|
898
|
-
}
|
899
|
-
if (startIdx >= leftSize)
|
900
|
-
if (endIdx <= leftSize + middleSize) {
|
901
|
-
return slice(tree.middle, startIdx - leftSize, endIdx - leftSize);
|
902
|
-
}
|
903
|
-
else {
|
904
|
-
let middleCut = slice(tree.middle, startIdx - leftSize, middleSize);
|
905
|
-
let rightCut = slice(tree.right, 0, endIdx - leftSize - middleSize);
|
906
|
-
return concat(middleCut, rightCut);
|
907
|
-
}
|
908
|
-
if (endIdx <= leftSize) {
|
909
|
-
return slice(tree.left, startIdx, endIdx);
|
910
|
-
}
|
911
|
-
if (endIdx <= leftSize + middleSize) {
|
912
|
-
let leftCut = slice(tree.left, startIdx, leftSize);
|
913
|
-
let middleCut = slice(tree.middle, 0, endIdx - leftSize);
|
914
|
-
return concat(leftCut, middleCut);
|
915
|
-
}
|
916
|
-
if (endIdx <= leftSize + middleSize + rightSize) {
|
917
|
-
let leftCut = slice(tree.left, startIdx, leftSize);
|
918
|
-
let rightCut = slice(tree.right, 0, endIdx - leftSize - middleSize);
|
919
|
-
return concat(concat(leftCut, tree.middle), rightCut);
|
920
|
-
}
|
921
|
-
throw new Error("Unknown");
|
922
|
-
}
|
923
|
-
function reverse(tree) {
|
924
|
-
if (tree == null) {
|
925
|
-
return tree;
|
926
|
-
}
|
927
|
-
switch (tree.kind) {
|
928
|
-
case _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeLeaf:
|
929
|
-
return tree;
|
930
|
-
case _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeBranch: {
|
931
|
-
let result = {
|
932
|
-
kind: _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeBranch,
|
933
|
-
size: tree.size,
|
934
|
-
depth: tree.depth,
|
935
|
-
left: reverse(tree.right),
|
936
|
-
middle: reverse(tree.middle),
|
937
|
-
right: reverse(tree.left),
|
938
|
-
};
|
939
|
-
return result;
|
940
|
-
}
|
941
|
-
}
|
942
|
-
}
|
943
|
-
function listMapValues(tree, f) {
|
944
|
-
if (tree == null) {
|
945
|
-
return tree;
|
946
|
-
}
|
947
|
-
switch (tree.kind) {
|
948
|
-
case _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeLeaf: {
|
949
|
-
let result = {
|
950
|
-
kind: _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeLeaf,
|
951
|
-
size: tree.size,
|
952
|
-
value: f(tree.value),
|
953
|
-
};
|
954
|
-
return result;
|
955
|
-
}
|
956
|
-
case _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeBranch: {
|
957
|
-
let result = {
|
958
|
-
kind: _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeBranch,
|
959
|
-
size: tree.size,
|
960
|
-
depth: tree.depth,
|
961
|
-
left: tree.left == null ? emptyBranch : listMapValues(tree.left, f),
|
962
|
-
middle: tree.middle == null ? emptyBranch : listMapValues(tree.middle, f),
|
963
|
-
right: tree.right == null ? emptyBranch : listMapValues(tree.right, f),
|
964
|
-
};
|
965
|
-
return result;
|
966
|
-
}
|
967
|
-
}
|
968
|
-
}
|
969
|
-
|
970
|
-
|
971
|
-
/***/ }),
|
972
|
-
|
973
|
-
/***/ "./lib/main.js":
|
974
|
-
/*!*********************!*\
|
975
|
-
!*** ./lib/main.js ***!
|
976
|
-
\*********************/
|
977
|
-
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
978
|
-
|
979
|
-
__webpack_require__.r(__webpack_exports__);
|
980
|
-
/* harmony import */ var _utils__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./utils */ "./lib/utils.js");
|
981
|
-
/* harmony import */ var _test_list__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./test-list */ "./lib/test-list.js");
|
982
|
-
/* harmony import */ var _test_map__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./test-map */ "./lib/test-map.js");
|
983
|
-
/* harmony import */ var _types__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./types */ "./lib/types.js");
|
984
|
-
|
985
|
-
|
986
|
-
|
987
|
-
|
988
|
-
|
989
|
-
|
990
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_0__.overwriteComparator)((x, y) => {
|
991
|
-
// console.log("comparing", x, y);
|
992
|
-
return (0,_utils__WEBPACK_IMPORTED_MODULE_0__.deepEqual)(x, y);
|
993
|
-
});
|
994
|
-
(0,_types__WEBPACK_IMPORTED_MODULE_3__.overwriteHashGenerator)((x) => {
|
995
|
-
let ret = (0,_types__WEBPACK_IMPORTED_MODULE_3__.mergeValueHash)(10, (0,_types__WEBPACK_IMPORTED_MODULE_3__.valueHash)(x));
|
996
|
-
// console.log("hashing", x, ret);
|
997
|
-
return ret;
|
998
|
-
});
|
999
|
-
(0,_test_list__WEBPACK_IMPORTED_MODULE_1__.runListTests)();
|
1000
|
-
(0,_test_map__WEBPACK_IMPORTED_MODULE_2__.runMapTests)();
|
1001
|
-
|
1002
|
-
|
1003
|
-
/***/ }),
|
1004
|
-
|
1005
|
-
/***/ "./lib/map.js":
|
1006
|
-
/*!********************!*\
|
1007
|
-
!*** ./lib/map.js ***!
|
1008
|
-
\********************/
|
1009
|
-
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
1010
|
-
|
1011
|
-
__webpack_require__.r(__webpack_exports__);
|
1012
|
-
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
1013
|
-
/* harmony export */ "getMapDepth": () => /* binding */ getMapDepth,
|
1014
|
-
/* harmony export */ "initTernaryTreeMapFromHashEntries": () => /* binding */ initTernaryTreeMapFromHashEntries,
|
1015
|
-
/* harmony export */ "initTernaryTreeMap": () => /* binding */ initTernaryTreeMap,
|
1016
|
-
/* harmony export */ "initEmptyTernaryTreeMap": () => /* binding */ initEmptyTernaryTreeMap,
|
1017
|
-
/* harmony export */ "mapToString": () => /* binding */ mapToString,
|
1018
|
-
/* harmony export */ "mapLen": () => /* binding */ mapLen,
|
1019
|
-
/* harmony export */ "mapLenBound": () => /* binding */ mapLenBound,
|
1020
|
-
/* harmony export */ "formatMapInline": () => /* binding */ formatMapInline,
|
1021
|
-
/* harmony export */ "isMapEmpty": () => /* binding */ isMapEmpty,
|
1022
|
-
/* harmony export */ "isMapOfOne": () => /* binding */ isMapOfOne,
|
1023
|
-
/* harmony export */ "toHashSortedPairs": () => /* binding */ toHashSortedPairs,
|
1024
|
-
/* harmony export */ "contains": () => /* binding */ contains,
|
1025
|
-
/* harmony export */ "mapGetDefault": () => /* binding */ mapGetDefault,
|
1026
|
-
/* harmony export */ "checkMapStructure": () => /* binding */ checkMapStructure,
|
1027
|
-
/* harmony export */ "assocMap": () => /* binding */ assocMap,
|
1028
|
-
/* harmony export */ "dissocMap": () => /* binding */ dissocMap,
|
1029
|
-
/* harmony export */ "toPairsArray": () => /* binding */ toPairsArray,
|
1030
|
-
/* harmony export */ "toPairs": () => /* binding */ toPairs,
|
1031
|
-
/* harmony export */ "toKeys": () => /* binding */ toKeys,
|
1032
|
-
/* harmony export */ "toValues": () => /* binding */ toValues,
|
1033
|
-
/* harmony export */ "mapEqual": () => /* binding */ mapEqual,
|
1034
|
-
/* harmony export */ "merge": () => /* binding */ merge,
|
1035
|
-
/* harmony export */ "mergeSkip": () => /* binding */ mergeSkip,
|
1036
|
-
/* harmony export */ "forceMapInplaceBalancing": () => /* binding */ forceMapInplaceBalancing,
|
1037
|
-
/* harmony export */ "sameMapShape": () => /* binding */ sameMapShape,
|
1038
|
-
/* harmony export */ "mapMapValues": () => /* binding */ mapMapValues
|
1039
|
-
/* harmony export */ });
|
1040
|
-
/* harmony import */ var _types__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./types */ "./lib/types.js");
|
1041
|
-
/* harmony import */ var _utils__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./utils */ "./lib/utils.js");
|
1042
|
-
|
1043
|
-
|
1044
|
-
let emptyBranch = null;
|
1045
|
-
let nilResult = null;
|
1046
|
-
function getMax(tree) {
|
1047
|
-
if (tree == null) {
|
1048
|
-
throw new Error("Cannot find max hash of nil");
|
1049
|
-
}
|
1050
|
-
switch (tree.kind) {
|
1051
|
-
case _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeLeaf:
|
1052
|
-
return tree.hash;
|
1053
|
-
case _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeBranch:
|
1054
|
-
return tree.maxHash;
|
1055
|
-
default:
|
1056
|
-
throw new Error("Unknown");
|
1057
|
-
}
|
1058
|
-
}
|
1059
|
-
function getMin(tree) {
|
1060
|
-
if (tree == null) {
|
1061
|
-
throw new Error("Cannot find min hash of nil");
|
1062
|
-
}
|
1063
|
-
switch (tree.kind) {
|
1064
|
-
case _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeLeaf:
|
1065
|
-
return tree.hash;
|
1066
|
-
case _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeBranch:
|
1067
|
-
return tree.minHash;
|
1068
|
-
default:
|
1069
|
-
throw new Error("Unknown");
|
1070
|
-
}
|
1071
|
-
}
|
1072
|
-
function getMapDepth(tree) {
|
1073
|
-
// console.log( "calling...", tree)
|
1074
|
-
if (tree == null) {
|
1075
|
-
return 0;
|
1076
|
-
}
|
1077
|
-
switch (tree.kind) {
|
1078
|
-
case _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeLeaf:
|
1079
|
-
return 1;
|
1080
|
-
case _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeBranch:
|
1081
|
-
return Math.max(getMapDepth(tree.left), getMapDepth(tree.middle), getMapDepth(tree.right)) + 1;
|
1082
|
-
default:
|
1083
|
-
throw new Error("Unknown");
|
1084
|
-
}
|
1085
|
-
}
|
1086
|
-
function createLeaf(k, v) {
|
1087
|
-
let result = {
|
1088
|
-
kind: _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeLeaf,
|
1089
|
-
hash: (0,_types__WEBPACK_IMPORTED_MODULE_0__.hashGenerator)(k),
|
1090
|
-
elements: [[k, v]],
|
1091
|
-
};
|
1092
|
-
return result;
|
1093
|
-
}
|
1094
|
-
function createLeafFromHashEntry(item) {
|
1095
|
-
let result = {
|
1096
|
-
kind: _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeLeaf,
|
1097
|
-
hash: item.hash,
|
1098
|
-
elements: item.pairs,
|
1099
|
-
};
|
1100
|
-
return result;
|
1101
|
-
}
|
1102
|
-
// this proc is not exported, pick up next proc as the entry.
|
1103
|
-
// pairs must be sorted before passing to proc.
|
1104
|
-
function makeTernaryTreeMap(size, offset, xs) {
|
1105
|
-
switch (size) {
|
1106
|
-
case 0: {
|
1107
|
-
let result = emptyBranch;
|
1108
|
-
return result;
|
1109
|
-
}
|
1110
|
-
case 1: {
|
1111
|
-
let leftPair = xs[offset];
|
1112
|
-
let result = createLeafFromHashEntry(leftPair);
|
1113
|
-
return result;
|
1114
|
-
}
|
1115
|
-
case 2: {
|
1116
|
-
let leftPair = xs[offset];
|
1117
|
-
let middlePair = xs[offset + 1];
|
1118
|
-
let result = {
|
1119
|
-
kind: _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeBranch,
|
1120
|
-
maxHash: middlePair.hash,
|
1121
|
-
minHash: leftPair.hash,
|
1122
|
-
left: createLeafFromHashEntry(leftPair),
|
1123
|
-
middle: createLeafFromHashEntry(middlePair),
|
1124
|
-
right: emptyBranch,
|
1125
|
-
depth: 1,
|
1126
|
-
};
|
1127
|
-
return result;
|
1128
|
-
}
|
1129
|
-
case 3: {
|
1130
|
-
let leftPair = xs[offset];
|
1131
|
-
let middlePair = xs[offset + 1];
|
1132
|
-
let rightPair = xs[offset + 2];
|
1133
|
-
let result = {
|
1134
|
-
kind: _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeBranch,
|
1135
|
-
maxHash: rightPair.hash,
|
1136
|
-
minHash: leftPair.hash,
|
1137
|
-
left: createLeafFromHashEntry(leftPair),
|
1138
|
-
middle: createLeafFromHashEntry(middlePair),
|
1139
|
-
right: createLeafFromHashEntry(rightPair),
|
1140
|
-
depth: 1,
|
1141
|
-
};
|
1142
|
-
return result;
|
1143
|
-
}
|
1144
|
-
default: {
|
1145
|
-
let divided = (0,_utils__WEBPACK_IMPORTED_MODULE_1__.divideTernarySizes)(size);
|
1146
|
-
let left = makeTernaryTreeMap(divided.left, offset, xs);
|
1147
|
-
let middle = makeTernaryTreeMap(divided.middle, offset + divided.left, xs);
|
1148
|
-
let right = makeTernaryTreeMap(divided.right, offset + divided.left + divided.middle, xs);
|
1149
|
-
let result = {
|
1150
|
-
kind: _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeBranch,
|
1151
|
-
maxHash: getMax(right),
|
1152
|
-
minHash: getMin(left),
|
1153
|
-
left: left,
|
1154
|
-
middle: middle,
|
1155
|
-
right: right,
|
1156
|
-
depth: Math.max(getMapDepth(left), getMapDepth(middle), getMapDepth(right)) + 1,
|
1157
|
-
};
|
1158
|
-
return result;
|
1159
|
-
}
|
1160
|
-
}
|
1161
|
-
}
|
1162
|
-
function initTernaryTreeMapFromHashEntries(xs) {
|
1163
|
-
return makeTernaryTreeMap(xs.length, 0, xs);
|
1164
|
-
}
|
1165
|
-
function initTernaryTreeMap(t) {
|
1166
|
-
let groupBuffers = new Map();
|
1167
|
-
for (let [k, v] of t) {
|
1168
|
-
let h = (0,_types__WEBPACK_IMPORTED_MODULE_0__.hashGenerator)(k);
|
1169
|
-
if (groupBuffers.has(h)) {
|
1170
|
-
let branch = groupBuffers.get(h);
|
1171
|
-
if (branch != null) {
|
1172
|
-
branch.push([k, v]);
|
1173
|
-
}
|
1174
|
-
else {
|
1175
|
-
throw new Error("Expected referece to pairs");
|
1176
|
-
}
|
1177
|
-
}
|
1178
|
-
else {
|
1179
|
-
groupBuffers.set(h, [[k, v]]);
|
1180
|
-
}
|
1181
|
-
}
|
1182
|
-
let xs = [];
|
1183
|
-
for (let [k, v] of groupBuffers) {
|
1184
|
-
if (v != null) {
|
1185
|
-
xs.push({
|
1186
|
-
hash: k,
|
1187
|
-
pairs: v,
|
1188
|
-
});
|
1189
|
-
}
|
1190
|
-
else {
|
1191
|
-
throw new Error("Expected reference to paris");
|
1192
|
-
}
|
1193
|
-
}
|
1194
|
-
// MUTABLE in-place sort
|
1195
|
-
xs.sort((a, b) => (0,_utils__WEBPACK_IMPORTED_MODULE_1__.cmp)(a.hash, b.hash));
|
1196
|
-
let result = initTernaryTreeMapFromHashEntries(xs);
|
1197
|
-
// checkMapStructure(result);
|
1198
|
-
return result;
|
1199
|
-
}
|
1200
|
-
// for empty map
|
1201
|
-
function initEmptyTernaryTreeMap() {
|
1202
|
-
let result = emptyBranch;
|
1203
|
-
return result;
|
1204
|
-
}
|
1205
|
-
function mapToString(tree) {
|
1206
|
-
return `TernaryTreeMap[${mapLen(tree)}, ...]`;
|
1207
|
-
}
|
1208
|
-
function mapLen(tree) {
|
1209
|
-
if (tree == null) {
|
1210
|
-
return 0;
|
1211
|
-
}
|
1212
|
-
switch (tree.kind) {
|
1213
|
-
case _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeLeaf:
|
1214
|
-
return tree.elements.length;
|
1215
|
-
case _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeBranch:
|
1216
|
-
return mapLen(tree.left) + mapLen(tree.middle) + mapLen(tree.right); // TODO
|
1217
|
-
default:
|
1218
|
-
throw new Error("Unknown");
|
1219
|
-
}
|
1220
|
-
}
|
1221
|
-
// when size succeeds bound, no longer counting, faster than traversing whole tree
|
1222
|
-
function mapLenBound(tree, bound) {
|
1223
|
-
if (tree == null) {
|
1224
|
-
return 0;
|
1225
|
-
}
|
1226
|
-
switch (tree.kind) {
|
1227
|
-
case _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeLeaf:
|
1228
|
-
return tree.elements.length;
|
1229
|
-
case _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeBranch:
|
1230
|
-
let ret = mapLenBound(tree.left, bound);
|
1231
|
-
if (ret > bound) {
|
1232
|
-
return ret;
|
1233
|
-
}
|
1234
|
-
ret = ret + mapLenBound(tree.middle, bound);
|
1235
|
-
if (ret > bound) {
|
1236
|
-
return ret;
|
1237
|
-
}
|
1238
|
-
ret = ret + mapLenBound(tree.right, bound);
|
1239
|
-
return ret;
|
1240
|
-
default:
|
1241
|
-
throw new Error("Unknown");
|
1242
|
-
}
|
1243
|
-
}
|
1244
|
-
function formatMapInline(tree, withHash = false) {
|
1245
|
-
if (tree == null) {
|
1246
|
-
return "_";
|
1247
|
-
}
|
1248
|
-
switch (tree.kind) {
|
1249
|
-
case _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeLeaf:
|
1250
|
-
if (withHash) {
|
1251
|
-
return `${tree.hash}->${tree.elements[0][0]}:${tree.elements[0][1]}`; // TODO show whole list
|
1252
|
-
}
|
1253
|
-
else {
|
1254
|
-
return `${tree.elements[0][0]}:${tree.elements[0][1]}`;
|
1255
|
-
}
|
1256
|
-
case _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeBranch: {
|
1257
|
-
return "(" + formatMapInline(tree.left, withHash) + " " + formatMapInline(tree.middle, withHash) + " " + formatMapInline(tree.right, withHash) + ")";
|
1258
|
-
}
|
1259
|
-
default:
|
1260
|
-
throw new Error("Unknown");
|
1261
|
-
}
|
1262
|
-
}
|
1263
|
-
function isMapEmpty(tree) {
|
1264
|
-
if (tree == null) {
|
1265
|
-
return true;
|
1266
|
-
}
|
1267
|
-
switch (tree.kind) {
|
1268
|
-
case _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeLeaf:
|
1269
|
-
return false;
|
1270
|
-
case _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeBranch:
|
1271
|
-
return tree.left == null && tree.middle == null && tree.right == null;
|
1272
|
-
default:
|
1273
|
-
throw new Error("Unknown");
|
1274
|
-
}
|
1275
|
-
}
|
1276
|
-
function isMapOfOne(tree, counted = 0) {
|
1277
|
-
if (tree == null) {
|
1278
|
-
return true;
|
1279
|
-
}
|
1280
|
-
switch (tree.kind) {
|
1281
|
-
case _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeLeaf:
|
1282
|
-
return false;
|
1283
|
-
case _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeBranch:
|
1284
|
-
return tree.left == null && tree.middle == null && tree.right == null;
|
1285
|
-
default:
|
1286
|
-
throw new Error("Unknown");
|
1287
|
-
}
|
1288
|
-
}
|
1289
|
-
function collectHashSortedArray(tree, acc, idx) {
|
1290
|
-
if (tree == null || isMapEmpty(tree)) {
|
1291
|
-
// discard
|
1292
|
-
}
|
1293
|
-
else {
|
1294
|
-
switch (tree.kind) {
|
1295
|
-
case _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeLeaf: {
|
1296
|
-
for (let i = 0; i < tree.elements.length; i++) {
|
1297
|
-
let item = tree.elements[i];
|
1298
|
-
acc[idx.value] = item;
|
1299
|
-
idx.value = idx.value + 1;
|
1300
|
-
}
|
1301
|
-
break;
|
1302
|
-
}
|
1303
|
-
case _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeBranch: {
|
1304
|
-
collectHashSortedArray(tree.left, acc, idx);
|
1305
|
-
collectHashSortedArray(tree.middle, acc, idx);
|
1306
|
-
collectHashSortedArray(tree.right, acc, idx);
|
1307
|
-
break;
|
1308
|
-
}
|
1309
|
-
default:
|
1310
|
-
throw new Error("Unknown");
|
1311
|
-
}
|
1312
|
-
}
|
1313
|
-
}
|
1314
|
-
// sorted by hash(tree.key)
|
1315
|
-
function toHashSortedPairs(tree) {
|
1316
|
-
let acc = new Array(mapLen(tree));
|
1317
|
-
let idx = { value: 0 };
|
1318
|
-
collectHashSortedArray(tree, acc, idx);
|
1319
|
-
return acc;
|
1320
|
-
}
|
1321
|
-
function collectOrderedHashEntries(tree, acc, idx) {
|
1322
|
-
if (tree == null || isMapEmpty(tree)) {
|
1323
|
-
// discard
|
1324
|
-
}
|
1325
|
-
else {
|
1326
|
-
switch (tree.kind) {
|
1327
|
-
case _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeLeaf: {
|
1328
|
-
acc[idx.value] = { hash: tree.hash, pairs: tree.elements };
|
1329
|
-
idx.value = idx.value + 1;
|
1330
|
-
break;
|
1331
|
-
}
|
1332
|
-
case _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeBranch: {
|
1333
|
-
collectOrderedHashEntries(tree.left, acc, idx);
|
1334
|
-
collectOrderedHashEntries(tree.middle, acc, idx);
|
1335
|
-
collectOrderedHashEntries(tree.right, acc, idx);
|
1336
|
-
break;
|
1337
|
-
}
|
1338
|
-
default: {
|
1339
|
-
throw new Error("Unknown");
|
1340
|
-
}
|
1341
|
-
}
|
1342
|
-
}
|
1343
|
-
}
|
1344
|
-
// for reusing leaves during rebalancing
|
1345
|
-
function toOrderedHashEntries(tree) {
|
1346
|
-
let acc = new Array(mapLen(tree));
|
1347
|
-
let idx = { value: 0 };
|
1348
|
-
collectOrderedHashEntries(tree, acc, idx);
|
1349
|
-
return acc;
|
1350
|
-
}
|
1351
|
-
function contains(originalTree, item) {
|
1352
|
-
if (originalTree == null) {
|
1353
|
-
return false;
|
1354
|
-
}
|
1355
|
-
// TODO
|
1356
|
-
// reduce redundant computation by reusing hash result
|
1357
|
-
let hx = (0,_types__WEBPACK_IMPORTED_MODULE_0__.hashGenerator)(item);
|
1358
|
-
let tree = originalTree;
|
1359
|
-
whileLoop: while (tree != null) {
|
1360
|
-
if (tree.kind === _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeLeaf) {
|
1361
|
-
if (hx === tree.hash) {
|
1362
|
-
let size = tree.elements.length;
|
1363
|
-
for (let idx = 0; idx < size; idx++) {
|
1364
|
-
let pair = tree.elements[idx];
|
1365
|
-
if ((0,_utils__WEBPACK_IMPORTED_MODULE_1__.dataEqual)(pair[0], item)) {
|
1366
|
-
return true;
|
1367
|
-
}
|
1368
|
-
}
|
1369
|
-
}
|
1370
|
-
return false;
|
1371
|
-
}
|
1372
|
-
// echo "looking for: ", hx, " ", item, " in ", tree.formatInline(true)
|
1373
|
-
if (tree.left == null) {
|
1374
|
-
return false;
|
1375
|
-
}
|
1376
|
-
if (tree.left.kind === _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeLeaf) {
|
1377
|
-
if (hx < tree.left.hash) {
|
1378
|
-
return false;
|
1379
|
-
}
|
1380
|
-
if (tree.left.hash === hx) {
|
1381
|
-
tree = tree.left;
|
1382
|
-
continue whileLoop; // notice, it jumps to while loop
|
1383
|
-
}
|
1384
|
-
}
|
1385
|
-
else {
|
1386
|
-
if (hx < tree.left.minHash) {
|
1387
|
-
return false;
|
1388
|
-
}
|
1389
|
-
if (hx <= tree.left.maxHash) {
|
1390
|
-
tree = tree.left;
|
1391
|
-
continue whileLoop; // notice, it jumps to while loop
|
1392
|
-
}
|
1393
|
-
}
|
1394
|
-
if (tree.middle == null) {
|
1395
|
-
return false;
|
1396
|
-
}
|
1397
|
-
if (tree.middle.kind === _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeLeaf) {
|
1398
|
-
if (hx < tree.middle.hash) {
|
1399
|
-
return false;
|
1400
|
-
}
|
1401
|
-
if (tree.middle.hash === hx) {
|
1402
|
-
tree = tree.middle;
|
1403
|
-
continue whileLoop; // notice, it jumps to while loop
|
1404
|
-
}
|
1405
|
-
}
|
1406
|
-
else {
|
1407
|
-
if (hx < tree.middle.minHash) {
|
1408
|
-
return false;
|
1409
|
-
}
|
1410
|
-
if (hx <= tree.middle.maxHash) {
|
1411
|
-
tree = tree.middle;
|
1412
|
-
continue whileLoop; // notice, it jumps to while loop
|
1413
|
-
}
|
1414
|
-
}
|
1415
|
-
if (tree.right == null) {
|
1416
|
-
return false;
|
1417
|
-
}
|
1418
|
-
if (tree.right.kind === _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeLeaf) {
|
1419
|
-
if (hx < tree.right.hash) {
|
1420
|
-
return false;
|
1421
|
-
}
|
1422
|
-
if (tree.right.hash === hx) {
|
1423
|
-
tree = tree.right;
|
1424
|
-
continue whileLoop; // notice, it jumps to while loop
|
1425
|
-
}
|
1426
|
-
}
|
1427
|
-
else {
|
1428
|
-
if (hx < tree.right.minHash) {
|
1429
|
-
return false;
|
1430
|
-
}
|
1431
|
-
if (hx <= tree.right.maxHash) {
|
1432
|
-
tree = tree.right;
|
1433
|
-
continue whileLoop; // notice, it jumps to while loop
|
1434
|
-
}
|
1435
|
-
}
|
1436
|
-
return false;
|
1437
|
-
}
|
1438
|
-
return false;
|
1439
|
-
}
|
1440
|
-
function mapGetDefault(originalTree, item, v0) {
|
1441
|
-
let hx = (0,_types__WEBPACK_IMPORTED_MODULE_0__.hashGenerator)(item);
|
1442
|
-
let tree = originalTree;
|
1443
|
-
whileLoop: while (tree != null) {
|
1444
|
-
if (tree.kind === _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeLeaf) {
|
1445
|
-
let size = tree.elements.length;
|
1446
|
-
for (let i = 0; i < size; i++) {
|
1447
|
-
let pair = tree.elements[i];
|
1448
|
-
if ((0,_utils__WEBPACK_IMPORTED_MODULE_1__.dataEqual)(pair[0], item)) {
|
1449
|
-
return pair[1];
|
1450
|
-
}
|
1451
|
-
}
|
1452
|
-
return v0;
|
1453
|
-
}
|
1454
|
-
// echo "looking for: ", hx, " ", item, " in ", tree.formatInline
|
1455
|
-
if (tree.left == null) {
|
1456
|
-
return v0;
|
1457
|
-
}
|
1458
|
-
if (tree.left.kind == _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeLeaf) {
|
1459
|
-
if (hx < tree.left.hash) {
|
1460
|
-
return v0;
|
1461
|
-
}
|
1462
|
-
if (tree.left.hash === hx) {
|
1463
|
-
tree = tree.left;
|
1464
|
-
continue whileLoop; // notice, it jumps to while loop
|
1465
|
-
}
|
1466
|
-
}
|
1467
|
-
else {
|
1468
|
-
if (hx < tree.left.minHash) {
|
1469
|
-
return v0;
|
1470
|
-
}
|
1471
|
-
if (hx <= tree.left.maxHash) {
|
1472
|
-
tree = tree.left;
|
1473
|
-
continue whileLoop; // notice, it jumps to while loop
|
1474
|
-
}
|
1475
|
-
}
|
1476
|
-
if (tree.middle == null) {
|
1477
|
-
return v0;
|
1478
|
-
}
|
1479
|
-
if (tree.middle.kind == _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeLeaf) {
|
1480
|
-
if (hx < tree.middle.hash) {
|
1481
|
-
return v0;
|
1482
|
-
}
|
1483
|
-
if (tree.middle.hash === hx) {
|
1484
|
-
tree = tree.middle;
|
1485
|
-
continue whileLoop; // notice, it jumps to while loop
|
1486
|
-
}
|
1487
|
-
}
|
1488
|
-
else {
|
1489
|
-
if (hx < tree.middle.minHash) {
|
1490
|
-
return v0;
|
1491
|
-
}
|
1492
|
-
if (hx <= tree.middle.maxHash) {
|
1493
|
-
tree = tree.middle;
|
1494
|
-
continue whileLoop; // notice, it jumps to while loop
|
1495
|
-
}
|
1496
|
-
}
|
1497
|
-
if (tree.right == null) {
|
1498
|
-
return v0;
|
1499
|
-
}
|
1500
|
-
if (tree.right.kind == _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeLeaf) {
|
1501
|
-
if (hx < tree.right.hash) {
|
1502
|
-
return v0;
|
1503
|
-
}
|
1504
|
-
if (tree.right.hash === hx) {
|
1505
|
-
tree = tree.right;
|
1506
|
-
continue whileLoop; // notice, it jumps to while loop
|
1507
|
-
}
|
1508
|
-
}
|
1509
|
-
else {
|
1510
|
-
if (hx < tree.right.minHash) {
|
1511
|
-
return v0;
|
1512
|
-
}
|
1513
|
-
if (hx <= tree.right.maxHash) {
|
1514
|
-
tree = tree.right;
|
1515
|
-
continue whileLoop; // notice, it jumps to while loop
|
1516
|
-
}
|
1517
|
-
}
|
1518
|
-
return v0;
|
1519
|
-
}
|
1520
|
-
return v0;
|
1521
|
-
}
|
1522
|
-
// leaves on the left has smaller hashes
|
1523
|
-
// TODO check sizes, hashes
|
1524
|
-
function checkMapStructure(tree) {
|
1525
|
-
if (tree.kind === _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeLeaf) {
|
1526
|
-
for (let i = 0; i < tree.elements.length; i++) {
|
1527
|
-
let pair = tree.elements[i];
|
1528
|
-
if (pair.length !== 2) {
|
1529
|
-
throw new Error("Expected pair to br [k,v] :" + pair);
|
1530
|
-
}
|
1531
|
-
if (tree.hash !== (0,_types__WEBPACK_IMPORTED_MODULE_0__.hashGenerator)(pair[0])) {
|
1532
|
-
throw new Error(`Bad hash at leaf node ${tree}`);
|
1533
|
-
}
|
1534
|
-
}
|
1535
|
-
if (mapLenBound(tree, 2) !== 1) {
|
1536
|
-
throw new Error(`Bad len at leaf node ${tree}`);
|
1537
|
-
}
|
1538
|
-
}
|
1539
|
-
else {
|
1540
|
-
if (tree.left == null) {
|
1541
|
-
if (tree.middle != null) {
|
1542
|
-
throw new Error("Layout is not compact");
|
1543
|
-
}
|
1544
|
-
if (tree.middle != null) {
|
1545
|
-
throw new Error("Layout is not compact");
|
1546
|
-
}
|
1547
|
-
}
|
1548
|
-
if (tree.middle == null) {
|
1549
|
-
if (tree.right != null) {
|
1550
|
-
throw new Error("Layout is not compact");
|
1551
|
-
}
|
1552
|
-
}
|
1553
|
-
if (tree.left != null && tree.middle != null) {
|
1554
|
-
if (getMax(tree.left) >= getMin(tree.middle)) {
|
1555
|
-
throw new Error(`Wrong hash order at left/middle branches ${formatMapInline(tree, true)}`);
|
1556
|
-
}
|
1557
|
-
}
|
1558
|
-
if (tree.left != null && tree.right != null) {
|
1559
|
-
if (getMax(tree.left) >= getMin(tree.right)) {
|
1560
|
-
console.log(getMax(tree.left), getMin(tree.right));
|
1561
|
-
throw new Error(`Wrong hash order at left/right branches ${formatMapInline(tree, true)}`);
|
1562
|
-
}
|
1563
|
-
}
|
1564
|
-
if (tree.middle != null && tree.right != null) {
|
1565
|
-
if (getMax(tree.middle) >= getMin(tree.right)) {
|
1566
|
-
throw new Error(`Wrong hash order at middle/right branches ${formatMapInline(tree, true)}`);
|
1567
|
-
}
|
1568
|
-
}
|
1569
|
-
if (tree.left != null) {
|
1570
|
-
checkMapStructure(tree.left);
|
1571
|
-
}
|
1572
|
-
if (tree.middle != null) {
|
1573
|
-
checkMapStructure(tree.middle);
|
1574
|
-
}
|
1575
|
-
if (tree.right != null) {
|
1576
|
-
checkMapStructure(tree.right);
|
1577
|
-
}
|
1578
|
-
}
|
1579
|
-
return true;
|
1580
|
-
}
|
1581
|
-
function rangeContainsHash(tree, thisHash) {
|
1582
|
-
if (tree == null) {
|
1583
|
-
return false;
|
1584
|
-
}
|
1585
|
-
else if (tree.kind === _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeLeaf) {
|
1586
|
-
return tree.hash === thisHash;
|
1587
|
-
}
|
1588
|
-
else {
|
1589
|
-
return thisHash >= tree.minHash && thisHash <= tree.maxHash;
|
1590
|
-
}
|
1591
|
-
}
|
1592
|
-
function assocExisted(tree, key, item, thisHash = null) {
|
1593
|
-
if (tree == null || isMapEmpty(tree)) {
|
1594
|
-
throw new Error("Cannot call assoc on nil");
|
1595
|
-
}
|
1596
|
-
thisHash = thisHash !== null && thisHash !== void 0 ? thisHash : (0,_types__WEBPACK_IMPORTED_MODULE_0__.hashGenerator)(key);
|
1597
|
-
if (tree.kind === _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeLeaf) {
|
1598
|
-
if (tree.hash !== thisHash) {
|
1599
|
-
throw new Error("Expected hashes to be identical, otherwise element is missing");
|
1600
|
-
}
|
1601
|
-
let newPairs = new Array(tree.elements.length);
|
1602
|
-
let replaced = false;
|
1603
|
-
let size = tree.elements.length;
|
1604
|
-
for (let idx = 0; idx < size; idx++) {
|
1605
|
-
let pair = tree.elements[idx];
|
1606
|
-
if ((0,_utils__WEBPACK_IMPORTED_MODULE_1__.dataEqual)(pair[0], key)) {
|
1607
|
-
newPairs[idx] = [key, item];
|
1608
|
-
replaced = true;
|
1609
|
-
}
|
1610
|
-
else {
|
1611
|
-
newPairs[idx] = pair;
|
1612
|
-
}
|
1613
|
-
}
|
1614
|
-
if (replaced) {
|
1615
|
-
let result = { kind: _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeLeaf, hash: thisHash, elements: newPairs };
|
1616
|
-
return result;
|
1617
|
-
}
|
1618
|
-
else {
|
1619
|
-
throw new Error("Unexpected missing hash in assoc, invalid branch");
|
1620
|
-
}
|
1621
|
-
}
|
1622
|
-
if (thisHash < tree.minHash)
|
1623
|
-
throw new Error("Unexpected missing hash in assoc, hash too small");
|
1624
|
-
else if (thisHash > tree.maxHash)
|
1625
|
-
throw new Error("Unexpected missing hash in assoc, hash too large");
|
1626
|
-
if (tree.left == null) {
|
1627
|
-
throw new Error("Unexpected missing hash in assoc, found not branch");
|
1628
|
-
}
|
1629
|
-
if (rangeContainsHash(tree.left, thisHash)) {
|
1630
|
-
let result = {
|
1631
|
-
kind: _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeBranch,
|
1632
|
-
maxHash: tree.maxHash,
|
1633
|
-
minHash: tree.minHash,
|
1634
|
-
left: assocExisted(tree.left, key, item, thisHash),
|
1635
|
-
middle: tree.middle,
|
1636
|
-
right: tree.right,
|
1637
|
-
depth: 0,
|
1638
|
-
};
|
1639
|
-
return result;
|
1640
|
-
}
|
1641
|
-
if (tree.middle == null) {
|
1642
|
-
throw new Error("Unexpected missing hash in assoc, found not branch");
|
1643
|
-
}
|
1644
|
-
if (rangeContainsHash(tree.middle, thisHash)) {
|
1645
|
-
let result = {
|
1646
|
-
kind: _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeBranch,
|
1647
|
-
maxHash: tree.maxHash,
|
1648
|
-
minHash: tree.minHash,
|
1649
|
-
left: tree.left,
|
1650
|
-
middle: assocExisted(tree.middle, key, item, thisHash),
|
1651
|
-
right: tree.right,
|
1652
|
-
depth: 0,
|
1653
|
-
};
|
1654
|
-
return result;
|
1655
|
-
}
|
1656
|
-
if (tree.right == null) {
|
1657
|
-
throw new Error("Unexpected missing hash in assoc, found not branch");
|
1658
|
-
}
|
1659
|
-
if (rangeContainsHash(tree.right, thisHash)) {
|
1660
|
-
let result = {
|
1661
|
-
kind: _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeBranch,
|
1662
|
-
maxHash: tree.maxHash,
|
1663
|
-
minHash: tree.minHash,
|
1664
|
-
left: tree.left,
|
1665
|
-
middle: tree.middle,
|
1666
|
-
right: assocExisted(tree.right, key, item, thisHash),
|
1667
|
-
depth: 0,
|
1668
|
-
};
|
1669
|
-
return result;
|
1670
|
-
}
|
1671
|
-
throw new Error("Unexpected missing hash in assoc, found not branch");
|
1672
|
-
}
|
1673
|
-
function assocNew(tree, key, item, thisHash = null) {
|
1674
|
-
// echo fmt"assoc new: {key} to {tree.formatInline}"
|
1675
|
-
if (tree == null || isMapEmpty(tree)) {
|
1676
|
-
return createLeaf(key, item);
|
1677
|
-
}
|
1678
|
-
thisHash = thisHash !== null && thisHash !== void 0 ? thisHash : (0,_types__WEBPACK_IMPORTED_MODULE_0__.hashGenerator)(key);
|
1679
|
-
if (tree.kind === _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeLeaf) {
|
1680
|
-
if (thisHash > tree.hash) {
|
1681
|
-
let childBranch = {
|
1682
|
-
kind: _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeLeaf,
|
1683
|
-
hash: thisHash,
|
1684
|
-
elements: [[key, item]],
|
1685
|
-
};
|
1686
|
-
let result = {
|
1687
|
-
kind: _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeBranch,
|
1688
|
-
maxHash: thisHash,
|
1689
|
-
minHash: tree.hash,
|
1690
|
-
left: tree,
|
1691
|
-
middle: childBranch,
|
1692
|
-
right: emptyBranch,
|
1693
|
-
depth: 0,
|
1694
|
-
};
|
1695
|
-
return result;
|
1696
|
-
}
|
1697
|
-
else if (thisHash < tree.hash) {
|
1698
|
-
let childBranch = {
|
1699
|
-
kind: _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeLeaf,
|
1700
|
-
hash: thisHash,
|
1701
|
-
elements: [[key, item]],
|
1702
|
-
};
|
1703
|
-
let result = {
|
1704
|
-
kind: _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeBranch,
|
1705
|
-
maxHash: tree.hash,
|
1706
|
-
minHash: thisHash,
|
1707
|
-
left: childBranch,
|
1708
|
-
middle: tree,
|
1709
|
-
right: emptyBranch,
|
1710
|
-
depth: 0,
|
1711
|
-
};
|
1712
|
-
return result;
|
1713
|
-
}
|
1714
|
-
else {
|
1715
|
-
let size = tree.elements.length;
|
1716
|
-
for (let i = 0; i < size; i++) {
|
1717
|
-
let pair = tree.elements[i];
|
1718
|
-
if ((0,_utils__WEBPACK_IMPORTED_MODULE_1__.dataEqual)(pair[0], key)) {
|
1719
|
-
throw new Error("Unexpected existed key in assoc");
|
1720
|
-
}
|
1721
|
-
}
|
1722
|
-
let newPairs = new Array(tree.elements.length + 1);
|
1723
|
-
for (let idx = 0; idx < size; idx++) {
|
1724
|
-
let pair = tree.elements[idx];
|
1725
|
-
newPairs[idx] = pair;
|
1726
|
-
}
|
1727
|
-
newPairs[tree.elements.length] = [key, item];
|
1728
|
-
let result = {
|
1729
|
-
kind: _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeLeaf,
|
1730
|
-
hash: tree.hash,
|
1731
|
-
elements: newPairs,
|
1732
|
-
};
|
1733
|
-
return result;
|
1734
|
-
}
|
1735
|
-
}
|
1736
|
-
else {
|
1737
|
-
if (thisHash < tree.minHash) {
|
1738
|
-
if (tree.right == null) {
|
1739
|
-
let childBranch = {
|
1740
|
-
kind: _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeLeaf,
|
1741
|
-
hash: thisHash,
|
1742
|
-
elements: [[key, item]],
|
1743
|
-
};
|
1744
|
-
let result = {
|
1745
|
-
kind: _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeBranch,
|
1746
|
-
maxHash: tree.maxHash,
|
1747
|
-
minHash: thisHash,
|
1748
|
-
left: childBranch,
|
1749
|
-
middle: tree.left,
|
1750
|
-
right: tree.middle,
|
1751
|
-
depth: 0,
|
1752
|
-
};
|
1753
|
-
return result;
|
1754
|
-
}
|
1755
|
-
else {
|
1756
|
-
let childBranch = {
|
1757
|
-
kind: _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeLeaf,
|
1758
|
-
hash: thisHash,
|
1759
|
-
elements: [[key, item]],
|
1760
|
-
};
|
1761
|
-
let result = {
|
1762
|
-
kind: _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeBranch,
|
1763
|
-
maxHash: tree.maxHash,
|
1764
|
-
minHash: thisHash,
|
1765
|
-
left: childBranch,
|
1766
|
-
middle: tree,
|
1767
|
-
right: emptyBranch,
|
1768
|
-
depth: 0,
|
1769
|
-
};
|
1770
|
-
return result;
|
1771
|
-
}
|
1772
|
-
}
|
1773
|
-
if (thisHash > tree.maxHash) {
|
1774
|
-
// in compact layout, left arm must be existed
|
1775
|
-
if (tree.middle == null) {
|
1776
|
-
let childBranch = {
|
1777
|
-
kind: _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeLeaf,
|
1778
|
-
hash: thisHash,
|
1779
|
-
elements: [[key, item]],
|
1780
|
-
};
|
1781
|
-
let result = {
|
1782
|
-
kind: _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeBranch,
|
1783
|
-
maxHash: thisHash,
|
1784
|
-
minHash: tree.minHash,
|
1785
|
-
left: tree.left,
|
1786
|
-
middle: childBranch,
|
1787
|
-
right: emptyBranch,
|
1788
|
-
depth: 0,
|
1789
|
-
};
|
1790
|
-
return result;
|
1791
|
-
}
|
1792
|
-
else if (tree.right == null) {
|
1793
|
-
let childBranch = {
|
1794
|
-
kind: _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeLeaf,
|
1795
|
-
hash: thisHash,
|
1796
|
-
elements: [[key, item]],
|
1797
|
-
};
|
1798
|
-
let result = {
|
1799
|
-
kind: _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeBranch,
|
1800
|
-
maxHash: thisHash,
|
1801
|
-
minHash: tree.minHash,
|
1802
|
-
left: tree.left,
|
1803
|
-
middle: tree.middle,
|
1804
|
-
right: childBranch,
|
1805
|
-
depth: 0,
|
1806
|
-
};
|
1807
|
-
return result;
|
1808
|
-
}
|
1809
|
-
else {
|
1810
|
-
let childBranch = {
|
1811
|
-
kind: _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeLeaf,
|
1812
|
-
hash: thisHash,
|
1813
|
-
elements: [[key, item]],
|
1814
|
-
};
|
1815
|
-
let result = {
|
1816
|
-
kind: _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeBranch,
|
1817
|
-
maxHash: thisHash,
|
1818
|
-
minHash: tree.minHash,
|
1819
|
-
left: tree,
|
1820
|
-
middle: childBranch,
|
1821
|
-
right: emptyBranch,
|
1822
|
-
depth: 0,
|
1823
|
-
};
|
1824
|
-
return result;
|
1825
|
-
}
|
1826
|
-
}
|
1827
|
-
if (rangeContainsHash(tree.left, thisHash)) {
|
1828
|
-
let result = {
|
1829
|
-
kind: _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeBranch,
|
1830
|
-
maxHash: tree.maxHash,
|
1831
|
-
minHash: tree.minHash,
|
1832
|
-
left: assocNew(tree.left, key, item, thisHash),
|
1833
|
-
middle: tree.middle,
|
1834
|
-
right: tree.right,
|
1835
|
-
depth: 0,
|
1836
|
-
};
|
1837
|
-
return result;
|
1838
|
-
}
|
1839
|
-
if (rangeContainsHash(tree.middle, thisHash)) {
|
1840
|
-
let result = {
|
1841
|
-
kind: _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeBranch,
|
1842
|
-
maxHash: tree.maxHash,
|
1843
|
-
minHash: tree.minHash,
|
1844
|
-
left: tree.left,
|
1845
|
-
middle: assocNew(tree.middle, key, item, thisHash),
|
1846
|
-
right: tree.right,
|
1847
|
-
depth: 0,
|
1848
|
-
};
|
1849
|
-
return result;
|
1850
|
-
}
|
1851
|
-
if (rangeContainsHash(tree.right, thisHash)) {
|
1852
|
-
let result = {
|
1853
|
-
kind: _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeBranch,
|
1854
|
-
maxHash: tree.maxHash,
|
1855
|
-
minHash: tree.minHash,
|
1856
|
-
left: tree.left,
|
1857
|
-
middle: tree.middle,
|
1858
|
-
right: assocNew(tree.right, key, item, thisHash),
|
1859
|
-
depth: 0,
|
1860
|
-
};
|
1861
|
-
return result;
|
1862
|
-
}
|
1863
|
-
if (tree.middle == null) {
|
1864
|
-
throw new Error("unreachable. if inside range, then middle should be here");
|
1865
|
-
}
|
1866
|
-
if (thisHash < getMin(tree.middle)) {
|
1867
|
-
let result = {
|
1868
|
-
kind: _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeBranch,
|
1869
|
-
maxHash: tree.maxHash,
|
1870
|
-
minHash: tree.minHash,
|
1871
|
-
left: assocNew(tree.left, key, item, thisHash),
|
1872
|
-
middle: tree.middle,
|
1873
|
-
right: tree.right,
|
1874
|
-
depth: 0,
|
1875
|
-
};
|
1876
|
-
return result;
|
1877
|
-
}
|
1878
|
-
else {
|
1879
|
-
let result = {
|
1880
|
-
kind: _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeBranch,
|
1881
|
-
maxHash: tree.maxHash,
|
1882
|
-
minHash: tree.minHash,
|
1883
|
-
left: tree.left,
|
1884
|
-
middle: tree.middle,
|
1885
|
-
right: assocNew(tree.right, key, item, thisHash),
|
1886
|
-
depth: 0,
|
1887
|
-
};
|
1888
|
-
return result;
|
1889
|
-
}
|
1890
|
-
}
|
1891
|
-
}
|
1892
|
-
function assocMap(tree, key, item, disableBalancing = false) {
|
1893
|
-
if (tree == null || isMapEmpty(tree)) {
|
1894
|
-
return createLeaf(key, item);
|
1895
|
-
}
|
1896
|
-
if (contains(tree, key)) {
|
1897
|
-
return assocExisted(tree, key, item);
|
1898
|
-
}
|
1899
|
-
else {
|
1900
|
-
return assocNew(tree, key, item);
|
1901
|
-
}
|
1902
|
-
}
|
1903
|
-
function dissocExisted(tree, key) {
|
1904
|
-
if (tree == null) {
|
1905
|
-
throw new Error("Unexpected missing key in dissoc");
|
1906
|
-
}
|
1907
|
-
if (tree.kind === _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeLeaf) {
|
1908
|
-
if (tree.hash === (0,_types__WEBPACK_IMPORTED_MODULE_0__.hashGenerator)(key)) {
|
1909
|
-
let size = tree.elements.length;
|
1910
|
-
if (size === 1 && (0,_utils__WEBPACK_IMPORTED_MODULE_1__.dataEqual)(key, tree.elements[0][0])) {
|
1911
|
-
return emptyBranch;
|
1912
|
-
}
|
1913
|
-
else {
|
1914
|
-
let newPairs = [];
|
1915
|
-
for (let i = 0; i < size; i++) {
|
1916
|
-
let pair = tree.elements[i];
|
1917
|
-
if (!(0,_utils__WEBPACK_IMPORTED_MODULE_1__.dataEqual)(pair[0], key)) {
|
1918
|
-
newPairs.push(pair);
|
1919
|
-
}
|
1920
|
-
}
|
1921
|
-
let result = { kind: _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeLeaf, hash: tree.hash, elements: newPairs };
|
1922
|
-
return result;
|
1923
|
-
}
|
1924
|
-
}
|
1925
|
-
else {
|
1926
|
-
throw new Error("Unexpected missing key in dissoc on leaf");
|
1927
|
-
}
|
1928
|
-
}
|
1929
|
-
if (mapLenBound(tree, 2) === 1) {
|
1930
|
-
if (!contains(tree, key)) {
|
1931
|
-
throw new Error("Unexpected missing key in dissoc single branch");
|
1932
|
-
}
|
1933
|
-
return emptyBranch;
|
1934
|
-
}
|
1935
|
-
let thisHash = (0,_types__WEBPACK_IMPORTED_MODULE_0__.hashGenerator)(key);
|
1936
|
-
if (rangeContainsHash(tree.left, thisHash)) {
|
1937
|
-
let changedBranch = dissocExisted(tree.left, key);
|
1938
|
-
if (isMapEmpty(changedBranch)) {
|
1939
|
-
if (isMapEmpty(tree.right)) {
|
1940
|
-
return tree.middle;
|
1941
|
-
}
|
1942
|
-
let result = {
|
1943
|
-
kind: _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeBranch,
|
1944
|
-
maxHash: tree.maxHash,
|
1945
|
-
minHash: getMin(tree.middle),
|
1946
|
-
left: tree.middle,
|
1947
|
-
middle: tree.right,
|
1948
|
-
right: emptyBranch,
|
1949
|
-
depth: 0,
|
1950
|
-
};
|
1951
|
-
return result;
|
1952
|
-
}
|
1953
|
-
else {
|
1954
|
-
let result = {
|
1955
|
-
kind: _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeBranch,
|
1956
|
-
maxHash: tree.maxHash,
|
1957
|
-
minHash: getMin(changedBranch),
|
1958
|
-
left: changedBranch,
|
1959
|
-
middle: tree.middle,
|
1960
|
-
right: tree.right,
|
1961
|
-
depth: 0,
|
1962
|
-
};
|
1963
|
-
return result;
|
1964
|
-
}
|
1965
|
-
}
|
1966
|
-
if (rangeContainsHash(tree.middle, thisHash)) {
|
1967
|
-
let changedBranch = dissocExisted(tree.middle, key);
|
1968
|
-
if (isMapEmpty(changedBranch)) {
|
1969
|
-
if (isMapEmpty(tree.right)) {
|
1970
|
-
return tree.left;
|
1971
|
-
}
|
1972
|
-
let result = {
|
1973
|
-
kind: _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeBranch,
|
1974
|
-
maxHash: tree.maxHash,
|
1975
|
-
minHash: tree.minHash,
|
1976
|
-
left: tree.left,
|
1977
|
-
middle: tree.right,
|
1978
|
-
right: emptyBranch,
|
1979
|
-
depth: 0,
|
1980
|
-
};
|
1981
|
-
return result;
|
1982
|
-
}
|
1983
|
-
else {
|
1984
|
-
let result = {
|
1985
|
-
kind: _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeBranch,
|
1986
|
-
maxHash: tree.maxHash,
|
1987
|
-
minHash: tree.minHash,
|
1988
|
-
left: tree.left,
|
1989
|
-
middle: changedBranch,
|
1990
|
-
right: tree.right,
|
1991
|
-
depth: 0,
|
1992
|
-
};
|
1993
|
-
return result;
|
1994
|
-
}
|
1995
|
-
}
|
1996
|
-
if (rangeContainsHash(tree.right, thisHash)) {
|
1997
|
-
let changedBranch = dissocExisted(tree.right, key);
|
1998
|
-
if (changedBranch == null) {
|
1999
|
-
let result = {
|
2000
|
-
kind: _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeBranch,
|
2001
|
-
maxHash: getMax(tree.middle),
|
2002
|
-
minHash: tree.minHash,
|
2003
|
-
left: tree.left,
|
2004
|
-
middle: tree.middle,
|
2005
|
-
right: emptyBranch,
|
2006
|
-
depth: 0,
|
2007
|
-
};
|
2008
|
-
return result;
|
2009
|
-
}
|
2010
|
-
else {
|
2011
|
-
let result = {
|
2012
|
-
kind: _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeBranch,
|
2013
|
-
maxHash: getMax(changedBranch),
|
2014
|
-
minHash: tree.minHash,
|
2015
|
-
left: tree.left,
|
2016
|
-
middle: tree.middle,
|
2017
|
-
right: changedBranch,
|
2018
|
-
depth: 0,
|
2019
|
-
};
|
2020
|
-
return result;
|
2021
|
-
}
|
2022
|
-
}
|
2023
|
-
throw new Error("Cannot find branch in dissoc");
|
2024
|
-
}
|
2025
|
-
function dissocMap(tree, key) {
|
2026
|
-
if (contains(tree, key)) {
|
2027
|
-
return dissocExisted(tree, key);
|
2028
|
-
}
|
2029
|
-
else {
|
2030
|
-
return tree;
|
2031
|
-
}
|
2032
|
-
}
|
2033
|
-
function collectToPairsArray(acc, tree) {
|
2034
|
-
if (tree != null) {
|
2035
|
-
if (tree.kind === _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeLeaf) {
|
2036
|
-
for (let i = 0; i < tree.elements.length; i++) {
|
2037
|
-
let pair = tree.elements[i];
|
2038
|
-
acc.push(pair);
|
2039
|
-
}
|
2040
|
-
}
|
2041
|
-
else {
|
2042
|
-
if (tree.left != null) {
|
2043
|
-
collectToPairsArray(acc, tree.left);
|
2044
|
-
}
|
2045
|
-
if (tree.middle != null) {
|
2046
|
-
collectToPairsArray(acc, tree.middle);
|
2047
|
-
}
|
2048
|
-
if (tree.right != null) {
|
2049
|
-
collectToPairsArray(acc, tree.right);
|
2050
|
-
}
|
2051
|
-
}
|
2052
|
-
}
|
2053
|
-
}
|
2054
|
-
/** similar to `toPairs`, but using Array.push directly */
|
2055
|
-
function toPairsArray(tree) {
|
2056
|
-
let result = [];
|
2057
|
-
collectToPairsArray(result, tree);
|
2058
|
-
return result;
|
2059
|
-
}
|
2060
|
-
function* toPairs(tree) {
|
2061
|
-
if (tree != null) {
|
2062
|
-
if (tree.kind === _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeLeaf) {
|
2063
|
-
for (let pair of tree.elements) {
|
2064
|
-
yield pair;
|
2065
|
-
}
|
2066
|
-
}
|
2067
|
-
else {
|
2068
|
-
if (tree.left != null) {
|
2069
|
-
for (let item of toPairs(tree.left)) {
|
2070
|
-
yield item;
|
2071
|
-
}
|
2072
|
-
}
|
2073
|
-
if (tree.middle != null) {
|
2074
|
-
for (let item of toPairs(tree.middle)) {
|
2075
|
-
yield item;
|
2076
|
-
}
|
2077
|
-
}
|
2078
|
-
if (tree.right != null) {
|
2079
|
-
for (let item of toPairs(tree.right)) {
|
2080
|
-
yield item;
|
2081
|
-
}
|
2082
|
-
}
|
2083
|
-
}
|
2084
|
-
}
|
2085
|
-
}
|
2086
|
-
function* toKeys(tree) {
|
2087
|
-
if (tree != null) {
|
2088
|
-
if (tree.kind === _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeLeaf) {
|
2089
|
-
for (let i = 0; i < tree.elements.length; i++) {
|
2090
|
-
let pair = tree.elements[i];
|
2091
|
-
yield pair[0];
|
2092
|
-
}
|
2093
|
-
}
|
2094
|
-
else {
|
2095
|
-
if (tree.left != null) {
|
2096
|
-
for (let item of toKeys(tree.left)) {
|
2097
|
-
yield item;
|
2098
|
-
}
|
2099
|
-
}
|
2100
|
-
if (tree.middle != null) {
|
2101
|
-
for (let item of toKeys(tree.middle)) {
|
2102
|
-
yield item;
|
2103
|
-
}
|
2104
|
-
}
|
2105
|
-
if (tree.right != null) {
|
2106
|
-
for (let item of toKeys(tree.right)) {
|
2107
|
-
yield item;
|
2108
|
-
}
|
2109
|
-
}
|
2110
|
-
}
|
2111
|
-
}
|
2112
|
-
}
|
2113
|
-
function* toValues(tree) {
|
2114
|
-
if (tree != null) {
|
2115
|
-
if (tree.kind === _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeLeaf) {
|
2116
|
-
for (let i = 0; i < tree.elements.length; i++) {
|
2117
|
-
let pair = tree.elements[i];
|
2118
|
-
yield pair[1];
|
2119
|
-
}
|
2120
|
-
}
|
2121
|
-
else {
|
2122
|
-
if (tree.left != null) {
|
2123
|
-
for (let item of toValues(tree.left)) {
|
2124
|
-
yield item;
|
2125
|
-
}
|
2126
|
-
}
|
2127
|
-
if (tree.middle != null) {
|
2128
|
-
for (let item of toValues(tree.middle)) {
|
2129
|
-
yield item;
|
2130
|
-
}
|
2131
|
-
}
|
2132
|
-
if (tree.right != null) {
|
2133
|
-
for (let item of toValues(tree.right)) {
|
2134
|
-
yield item;
|
2135
|
-
}
|
2136
|
-
}
|
2137
|
-
}
|
2138
|
-
}
|
2139
|
-
}
|
2140
|
-
function mapEqual(xs, ys) {
|
2141
|
-
if (xs === ys) {
|
2142
|
-
return true;
|
2143
|
-
}
|
2144
|
-
if (mapLen(xs) !== mapLen(ys)) {
|
2145
|
-
return false;
|
2146
|
-
}
|
2147
|
-
if (isMapEmpty(xs)) {
|
2148
|
-
return true;
|
2149
|
-
}
|
2150
|
-
for (let pair of toPairsArray(xs)) {
|
2151
|
-
let key = pair[0];
|
2152
|
-
let vx = pair[1];
|
2153
|
-
if (!contains(ys, key)) {
|
2154
|
-
return false;
|
2155
|
-
}
|
2156
|
-
let vy = mapGetDefault(ys, key, null);
|
2157
|
-
// TODO compare deep structures
|
2158
|
-
if (!(0,_utils__WEBPACK_IMPORTED_MODULE_1__.dataEqual)(vx, vy)) {
|
2159
|
-
return false;
|
2160
|
-
}
|
2161
|
-
}
|
2162
|
-
return true;
|
2163
|
-
}
|
2164
|
-
function merge(xs, ys) {
|
2165
|
-
let ret = xs;
|
2166
|
-
let counted = 0;
|
2167
|
-
for (let [key, item] of toPairs(ys)) {
|
2168
|
-
ret = assocMap(ret, key, item);
|
2169
|
-
// # TODO pickd loop by experience
|
2170
|
-
if (counted > 700) {
|
2171
|
-
forceMapInplaceBalancing(ret);
|
2172
|
-
counted = 0;
|
2173
|
-
}
|
2174
|
-
else {
|
2175
|
-
counted = counted + 1;
|
2176
|
-
}
|
2177
|
-
}
|
2178
|
-
return ret;
|
2179
|
-
}
|
2180
|
-
// # skip a value, mostly for nil
|
2181
|
-
function mergeSkip(xs, ys, skipped) {
|
2182
|
-
let ret = xs;
|
2183
|
-
let counted = 0;
|
2184
|
-
for (let [key, item] of toPairs(ys)) {
|
2185
|
-
if ((0,_utils__WEBPACK_IMPORTED_MODULE_1__.dataEqual)(item, skipped)) {
|
2186
|
-
continue;
|
2187
|
-
}
|
2188
|
-
ret = assocMap(ret, key, item);
|
2189
|
-
// # TODO pickd loop by experience
|
2190
|
-
if (counted > 700) {
|
2191
|
-
forceMapInplaceBalancing(ret);
|
2192
|
-
counted = 0;
|
2193
|
-
}
|
2194
|
-
else {
|
2195
|
-
counted = counted + 1;
|
2196
|
-
}
|
2197
|
-
}
|
2198
|
-
return ret;
|
2199
|
-
}
|
2200
|
-
// this function mutates original tree to make it more balanced
|
2201
|
-
function forceMapInplaceBalancing(tree) {
|
2202
|
-
// echo "Force inplace balancing of list"
|
2203
|
-
if (tree.kind === _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeBranch) {
|
2204
|
-
let xs = toOrderedHashEntries(tree);
|
2205
|
-
let newTree = makeTernaryTreeMap(xs.length, 0, xs);
|
2206
|
-
tree.left = newTree.left;
|
2207
|
-
tree.middle = newTree.middle;
|
2208
|
-
tree.right = newTree.right;
|
2209
|
-
}
|
2210
|
-
else {
|
2211
|
-
// discard
|
2212
|
-
}
|
2213
|
-
}
|
2214
|
-
function sameMapShape(xs, ys) {
|
2215
|
-
if (xs == null) {
|
2216
|
-
if (ys == null) {
|
2217
|
-
return true;
|
2218
|
-
}
|
2219
|
-
else {
|
2220
|
-
return false;
|
2221
|
-
}
|
2222
|
-
}
|
2223
|
-
if (ys == null) {
|
2224
|
-
return false;
|
2225
|
-
}
|
2226
|
-
if (mapLen(xs) !== mapLen(ys)) {
|
2227
|
-
return false;
|
2228
|
-
}
|
2229
|
-
if (xs.kind !== ys.kind) {
|
2230
|
-
return false;
|
2231
|
-
}
|
2232
|
-
if (xs.kind === _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeLeaf && ys.kind === _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeLeaf) {
|
2233
|
-
if (xs.elements.length !== ys.elements.length) {
|
2234
|
-
return false;
|
2235
|
-
}
|
2236
|
-
for (let idx = 0; idx < xs.elements.length; idx++) {
|
2237
|
-
if (!(0,_utils__WEBPACK_IMPORTED_MODULE_1__.dataEqual)(xs.elements[idx], ys.elements[idx])) {
|
2238
|
-
return false;
|
2239
|
-
}
|
2240
|
-
}
|
2241
|
-
return true;
|
2242
|
-
}
|
2243
|
-
else if (xs.kind === _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeBranch && ys.kind === _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeBranch) {
|
2244
|
-
if (!sameMapShape(xs.left, ys.left)) {
|
2245
|
-
return false;
|
2246
|
-
}
|
2247
|
-
if (!sameMapShape(xs.middle, ys.middle)) {
|
2248
|
-
return false;
|
2249
|
-
}
|
2250
|
-
if (!sameMapShape(xs.right, ys.right)) {
|
2251
|
-
return false;
|
2252
|
-
}
|
2253
|
-
return true;
|
2254
|
-
}
|
2255
|
-
else {
|
2256
|
-
throw new Error("Unknown");
|
2257
|
-
}
|
2258
|
-
}
|
2259
|
-
function mapMapValues(tree, f) {
|
2260
|
-
if (tree == null) {
|
2261
|
-
return tree;
|
2262
|
-
}
|
2263
|
-
switch (tree.kind) {
|
2264
|
-
case _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeLeaf: {
|
2265
|
-
let newElements = new Array(tree.elements.length);
|
2266
|
-
let size = tree.elements.length;
|
2267
|
-
for (let idx = 0; idx < size; idx++) {
|
2268
|
-
newElements[idx] = [tree.elements[idx][0], f(tree.elements[idx][1])];
|
2269
|
-
}
|
2270
|
-
let result = {
|
2271
|
-
kind: _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeLeaf,
|
2272
|
-
hash: tree.hash,
|
2273
|
-
elements: newElements,
|
2274
|
-
};
|
2275
|
-
return result;
|
2276
|
-
}
|
2277
|
-
case _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeBranch: {
|
2278
|
-
let result = {
|
2279
|
-
kind: _types__WEBPACK_IMPORTED_MODULE_0__.TernaryTreeKind.ternaryTreeBranch,
|
2280
|
-
depth: tree.depth,
|
2281
|
-
minHash: tree.minHash,
|
2282
|
-
maxHash: tree.maxHash,
|
2283
|
-
left: mapMapValues(tree.left, f),
|
2284
|
-
middle: mapMapValues(tree.middle, f),
|
2285
|
-
right: mapMapValues(tree.right, f),
|
2286
|
-
};
|
2287
|
-
return result;
|
2288
|
-
}
|
2289
|
-
}
|
2290
|
-
}
|
2291
|
-
|
2292
|
-
|
2293
|
-
/***/ }),
|
2294
|
-
|
2295
|
-
/***/ "./lib/test-list.js":
|
2296
|
-
/*!**************************!*\
|
2297
|
-
!*** ./lib/test-list.js ***!
|
2298
|
-
\**************************/
|
2299
|
-
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
2300
|
-
|
2301
|
-
__webpack_require__.r(__webpack_exports__);
|
2302
|
-
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
2303
|
-
/* harmony export */ "runListTests": () => /* binding */ runListTests
|
2304
|
-
/* harmony export */ });
|
2305
|
-
/* harmony import */ var _list__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./list */ "./lib/list.js");
|
2306
|
-
/* harmony import */ var _utils__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./utils */ "./lib/utils.js");
|
2307
|
-
|
2308
|
-
|
2309
|
-
let runListTests = () => {
|
2310
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.test)("init list", () => {
|
2311
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.check)((0,_list__WEBPACK_IMPORTED_MODULE_0__.listToString)((0,_list__WEBPACK_IMPORTED_MODULE_0__.initTernaryTreeList)([1, 2, 3, 4])) === "TernaryTreeList[4, ...]");
|
2312
|
-
let origin11 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11];
|
2313
|
-
let data11 = (0,_list__WEBPACK_IMPORTED_MODULE_0__.initTernaryTreeList)(origin11);
|
2314
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.check)((0,_list__WEBPACK_IMPORTED_MODULE_0__.checkListStructure)(data11));
|
2315
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.checkEqual)((0,_list__WEBPACK_IMPORTED_MODULE_0__.formatListInline)(data11), "((1 (2 3 _) 4) (5 6 7) (8 (9 10 _) 11))");
|
2316
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.check)((0,_utils__WEBPACK_IMPORTED_MODULE_1__.arrayEqual)(origin11, [...(0,_list__WEBPACK_IMPORTED_MODULE_0__.listToItems)(data11)]));
|
2317
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.check)((0,_utils__WEBPACK_IMPORTED_MODULE_1__.arrayEqual)([...(0,_list__WEBPACK_IMPORTED_MODULE_0__.listToItems)(data11)], [...(0,_list__WEBPACK_IMPORTED_MODULE_0__.indexToItems)(data11)]));
|
2318
|
-
let emptyXs = new Array(0);
|
2319
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.check)((0,_list__WEBPACK_IMPORTED_MODULE_0__.listEqual)((0,_list__WEBPACK_IMPORTED_MODULE_0__.initEmptyTernaryTreeList)(), (0,_list__WEBPACK_IMPORTED_MODULE_0__.initTernaryTreeList)(emptyXs)));
|
2320
|
-
});
|
2321
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.test)("list operations", () => {
|
2322
|
-
let origin11 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11];
|
2323
|
-
let data11 = (0,_list__WEBPACK_IMPORTED_MODULE_0__.initTernaryTreeList)(origin11);
|
2324
|
-
// get
|
2325
|
-
for (let idx = 0; idx < origin11.length; idx++) {
|
2326
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.check)(origin11[idx] === (0,_list__WEBPACK_IMPORTED_MODULE_0__.listGet)(data11, idx));
|
2327
|
-
}
|
2328
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.check)((0,_list__WEBPACK_IMPORTED_MODULE_0__.first)(data11) === 1);
|
2329
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.check)((0,_list__WEBPACK_IMPORTED_MODULE_0__.last)(data11) === 11);
|
2330
|
-
// assoc
|
2331
|
-
let origin5 = [1, 2, 3, 4, 5];
|
2332
|
-
let data5 = (0,_list__WEBPACK_IMPORTED_MODULE_0__.initTernaryTreeList)(origin5);
|
2333
|
-
let updated = (0,_list__WEBPACK_IMPORTED_MODULE_0__.assocList)(data5, 3, 10);
|
2334
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.check)((0,_list__WEBPACK_IMPORTED_MODULE_0__.listGet)(updated, 3) === 10);
|
2335
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.check)((0,_list__WEBPACK_IMPORTED_MODULE_0__.listGet)(data5, 3) === 4);
|
2336
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.check)((0,_list__WEBPACK_IMPORTED_MODULE_0__.listLen)(updated) === (0,_list__WEBPACK_IMPORTED_MODULE_0__.listLen)(data5));
|
2337
|
-
for (let idx = 0; idx < (0,_list__WEBPACK_IMPORTED_MODULE_0__.listLen)(data5); idx++) {
|
2338
|
-
// echo data5.dissoc(idx).formatInline
|
2339
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.check)((0,_list__WEBPACK_IMPORTED_MODULE_0__.listLen)((0,_list__WEBPACK_IMPORTED_MODULE_0__.dissocList)(data5, idx)) === (0,_list__WEBPACK_IMPORTED_MODULE_0__.listLen)(data5) - 1);
|
2340
|
-
}
|
2341
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.checkEqual)((0,_list__WEBPACK_IMPORTED_MODULE_0__.formatListInline)(data5), "((1 2 _) 3 (4 5 _))");
|
2342
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.checkEqual)((0,_list__WEBPACK_IMPORTED_MODULE_0__.formatListInline)((0,_list__WEBPACK_IMPORTED_MODULE_0__.dissocList)(data5, 0)), "(2 3 (4 5 _))");
|
2343
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.checkEqual)((0,_list__WEBPACK_IMPORTED_MODULE_0__.formatListInline)((0,_list__WEBPACK_IMPORTED_MODULE_0__.dissocList)(data5, 1)), "(1 3 (4 5 _))");
|
2344
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.checkEqual)((0,_list__WEBPACK_IMPORTED_MODULE_0__.formatListInline)((0,_list__WEBPACK_IMPORTED_MODULE_0__.dissocList)(data5, 2)), "((1 2 _) (4 5 _) _)");
|
2345
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.checkEqual)((0,_list__WEBPACK_IMPORTED_MODULE_0__.formatListInline)((0,_list__WEBPACK_IMPORTED_MODULE_0__.dissocList)(data5, 3)), "((1 2 _) 3 5)");
|
2346
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.checkEqual)((0,_list__WEBPACK_IMPORTED_MODULE_0__.formatListInline)((0,_list__WEBPACK_IMPORTED_MODULE_0__.dissocList)(data5, 4)), "((1 2 _) 3 4)");
|
2347
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.checkEqual)((0,_list__WEBPACK_IMPORTED_MODULE_0__.formatListInline)((0,_list__WEBPACK_IMPORTED_MODULE_0__.rest)((0,_list__WEBPACK_IMPORTED_MODULE_0__.initTernaryTreeList)([1]))), "_");
|
2348
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.checkEqual)((0,_list__WEBPACK_IMPORTED_MODULE_0__.formatListInline)((0,_list__WEBPACK_IMPORTED_MODULE_0__.rest)((0,_list__WEBPACK_IMPORTED_MODULE_0__.initTernaryTreeList)([1, 2]))), "2");
|
2349
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.checkEqual)((0,_list__WEBPACK_IMPORTED_MODULE_0__.formatListInline)((0,_list__WEBPACK_IMPORTED_MODULE_0__.rest)((0,_list__WEBPACK_IMPORTED_MODULE_0__.initTernaryTreeList)([1, 2, 3]))), "(2 3 _)");
|
2350
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.checkEqual)((0,_list__WEBPACK_IMPORTED_MODULE_0__.formatListInline)((0,_list__WEBPACK_IMPORTED_MODULE_0__.rest)((0,_list__WEBPACK_IMPORTED_MODULE_0__.initTernaryTreeList)([1, 2, 3, 4]))), "((2 3 _) 4 _)");
|
2351
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.checkEqual)((0,_list__WEBPACK_IMPORTED_MODULE_0__.formatListInline)((0,_list__WEBPACK_IMPORTED_MODULE_0__.rest)((0,_list__WEBPACK_IMPORTED_MODULE_0__.initTernaryTreeList)([1, 2, 3, 4, 5]))), "(2 3 (4 5 _))");
|
2352
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.checkEqual)((0,_list__WEBPACK_IMPORTED_MODULE_0__.formatListInline)((0,_list__WEBPACK_IMPORTED_MODULE_0__.butlast)((0,_list__WEBPACK_IMPORTED_MODULE_0__.initTernaryTreeList)([1]))), "_");
|
2353
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.checkEqual)((0,_list__WEBPACK_IMPORTED_MODULE_0__.formatListInline)((0,_list__WEBPACK_IMPORTED_MODULE_0__.butlast)((0,_list__WEBPACK_IMPORTED_MODULE_0__.initTernaryTreeList)([1, 2]))), "1");
|
2354
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.checkEqual)((0,_list__WEBPACK_IMPORTED_MODULE_0__.formatListInline)((0,_list__WEBPACK_IMPORTED_MODULE_0__.butlast)((0,_list__WEBPACK_IMPORTED_MODULE_0__.initTernaryTreeList)([1, 2, 3]))), "(1 2 _)");
|
2355
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.checkEqual)((0,_list__WEBPACK_IMPORTED_MODULE_0__.formatListInline)((0,_list__WEBPACK_IMPORTED_MODULE_0__.butlast)((0,_list__WEBPACK_IMPORTED_MODULE_0__.initTernaryTreeList)([1, 2, 3, 4]))), "(1 (2 3 _) _)");
|
2356
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.checkEqual)((0,_list__WEBPACK_IMPORTED_MODULE_0__.formatListInline)((0,_list__WEBPACK_IMPORTED_MODULE_0__.butlast)((0,_list__WEBPACK_IMPORTED_MODULE_0__.initTernaryTreeList)([1, 2, 3, 4, 5]))), "((1 2 _) 3 4)");
|
2357
|
-
});
|
2358
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.test)("list insertions", () => {
|
2359
|
-
let origin5 = [1, 2, 3, 4, 5];
|
2360
|
-
let data5 = (0,_list__WEBPACK_IMPORTED_MODULE_0__.initTernaryTreeList)(origin5);
|
2361
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.checkEqual)((0,_list__WEBPACK_IMPORTED_MODULE_0__.formatListInline)(data5), "((1 2 _) 3 (4 5 _))");
|
2362
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.checkEqual)((0,_list__WEBPACK_IMPORTED_MODULE_0__.formatListInline)((0,_list__WEBPACK_IMPORTED_MODULE_0__.insert)(data5, 0, 10, false)), "(10 ((1 2 _) 3 (4 5 _)) _)");
|
2363
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.checkEqual)((0,_list__WEBPACK_IMPORTED_MODULE_0__.formatListInline)((0,_list__WEBPACK_IMPORTED_MODULE_0__.insert)(data5, 0, 10, true)), "((1 10 2) 3 (4 5 _))");
|
2364
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.checkEqual)((0,_list__WEBPACK_IMPORTED_MODULE_0__.formatListInline)((0,_list__WEBPACK_IMPORTED_MODULE_0__.insert)(data5, 1, 10, false)), "((1 10 2) 3 (4 5 _))");
|
2365
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.checkEqual)((0,_list__WEBPACK_IMPORTED_MODULE_0__.formatListInline)((0,_list__WEBPACK_IMPORTED_MODULE_0__.insert)(data5, 1, 10, true)), "((1 2 10) 3 (4 5 _))");
|
2366
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.checkEqual)((0,_list__WEBPACK_IMPORTED_MODULE_0__.formatListInline)((0,_list__WEBPACK_IMPORTED_MODULE_0__.insert)(data5, 2, 10, false)), "((1 2 _) (10 3 _) (4 5 _))");
|
2367
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.checkEqual)((0,_list__WEBPACK_IMPORTED_MODULE_0__.formatListInline)((0,_list__WEBPACK_IMPORTED_MODULE_0__.insert)(data5, 2, 10, true)), "((1 2 _) (3 10 _) (4 5 _))");
|
2368
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.checkEqual)((0,_list__WEBPACK_IMPORTED_MODULE_0__.formatListInline)((0,_list__WEBPACK_IMPORTED_MODULE_0__.insert)(data5, 3, 10, false)), "((1 2 _) 3 (10 4 5))");
|
2369
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.checkEqual)((0,_list__WEBPACK_IMPORTED_MODULE_0__.formatListInline)((0,_list__WEBPACK_IMPORTED_MODULE_0__.insert)(data5, 3, 10, true)), "((1 2 _) 3 (4 10 5))");
|
2370
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.checkEqual)((0,_list__WEBPACK_IMPORTED_MODULE_0__.formatListInline)((0,_list__WEBPACK_IMPORTED_MODULE_0__.insert)(data5, 4, 10, false)), "((1 2 _) 3 (4 10 5))");
|
2371
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.checkEqual)((0,_list__WEBPACK_IMPORTED_MODULE_0__.formatListInline)((0,_list__WEBPACK_IMPORTED_MODULE_0__.insert)(data5, 4, 10, true)), "(((1 2 _) 3 (4 5 _)) 10 _)");
|
2372
|
-
let origin4 = [1, 2, 3, 4];
|
2373
|
-
let data4 = (0,_list__WEBPACK_IMPORTED_MODULE_0__.initTernaryTreeList)(origin4);
|
2374
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.checkEqual)((0,_list__WEBPACK_IMPORTED_MODULE_0__.formatListInline)((0,_list__WEBPACK_IMPORTED_MODULE_0__.assocBefore)(data4, 3, 10)), "(1 (2 3 _) (10 4 _))");
|
2375
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.checkEqual)((0,_list__WEBPACK_IMPORTED_MODULE_0__.formatListInline)((0,_list__WEBPACK_IMPORTED_MODULE_0__.assocAfter)(data4, 3, 10)), "(1 (2 3 _) (4 10 _))");
|
2376
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.checkEqual)((0,_list__WEBPACK_IMPORTED_MODULE_0__.formatListInline)((0,_list__WEBPACK_IMPORTED_MODULE_0__.prepend)(data4, 10)), "((10 1 _) (2 3 _) 4)");
|
2377
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.checkEqual)((0,_list__WEBPACK_IMPORTED_MODULE_0__.formatListInline)((0,_list__WEBPACK_IMPORTED_MODULE_0__.append)(data4, 10)), "(1 (2 3 _) (4 10 _))");
|
2378
|
-
});
|
2379
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.test)("concat", () => {
|
2380
|
-
let data1 = (0,_list__WEBPACK_IMPORTED_MODULE_0__.initTernaryTreeList)([1, 2]);
|
2381
|
-
let data2 = (0,_list__WEBPACK_IMPORTED_MODULE_0__.initTernaryTreeList)([3, 4]);
|
2382
|
-
let data3 = (0,_list__WEBPACK_IMPORTED_MODULE_0__.initTernaryTreeList)([5, 6]);
|
2383
|
-
let data4 = (0,_list__WEBPACK_IMPORTED_MODULE_0__.initTernaryTreeList)([7, 8]);
|
2384
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.check)((0,_list__WEBPACK_IMPORTED_MODULE_0__.formatListInline)((0,_list__WEBPACK_IMPORTED_MODULE_0__.concat)(data1, data2)) === "((1 2 _) (3 4 _) _)");
|
2385
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.check)((0,_list__WEBPACK_IMPORTED_MODULE_0__.formatListInline)((0,_list__WEBPACK_IMPORTED_MODULE_0__.concat)((0,_list__WEBPACK_IMPORTED_MODULE_0__.initTernaryTreeList)([]), data1)) === "(1 2 _)");
|
2386
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.check)((0,_list__WEBPACK_IMPORTED_MODULE_0__.formatListInline)((0,_list__WEBPACK_IMPORTED_MODULE_0__.concat)(data1, data2, data3)) === "((1 2 _) (3 4 _) (5 6 _))");
|
2387
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.check)((0,_list__WEBPACK_IMPORTED_MODULE_0__.formatListInline)((0,_list__WEBPACK_IMPORTED_MODULE_0__.concat)(data1, data2, data3, data4)) === "((1 2 _) ((3 4 _) (5 6 _) _) (7 8 _))");
|
2388
|
-
(0,_list__WEBPACK_IMPORTED_MODULE_0__.checkListStructure)((0,_list__WEBPACK_IMPORTED_MODULE_0__.concat)(data1, data2));
|
2389
|
-
(0,_list__WEBPACK_IMPORTED_MODULE_0__.checkListStructure)((0,_list__WEBPACK_IMPORTED_MODULE_0__.concat)(data1, data2, data3));
|
2390
|
-
(0,_list__WEBPACK_IMPORTED_MODULE_0__.checkListStructure)((0,_list__WEBPACK_IMPORTED_MODULE_0__.concat)(data1, data2, data3, data4));
|
2391
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.check)((0,_list__WEBPACK_IMPORTED_MODULE_0__.listLen)((0,_list__WEBPACK_IMPORTED_MODULE_0__.concat)(data1, data2, data3, data4)) === 8);
|
2392
|
-
});
|
2393
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.test)("check(equality", () => {
|
2394
|
-
let origin4 = [1, 2, 3, 4];
|
2395
|
-
let data4 = (0,_list__WEBPACK_IMPORTED_MODULE_0__.initTernaryTreeList)(origin4);
|
2396
|
-
let data4n = (0,_list__WEBPACK_IMPORTED_MODULE_0__.initTernaryTreeList)(origin4);
|
2397
|
-
let data4Made = (0,_list__WEBPACK_IMPORTED_MODULE_0__.prepend)((0,_list__WEBPACK_IMPORTED_MODULE_0__.initTernaryTreeList)([2, 3, 4]), 1);
|
2398
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.check)((0,_list__WEBPACK_IMPORTED_MODULE_0__.sameListShape)(data4, data4) === true);
|
2399
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.check)((0,_list__WEBPACK_IMPORTED_MODULE_0__.sameListShape)(data4, data4n) === true);
|
2400
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.check)((0,_list__WEBPACK_IMPORTED_MODULE_0__.sameListShape)(data4, data4Made) === false);
|
2401
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.check)((0,_list__WEBPACK_IMPORTED_MODULE_0__.listEqual)(data4, data4n));
|
2402
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.check)((0,_list__WEBPACK_IMPORTED_MODULE_0__.listEqual)(data4, data4Made));
|
2403
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.check)((0,_list__WEBPACK_IMPORTED_MODULE_0__.listEqual)(data4n, data4Made));
|
2404
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.check)(data4 !== data4Made); // identical false
|
2405
|
-
});
|
2406
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.test)("force balancing", () => {
|
2407
|
-
var data = (0,_list__WEBPACK_IMPORTED_MODULE_0__.initTernaryTreeList)([]);
|
2408
|
-
for (let idx = 0; idx < 20; idx++) {
|
2409
|
-
data = (0,_list__WEBPACK_IMPORTED_MODULE_0__.append)(data, idx, true);
|
2410
|
-
}
|
2411
|
-
// echo data.formatInline
|
2412
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.check)((0,_list__WEBPACK_IMPORTED_MODULE_0__.formatListInline)(data) === "(((0 1 2) (3 4 5) (6 7 8)) ((9 10 11) (12 13 14) (15 16 17)) (18 19 _))");
|
2413
|
-
(0,_list__WEBPACK_IMPORTED_MODULE_0__.forceListInplaceBalancing)(data);
|
2414
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.check)((0,_list__WEBPACK_IMPORTED_MODULE_0__.formatListInline)(data) === "(((0 1 _) (2 3 4) (5 6 _)) ((7 8 _) (9 10 _) (11 12 _)) ((13 14 _) (15 16 17) (18 19 _)))");
|
2415
|
-
// echo data.formatInline
|
2416
|
-
});
|
2417
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.test)("iterator", () => {
|
2418
|
-
let origin4 = [1, 2, 3, 4];
|
2419
|
-
let data4 = (0,_list__WEBPACK_IMPORTED_MODULE_0__.initTernaryTreeList)(origin4);
|
2420
|
-
var i = 0;
|
2421
|
-
for (let item of (0,_list__WEBPACK_IMPORTED_MODULE_0__.listToItems)(data4)) {
|
2422
|
-
i = i + 1;
|
2423
|
-
}
|
2424
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.check)(i === 4);
|
2425
|
-
i = 0;
|
2426
|
-
for (let [idx, item] of (0,_list__WEBPACK_IMPORTED_MODULE_0__.listToPairs)(data4)) {
|
2427
|
-
i = i + idx;
|
2428
|
-
}
|
2429
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.check)(i === 6);
|
2430
|
-
});
|
2431
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.test)("check structure", () => {
|
2432
|
-
var data = (0,_list__WEBPACK_IMPORTED_MODULE_0__.initTernaryTreeList)([]);
|
2433
|
-
for (let idx = 0; idx < 20; idx++) {
|
2434
|
-
data = (0,_list__WEBPACK_IMPORTED_MODULE_0__.append)(data, idx, true);
|
2435
|
-
}
|
2436
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.check)((0,_list__WEBPACK_IMPORTED_MODULE_0__.checkListStructure)(data));
|
2437
|
-
let origin11 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11];
|
2438
|
-
let data11 = (0,_list__WEBPACK_IMPORTED_MODULE_0__.initTernaryTreeList)(origin11);
|
2439
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.check)((0,_list__WEBPACK_IMPORTED_MODULE_0__.checkListStructure)(data11));
|
2440
|
-
});
|
2441
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.test)("slices", () => {
|
2442
|
-
var data = (0,_list__WEBPACK_IMPORTED_MODULE_0__.initTernaryTreeList)([]);
|
2443
|
-
for (let idx = 0; idx < 40; idx++) {
|
2444
|
-
data = (0,_list__WEBPACK_IMPORTED_MODULE_0__.append)(data, idx, true);
|
2445
|
-
}
|
2446
|
-
var list40 = [];
|
2447
|
-
for (let idx = 0; idx < 40; idx++) {
|
2448
|
-
list40.push(idx);
|
2449
|
-
}
|
2450
|
-
for (let i = 0; i < 40; i++) {
|
2451
|
-
for (let j = i; j < 40; j++) {
|
2452
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.check)((0,_utils__WEBPACK_IMPORTED_MODULE_1__.arrayEqual)([...(0,_list__WEBPACK_IMPORTED_MODULE_0__.listToItems)((0,_list__WEBPACK_IMPORTED_MODULE_0__.slice)(data, i, j))], list40.slice(i, j)));
|
2453
|
-
}
|
2454
|
-
}
|
2455
|
-
});
|
2456
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.test)("reverse", () => {
|
2457
|
-
let data = (0,_list__WEBPACK_IMPORTED_MODULE_0__.initTernaryTreeList)([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
|
2458
|
-
let reversedData = (0,_list__WEBPACK_IMPORTED_MODULE_0__.reverse)(data);
|
2459
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.check)((0,_utils__WEBPACK_IMPORTED_MODULE_1__.arrayEqual)([...(0,_list__WEBPACK_IMPORTED_MODULE_0__.listToItems)(data)].reverse(), [...(0,_list__WEBPACK_IMPORTED_MODULE_0__.listToItems)(reversedData)]));
|
2460
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.check)((0,_list__WEBPACK_IMPORTED_MODULE_0__.checkListStructure)(reversedData));
|
2461
|
-
});
|
2462
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.test)("list traverse", () => {
|
2463
|
-
var i = 0;
|
2464
|
-
let data = (0,_list__WEBPACK_IMPORTED_MODULE_0__.initTernaryTreeList)([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
|
2465
|
-
for (let x of (0,_list__WEBPACK_IMPORTED_MODULE_0__.listToItems)(data)) {
|
2466
|
-
i = i + 1;
|
2467
|
-
}
|
2468
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.check)(i === 10);
|
2469
|
-
});
|
2470
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.test)("index of", () => {
|
2471
|
-
let data = (0,_list__WEBPACK_IMPORTED_MODULE_0__.initTernaryTreeList)([1, 2, 3, 4, 5, 6, 7, 8]);
|
2472
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.check)((0,_list__WEBPACK_IMPORTED_MODULE_0__.indexOf)(data, 2) === 1);
|
2473
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.check)((0,_list__WEBPACK_IMPORTED_MODULE_0__.findIndex)(data, (x) => x === 2) === 1);
|
2474
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.check)((0,_list__WEBPACK_IMPORTED_MODULE_0__.indexOf)(data, 9) === -1);
|
2475
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.check)((0,_list__WEBPACK_IMPORTED_MODULE_0__.findIndex)(data, (x) => x === 9) === -1);
|
2476
|
-
});
|
2477
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.test)("map values", () => {
|
2478
|
-
let data = (0,_list__WEBPACK_IMPORTED_MODULE_0__.initTernaryTreeList)([1, 2, 3, 4]);
|
2479
|
-
let data2 = (0,_list__WEBPACK_IMPORTED_MODULE_0__.initTernaryTreeList)([1, 4, 9, 16]);
|
2480
|
-
let data3 = (0,_list__WEBPACK_IMPORTED_MODULE_0__.listMapValues)(data, (x) => x * x);
|
2481
|
-
(0,_list__WEBPACK_IMPORTED_MODULE_0__.checkListStructure)(data3);
|
2482
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.check)((0,_list__WEBPACK_IMPORTED_MODULE_0__.listEqual)(data2, data3));
|
2483
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.check)((0,_list__WEBPACK_IMPORTED_MODULE_0__.formatListInline)(data2) == (0,_list__WEBPACK_IMPORTED_MODULE_0__.formatListInline)(data3));
|
2484
|
-
});
|
2485
|
-
};
|
2486
|
-
|
2487
|
-
|
2488
|
-
/***/ }),
|
2489
|
-
|
2490
|
-
/***/ "./lib/test-map.js":
|
2491
|
-
/*!*************************!*\
|
2492
|
-
!*** ./lib/test-map.js ***!
|
2493
|
-
\*************************/
|
2494
|
-
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
2495
|
-
|
2496
|
-
__webpack_require__.r(__webpack_exports__);
|
2497
|
-
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
2498
|
-
/* harmony export */ "runMapTests": () => /* binding */ runMapTests
|
2499
|
-
/* harmony export */ });
|
2500
|
-
/* harmony import */ var _types__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./types */ "./lib/types.js");
|
2501
|
-
/* harmony import */ var _utils__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./utils */ "./lib/utils.js");
|
2502
|
-
/* harmony import */ var _map__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./map */ "./lib/map.js");
|
2503
|
-
|
2504
|
-
|
2505
|
-
|
2506
|
-
let runMapTests = () => {
|
2507
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.test)("init map", () => {
|
2508
|
-
var dict = new Map();
|
2509
|
-
var inList = [];
|
2510
|
-
for (let idx = 0; idx < 10; idx++) {
|
2511
|
-
dict.set(`${idx}`, idx + 10);
|
2512
|
-
inList.push([`${idx}`, idx + 10]);
|
2513
|
-
}
|
2514
|
-
// TODO
|
2515
|
-
inList.sort((x, y) => {
|
2516
|
-
let hx = (0,_types__WEBPACK_IMPORTED_MODULE_0__.hashGenerator)(x[0]);
|
2517
|
-
let hy = (0,_types__WEBPACK_IMPORTED_MODULE_0__.hashGenerator)(y[0]);
|
2518
|
-
return (0,_utils__WEBPACK_IMPORTED_MODULE_1__.cmp)(hx, hy);
|
2519
|
-
});
|
2520
|
-
let data10 = (0,_map__WEBPACK_IMPORTED_MODULE_2__.initTernaryTreeMap)(dict);
|
2521
|
-
let data11 = (0,_map__WEBPACK_IMPORTED_MODULE_2__.initTernaryTreeMap)(inList);
|
2522
|
-
(0,_map__WEBPACK_IMPORTED_MODULE_2__.checkMapStructure)(data10);
|
2523
|
-
(0,_map__WEBPACK_IMPORTED_MODULE_2__.checkMapStructure)(data11);
|
2524
|
-
// echo data10
|
2525
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.justDisplay)((0,_map__WEBPACK_IMPORTED_MODULE_2__.formatMapInline)(data10, true), " ((0:10 1:11 2:12) (3:13 (4:14 5:15 _) 6:16) (7:17 8:18 9:19))");
|
2526
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.check)((0,_utils__WEBPACK_IMPORTED_MODULE_1__.deepEqual)((0,_map__WEBPACK_IMPORTED_MODULE_2__.toHashSortedPairs)(data10), inList));
|
2527
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.check)((0,_utils__WEBPACK_IMPORTED_MODULE_1__.deepEqual)((0,_map__WEBPACK_IMPORTED_MODULE_2__.toHashSortedPairs)(data11), inList));
|
2528
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.check)((0,_map__WEBPACK_IMPORTED_MODULE_2__.contains)(data10, "1") == true);
|
2529
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.check)((0,_map__WEBPACK_IMPORTED_MODULE_2__.contains)(data10, "11") == false);
|
2530
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.check)((0,_utils__WEBPACK_IMPORTED_MODULE_1__.deepEqual)((0,_map__WEBPACK_IMPORTED_MODULE_2__.mapGetDefault)(data10, "1", null), 11));
|
2531
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.check)((0,_utils__WEBPACK_IMPORTED_MODULE_1__.deepEqual)((0,_map__WEBPACK_IMPORTED_MODULE_2__.mapGetDefault)(data10, "111", 0), 0));
|
2532
|
-
// check(deepEqual(mapGetDefault(data10, "11", {} as any), null)); // should throws error
|
2533
|
-
let emptyData = new Map();
|
2534
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.check)((0,_map__WEBPACK_IMPORTED_MODULE_2__.mapEqual)((0,_map__WEBPACK_IMPORTED_MODULE_2__.initEmptyTernaryTreeMap)(), (0,_map__WEBPACK_IMPORTED_MODULE_2__.initTernaryTreeMap)(emptyData)));
|
2535
|
-
});
|
2536
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.test)("assoc and contains", () => {
|
2537
|
-
var dict = new Map();
|
2538
|
-
for (let idx = 0; idx < 100; idx++) {
|
2539
|
-
dict.set(`${idx * 2}`, idx);
|
2540
|
-
}
|
2541
|
-
let data = (0,_map__WEBPACK_IMPORTED_MODULE_2__.initTernaryTreeMap)(dict);
|
2542
|
-
for (let idx = 0; idx < 100; idx++) {
|
2543
|
-
dict.set(`${idx * 2 + 1}`, idx);
|
2544
|
-
let data2 = (0,_map__WEBPACK_IMPORTED_MODULE_2__.assocMap)(data, `${idx * 2 + 1}`, idx);
|
2545
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.check)((0,_map__WEBPACK_IMPORTED_MODULE_2__.contains)(data2, `${idx * 2 + 1}`));
|
2546
|
-
}
|
2547
|
-
var dict = new Map();
|
2548
|
-
data = (0,_map__WEBPACK_IMPORTED_MODULE_2__.initTernaryTreeMap)(dict);
|
2549
|
-
for (let idx = 0; idx < 1000; idx++) {
|
2550
|
-
let p = 100 - idx / 10;
|
2551
|
-
data = (0,_map__WEBPACK_IMPORTED_MODULE_2__.assocMap)(data, `${p}`, idx);
|
2552
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.check)((0,_map__WEBPACK_IMPORTED_MODULE_2__.contains)(data, `${p}`));
|
2553
|
-
}
|
2554
|
-
});
|
2555
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.test)("check structure", () => {
|
2556
|
-
var dict = new Map();
|
2557
|
-
for (let idx = 0; idx < 100; idx++) {
|
2558
|
-
dict.set(`${idx}`, idx + 10);
|
2559
|
-
}
|
2560
|
-
let data = (0,_map__WEBPACK_IMPORTED_MODULE_2__.initTernaryTreeMap)(dict);
|
2561
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.check)((0,_map__WEBPACK_IMPORTED_MODULE_2__.checkMapStructure)(data));
|
2562
|
-
});
|
2563
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.test)("assoc map", () => {
|
2564
|
-
var dict = new Map();
|
2565
|
-
for (let idx = 0; idx < 10; idx++) {
|
2566
|
-
dict.set(`${idx}`, idx + 10);
|
2567
|
-
}
|
2568
|
-
let data = (0,_map__WEBPACK_IMPORTED_MODULE_2__.initTernaryTreeMap)(dict);
|
2569
|
-
// echo data.formatInline
|
2570
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.check)((0,_map__WEBPACK_IMPORTED_MODULE_2__.contains)(data, "1") == true);
|
2571
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.check)((0,_map__WEBPACK_IMPORTED_MODULE_2__.contains)(data, "12") == false);
|
2572
|
-
(0,_map__WEBPACK_IMPORTED_MODULE_2__.checkMapStructure)(data);
|
2573
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.justDisplay)((0,_map__WEBPACK_IMPORTED_MODULE_2__.formatMapInline)((0,_map__WEBPACK_IMPORTED_MODULE_2__.assocMap)(data, "1", 2222), true), "((0:10 1:2222 2:12) (3:13 (4:14 5:15 _) 6:16) (7:17 8:18 9:19))");
|
2574
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.justDisplay)((0,_map__WEBPACK_IMPORTED_MODULE_2__.formatMapInline)((0,_map__WEBPACK_IMPORTED_MODULE_2__.assocMap)(data, "23", 2222), true), "(((0:10 1:11 2:12) (3:13 (4:14 5:15 _) 6:16) (7:17 8:18 9:19)) 23:2222 _)");
|
2575
|
-
});
|
2576
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.test)("dissoc", () => {
|
2577
|
-
var dict = new Map();
|
2578
|
-
for (let idx = 0; idx < 10; idx++) {
|
2579
|
-
dict.set(`${idx}`, idx + 10);
|
2580
|
-
}
|
2581
|
-
let data = (0,_map__WEBPACK_IMPORTED_MODULE_2__.initTernaryTreeMap)(dict);
|
2582
|
-
(0,_map__WEBPACK_IMPORTED_MODULE_2__.checkMapStructure)(data);
|
2583
|
-
// echo data.formatInline
|
2584
|
-
for (let idx = 0; idx < 10; idx++) {
|
2585
|
-
let v = (0,_map__WEBPACK_IMPORTED_MODULE_2__.dissocMap)(data, `${idx}`);
|
2586
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.check)((0,_map__WEBPACK_IMPORTED_MODULE_2__.contains)(v, `${idx}`) == false);
|
2587
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.check)((0,_map__WEBPACK_IMPORTED_MODULE_2__.contains)(data, `${idx}`) == true);
|
2588
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.check)((0,_map__WEBPACK_IMPORTED_MODULE_2__.mapLen)(v) == (0,_map__WEBPACK_IMPORTED_MODULE_2__.mapLen)(data) - 1);
|
2589
|
-
}
|
2590
|
-
for (let idx = 10; idx < 12; idx++) {
|
2591
|
-
let v = (0,_map__WEBPACK_IMPORTED_MODULE_2__.dissocMap)(data, `${idx}`);
|
2592
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.check)((0,_map__WEBPACK_IMPORTED_MODULE_2__.contains)(v, `${idx}`) == false);
|
2593
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.check)((0,_map__WEBPACK_IMPORTED_MODULE_2__.mapLen)(v) == (0,_map__WEBPACK_IMPORTED_MODULE_2__.mapLen)(data));
|
2594
|
-
}
|
2595
|
-
});
|
2596
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.test)("to array", () => {
|
2597
|
-
var dict = new Map();
|
2598
|
-
for (let idx = 0; idx < 10; idx++) {
|
2599
|
-
dict.set(`${idx}`, idx + 10);
|
2600
|
-
}
|
2601
|
-
let data = (0,_map__WEBPACK_IMPORTED_MODULE_2__.initTernaryTreeMap)(dict);
|
2602
|
-
(0,_map__WEBPACK_IMPORTED_MODULE_2__.checkMapStructure)(data);
|
2603
|
-
// TODO
|
2604
|
-
// justDisplay((mapToString(toPairs(data))) , "@[2:12, 3:13, 7:17, 9:19, 6:16, 5:15, 1:11, 8:18, 0:10, 4:14]")
|
2605
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.justDisplay)([...(0,_map__WEBPACK_IMPORTED_MODULE_2__.toKeys)(data)], ["2", "3", "7", "9", "6", "5", "1", "8", "0", "4"]);
|
2606
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.check)((0,_utils__WEBPACK_IMPORTED_MODULE_1__.deepEqual)((0,_map__WEBPACK_IMPORTED_MODULE_2__.toPairsArray)(data), [...(0,_map__WEBPACK_IMPORTED_MODULE_2__.toPairs)(data)]));
|
2607
|
-
});
|
2608
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.test)("Equality", () => {
|
2609
|
-
var dict = new Map();
|
2610
|
-
for (let idx = 0; idx < 10; idx++) {
|
2611
|
-
dict.set(`${idx}`, idx + 10);
|
2612
|
-
}
|
2613
|
-
let data = (0,_map__WEBPACK_IMPORTED_MODULE_2__.initTernaryTreeMap)(dict);
|
2614
|
-
let b = (0,_map__WEBPACK_IMPORTED_MODULE_2__.dissocMap)(data, "3");
|
2615
|
-
(0,_map__WEBPACK_IMPORTED_MODULE_2__.checkMapStructure)(data);
|
2616
|
-
(0,_map__WEBPACK_IMPORTED_MODULE_2__.checkMapStructure)(b);
|
2617
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.check)((0,_map__WEBPACK_IMPORTED_MODULE_2__.mapEqual)(data, data));
|
2618
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.check)(!(0,_map__WEBPACK_IMPORTED_MODULE_2__.mapEqual)(data, b));
|
2619
|
-
let c = (0,_map__WEBPACK_IMPORTED_MODULE_2__.assocMap)(data, "3", 15);
|
2620
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.check)((0,_map__WEBPACK_IMPORTED_MODULE_2__.sameMapShape)(data, data));
|
2621
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.check)((0,_map__WEBPACK_IMPORTED_MODULE_2__.sameMapShape)(data, b) == false);
|
2622
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.check)((0,_map__WEBPACK_IMPORTED_MODULE_2__.sameMapShape)(data, c) == false);
|
2623
|
-
let d = (0,_map__WEBPACK_IMPORTED_MODULE_2__.assocMap)(c, "3", 13);
|
2624
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.check)((0,_map__WEBPACK_IMPORTED_MODULE_2__.mapEqual)(data, d));
|
2625
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.check)(data !== d); // not identical
|
2626
|
-
});
|
2627
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.test)("Merge", () => {
|
2628
|
-
var dict = new Map();
|
2629
|
-
var dictBoth = new Map();
|
2630
|
-
for (let idx = 0; idx < 4; idx++) {
|
2631
|
-
dict.set(`${idx}`, idx + 10);
|
2632
|
-
dictBoth.set(`${idx}`, idx + 10);
|
2633
|
-
}
|
2634
|
-
let data = (0,_map__WEBPACK_IMPORTED_MODULE_2__.initTernaryTreeMap)(dict);
|
2635
|
-
(0,_map__WEBPACK_IMPORTED_MODULE_2__.checkMapStructure)(data);
|
2636
|
-
var dictB = new Map();
|
2637
|
-
for (let idx = 10; idx < 14; idx++) {
|
2638
|
-
dictB.set(`${idx}`, idx + 23);
|
2639
|
-
dictBoth.set(`${idx}`, idx + 23);
|
2640
|
-
}
|
2641
|
-
let b = (0,_map__WEBPACK_IMPORTED_MODULE_2__.initTernaryTreeMap)(dictB);
|
2642
|
-
let merged = (0,_map__WEBPACK_IMPORTED_MODULE_2__.merge)(data, b);
|
2643
|
-
let both = (0,_map__WEBPACK_IMPORTED_MODULE_2__.initTernaryTreeMap)(dictBoth);
|
2644
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.check)((0,_map__WEBPACK_IMPORTED_MODULE_2__.mapEqual)(merged, both));
|
2645
|
-
});
|
2646
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.test)("Merge skip", () => {
|
2647
|
-
var dict = new Map();
|
2648
|
-
for (let idx = 0; idx < 4; idx++) {
|
2649
|
-
dict.set(`${idx}`, idx + 10);
|
2650
|
-
}
|
2651
|
-
let a = (0,_map__WEBPACK_IMPORTED_MODULE_2__.initTernaryTreeMap)(dict);
|
2652
|
-
(0,_map__WEBPACK_IMPORTED_MODULE_2__.checkMapStructure)(a);
|
2653
|
-
var dict2 = new Map();
|
2654
|
-
for (let idx = 0; idx < 4; idx++) {
|
2655
|
-
dict2.set(`${idx}`, idx + 11);
|
2656
|
-
}
|
2657
|
-
let b = (0,_map__WEBPACK_IMPORTED_MODULE_2__.initTernaryTreeMap)(dict2);
|
2658
|
-
(0,_map__WEBPACK_IMPORTED_MODULE_2__.checkMapStructure)(b);
|
2659
|
-
let c = (0,_map__WEBPACK_IMPORTED_MODULE_2__.mergeSkip)(a, b, 11);
|
2660
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.check)((0,_utils__WEBPACK_IMPORTED_MODULE_1__.deepEqual)((0,_map__WEBPACK_IMPORTED_MODULE_2__.mapGetDefault)(c, "0", null), 10));
|
2661
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.check)((0,_utils__WEBPACK_IMPORTED_MODULE_1__.deepEqual)((0,_map__WEBPACK_IMPORTED_MODULE_2__.mapGetDefault)(c, "1", null), 12));
|
2662
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.check)((0,_utils__WEBPACK_IMPORTED_MODULE_1__.deepEqual)((0,_map__WEBPACK_IMPORTED_MODULE_2__.mapGetDefault)(c, "2", null), 13));
|
2663
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.check)((0,_utils__WEBPACK_IMPORTED_MODULE_1__.deepEqual)((0,_map__WEBPACK_IMPORTED_MODULE_2__.mapGetDefault)(c, "3", null), 14));
|
2664
|
-
});
|
2665
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.test)("iterator", () => {
|
2666
|
-
var dict = new Map();
|
2667
|
-
var dictBoth = new Map();
|
2668
|
-
for (let idx = 0; idx < 4; idx++) {
|
2669
|
-
dict.set(`${idx}`, idx + 10);
|
2670
|
-
dictBoth.set(`${idx}`, idx + 10);
|
2671
|
-
}
|
2672
|
-
let data = (0,_map__WEBPACK_IMPORTED_MODULE_2__.initTernaryTreeMap)(dict);
|
2673
|
-
(0,_map__WEBPACK_IMPORTED_MODULE_2__.checkMapStructure)(data);
|
2674
|
-
var i = 0;
|
2675
|
-
for (let [k, v] of (0,_map__WEBPACK_IMPORTED_MODULE_2__.toPairs)(data)) {
|
2676
|
-
i = i + 1;
|
2677
|
-
}
|
2678
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.check)(i == 4);
|
2679
|
-
i = 0;
|
2680
|
-
for (let key of (0,_map__WEBPACK_IMPORTED_MODULE_2__.toPairs)(data)) {
|
2681
|
-
i = i + 1;
|
2682
|
-
}
|
2683
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.check)(i == 4);
|
2684
|
-
});
|
2685
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.test)("each map", () => {
|
2686
|
-
var dict = new Map();
|
2687
|
-
for (let idx = 0; idx < 100; idx++) {
|
2688
|
-
dict.set(`${idx}`, idx + 10);
|
2689
|
-
}
|
2690
|
-
let data = (0,_map__WEBPACK_IMPORTED_MODULE_2__.initTernaryTreeMap)(dict);
|
2691
|
-
(0,_map__WEBPACK_IMPORTED_MODULE_2__.checkMapStructure)(data);
|
2692
|
-
var i = 0;
|
2693
|
-
for (let [k, v] of (0,_map__WEBPACK_IMPORTED_MODULE_2__.toPairs)(data)) {
|
2694
|
-
// echo "..{k}-{v}.."
|
2695
|
-
i = i + 1;
|
2696
|
-
}
|
2697
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.check)(i == 100);
|
2698
|
-
});
|
2699
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.test)("map values", () => {
|
2700
|
-
var dict = new Map();
|
2701
|
-
for (let idx = 0; idx < 4; idx++) {
|
2702
|
-
dict.set(`${idx}`, idx + 10);
|
2703
|
-
}
|
2704
|
-
let data = (0,_map__WEBPACK_IMPORTED_MODULE_2__.initTernaryTreeMap)(dict);
|
2705
|
-
var dict2 = new Map();
|
2706
|
-
for (let idx = 0; idx < 4; idx++) {
|
2707
|
-
dict2.set(`${idx}`, idx + 20);
|
2708
|
-
}
|
2709
|
-
let data2 = (0,_map__WEBPACK_IMPORTED_MODULE_2__.initTernaryTreeMap)(dict2);
|
2710
|
-
let data3 = (0,_map__WEBPACK_IMPORTED_MODULE_2__.mapMapValues)(data, (x) => x + 10);
|
2711
|
-
(0,_map__WEBPACK_IMPORTED_MODULE_2__.checkMapStructure)(data3);
|
2712
|
-
(0,_map__WEBPACK_IMPORTED_MODULE_2__.checkMapStructure)(data3);
|
2713
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.check)((0,_map__WEBPACK_IMPORTED_MODULE_2__.mapEqual)(data2, data3));
|
2714
|
-
(0,_utils__WEBPACK_IMPORTED_MODULE_1__.check)((0,_map__WEBPACK_IMPORTED_MODULE_2__.formatMapInline)(data2) === (0,_map__WEBPACK_IMPORTED_MODULE_2__.formatMapInline)(data3));
|
2715
|
-
});
|
2716
|
-
};
|
2717
|
-
|
2718
|
-
|
2719
|
-
/***/ }),
|
2720
|
-
|
2721
|
-
/***/ "./lib/types.js":
|
2722
|
-
/*!**********************!*\
|
2723
|
-
!*** ./lib/types.js ***!
|
2724
|
-
\**********************/
|
2725
|
-
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
2726
|
-
|
2727
|
-
__webpack_require__.r(__webpack_exports__);
|
2728
|
-
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
2729
|
-
/* harmony export */ "TernaryTreeKind": () => /* binding */ TernaryTreeKind,
|
2730
|
-
/* harmony export */ "valueHash": () => /* binding */ valueHash,
|
2731
|
-
/* harmony export */ "hashGenerator": () => /* binding */ hashGenerator,
|
2732
|
-
/* harmony export */ "overwriteHashGenerator": () => /* binding */ overwriteHashGenerator,
|
2733
|
-
/* harmony export */ "mergeValueHash": () => /* binding */ mergeValueHash
|
2734
|
-
/* harmony export */ });
|
2735
|
-
var TernaryTreeKind;
|
2736
|
-
(function (TernaryTreeKind) {
|
2737
|
-
TernaryTreeKind[TernaryTreeKind["ternaryTreeBranch"] = 0] = "ternaryTreeBranch";
|
2738
|
-
TernaryTreeKind[TernaryTreeKind["ternaryTreeLeaf"] = 1] = "ternaryTreeLeaf";
|
2739
|
-
})(TernaryTreeKind || (TernaryTreeKind = {}));
|
2740
|
-
let valueHash = (x) => {
|
2741
|
-
if (typeof x === "number") {
|
2742
|
-
// console.log("hash for x:", x, "\t", result);
|
2743
|
-
return x;
|
2744
|
-
}
|
2745
|
-
else if (typeof x === "string") {
|
2746
|
-
let h = 0;
|
2747
|
-
// https://gist.github.com/hyamamoto/fd435505d29ebfa3d9716fd2be8d42f0#gistcomment-2775538
|
2748
|
-
for (var i = 0; i < x.length; i++) {
|
2749
|
-
h = Math.imul(31, h) + (x[i].charCodeAt(0) | 0);
|
2750
|
-
}
|
2751
|
-
// console.log("hash for x:", x, "\t", result);
|
2752
|
-
return h;
|
2753
|
-
}
|
2754
|
-
throw new Error("Hash solution not provided for this type(other than number and string)");
|
2755
|
-
};
|
2756
|
-
/** default hash function only handles number and string, need customization */
|
2757
|
-
let hashGenerator = valueHash;
|
2758
|
-
/** allow customizing hash function from outside */
|
2759
|
-
let overwriteHashGenerator = (f) => {
|
2760
|
-
hashGenerator = f;
|
2761
|
-
};
|
2762
|
-
let mergeValueHash = (base, x) => {
|
2763
|
-
if (typeof x === "number") {
|
2764
|
-
return Math.imul(31, base) + x;
|
2765
|
-
}
|
2766
|
-
else if (typeof x === "string") {
|
2767
|
-
let h = base;
|
2768
|
-
// https://gist.github.com/hyamamoto/fd435505d29ebfa3d9716fd2be8d42f0#gistcomment-2775538
|
2769
|
-
for (var i = 0; i < x.length; i++) {
|
2770
|
-
h = Math.imul(31, h) + (x[i].charCodeAt(0) | 0);
|
2771
|
-
}
|
2772
|
-
return h;
|
2773
|
-
}
|
2774
|
-
throw new Error("Hash solution not provided for this type(other than number and string)");
|
2775
|
-
};
|
2776
|
-
|
2777
|
-
|
2778
|
-
/***/ }),
|
2779
|
-
|
2780
|
-
/***/ "./lib/utils.js":
|
2781
|
-
/*!**********************!*\
|
2782
|
-
!*** ./lib/utils.js ***!
|
2783
|
-
\**********************/
|
2784
|
-
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
2785
|
-
|
2786
|
-
__webpack_require__.r(__webpack_exports__);
|
2787
|
-
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
2788
|
-
/* harmony export */ "dataEqual": () => /* binding */ dataEqual,
|
2789
|
-
/* harmony export */ "overwriteComparator": () => /* binding */ overwriteComparator,
|
2790
|
-
/* harmony export */ "roughIntPow": () => /* binding */ roughIntPow,
|
2791
|
-
/* harmony export */ "divideTernarySizes": () => /* binding */ divideTernarySizes,
|
2792
|
-
/* harmony export */ "shallowCloneArray": () => /* binding */ shallowCloneArray,
|
2793
|
-
/* harmony export */ "test": () => /* binding */ test,
|
2794
|
-
/* harmony export */ "check": () => /* binding */ check,
|
2795
|
-
/* harmony export */ "checkEqual": () => /* binding */ checkEqual,
|
2796
|
-
/* harmony export */ "justDisplay": () => /* binding */ justDisplay,
|
2797
|
-
/* harmony export */ "cmp": () => /* binding */ cmp,
|
2798
|
-
/* harmony export */ "deepEqual": () => /* binding */ deepEqual,
|
2799
|
-
/* harmony export */ "arrayEqual": () => /* binding */ arrayEqual
|
2800
|
-
/* harmony export */ });
|
2801
|
-
/** by default, it compares by reference
|
2802
|
-
* supposed to be overwritten by user
|
2803
|
-
*/
|
2804
|
-
let dataEqual = (x, y) => {
|
2805
|
-
return x === y;
|
2806
|
-
};
|
2807
|
-
let overwriteComparator = (f) => {
|
2808
|
-
dataEqual = f;
|
2809
|
-
};
|
2810
|
-
let roughIntPow = (x, times) => {
|
2811
|
-
if (times < 1) {
|
2812
|
-
return x;
|
2813
|
-
}
|
2814
|
-
let result = 1;
|
2815
|
-
for (let idx = 0; idx < times; idx++) {
|
2816
|
-
result = result * x;
|
2817
|
-
}
|
2818
|
-
return result;
|
2819
|
-
};
|
2820
|
-
let divideTernarySizes = (size) => {
|
2821
|
-
if (size < 0) {
|
2822
|
-
throw new Error("Unexpected negative size");
|
2823
|
-
}
|
2824
|
-
let extra = size % 3;
|
2825
|
-
let groupSize = Math.floor(size / 3);
|
2826
|
-
var leftSize = groupSize;
|
2827
|
-
var middleSize = groupSize;
|
2828
|
-
var rightSize = groupSize;
|
2829
|
-
switch (extra) {
|
2830
|
-
case 0:
|
2831
|
-
break;
|
2832
|
-
case 1:
|
2833
|
-
middleSize = middleSize + 1;
|
2834
|
-
break;
|
2835
|
-
case 2:
|
2836
|
-
leftSize = leftSize + 1;
|
2837
|
-
rightSize = rightSize + 1;
|
2838
|
-
break;
|
2839
|
-
default:
|
2840
|
-
throw new Error(`Unexpected mod result ${extra}`);
|
2841
|
-
}
|
2842
|
-
return { left: leftSize, middle: middleSize, right: rightSize };
|
2843
|
-
};
|
2844
|
-
function shallowCloneArray(xs) {
|
2845
|
-
let ys = new Array(xs.length);
|
2846
|
-
for (let i = 0; i < xs.length; i++) {
|
2847
|
-
ys[i] = xs[i];
|
2848
|
-
}
|
2849
|
-
return ys;
|
2850
|
-
}
|
2851
|
-
let test = (name, cb) => {
|
2852
|
-
console.log("Test:", name);
|
2853
|
-
cb();
|
2854
|
-
};
|
2855
|
-
let check = (x) => {
|
2856
|
-
if (!x) {
|
2857
|
-
throw new Error("Test failed");
|
2858
|
-
}
|
2859
|
-
};
|
2860
|
-
/** compare by reference */
|
2861
|
-
let checkEqual = (x, y) => {
|
2862
|
-
if (x !== y) {
|
2863
|
-
console.log("Left: ", x);
|
2864
|
-
console.log("Right: ", y);
|
2865
|
-
throw new Error("Test failed");
|
2866
|
-
}
|
2867
|
-
};
|
2868
|
-
let justDisplay = (x, y) => {
|
2869
|
-
console.group("Compare:");
|
2870
|
-
console.log(x);
|
2871
|
-
console.log(y);
|
2872
|
-
console.groupEnd();
|
2873
|
-
};
|
2874
|
-
let cmp = (x, y) => {
|
2875
|
-
if (x < y) {
|
2876
|
-
return -1;
|
2877
|
-
}
|
2878
|
-
if (x > y) {
|
2879
|
-
return 1;
|
2880
|
-
}
|
2881
|
-
return 0;
|
2882
|
-
};
|
2883
|
-
// https://stackoverflow.com/a/25456134/883571
|
2884
|
-
let deepEqual = function (x, y) {
|
2885
|
-
if (x === y) {
|
2886
|
-
return true;
|
2887
|
-
}
|
2888
|
-
else if (typeof x == "object" && x != null && typeof y == "object" && y != null) {
|
2889
|
-
if (Object.keys(x).length != Object.keys(y).length)
|
2890
|
-
return false;
|
2891
|
-
for (var prop in x) {
|
2892
|
-
if (y.hasOwnProperty(prop)) {
|
2893
|
-
if (!deepEqual(x[prop], y[prop]))
|
2894
|
-
return false;
|
2895
|
-
}
|
2896
|
-
else
|
2897
|
-
return false;
|
2898
|
-
}
|
2899
|
-
return true;
|
2900
|
-
}
|
2901
|
-
else
|
2902
|
-
return false;
|
2903
|
-
};
|
2904
|
-
let arrayEqual = (xs, ys) => {
|
2905
|
-
if (xs.length != ys.length) {
|
2906
|
-
return false;
|
2907
|
-
}
|
2908
|
-
for (let idx = 0; idx < xs.length; idx++) {
|
2909
|
-
if (xs[idx] !== ys[idx]) {
|
2910
|
-
return false;
|
2911
|
-
}
|
2912
|
-
}
|
2913
|
-
return true;
|
2914
|
-
};
|
2915
|
-
|
2916
|
-
|
2917
|
-
/***/ })
|
2918
|
-
|
2919
|
-
/******/ });
|
2920
|
-
/************************************************************************/
|
2921
|
-
/******/ // The module cache
|
2922
|
-
/******/ var __webpack_module_cache__ = {};
|
2923
|
-
/******/
|
2924
|
-
/******/ // The require function
|
2925
|
-
/******/ function __webpack_require__(moduleId) {
|
2926
|
-
/******/ // Check if module is in cache
|
2927
|
-
/******/ if(__webpack_module_cache__[moduleId]) {
|
2928
|
-
/******/ return __webpack_module_cache__[moduleId].exports;
|
2929
|
-
/******/ }
|
2930
|
-
/******/ // Create a new module (and put it into the cache)
|
2931
|
-
/******/ var module = __webpack_module_cache__[moduleId] = {
|
2932
|
-
/******/ // no module.id needed
|
2933
|
-
/******/ // no module.loaded needed
|
2934
|
-
/******/ exports: {}
|
2935
|
-
/******/ };
|
2936
|
-
/******/
|
2937
|
-
/******/ // Execute the module function
|
2938
|
-
/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
2939
|
-
/******/
|
2940
|
-
/******/ // Return the exports of the module
|
2941
|
-
/******/ return module.exports;
|
2942
|
-
/******/ }
|
2943
|
-
/******/
|
2944
|
-
/************************************************************************/
|
2945
|
-
/******/ /* webpack/runtime/define property getters */
|
2946
|
-
/******/ (() => {
|
2947
|
-
/******/ // define getter functions for harmony exports
|
2948
|
-
/******/ __webpack_require__.d = (exports, definition) => {
|
2949
|
-
/******/ for(var key in definition) {
|
2950
|
-
/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
|
2951
|
-
/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
|
2952
|
-
/******/ }
|
2953
|
-
/******/ }
|
2954
|
-
/******/ };
|
2955
|
-
/******/ })();
|
2956
|
-
/******/
|
2957
|
-
/******/ /* webpack/runtime/hasOwnProperty shorthand */
|
2958
|
-
/******/ (() => {
|
2959
|
-
/******/ __webpack_require__.o = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop)
|
2960
|
-
/******/ })();
|
2961
|
-
/******/
|
2962
|
-
/******/ /* webpack/runtime/make namespace object */
|
2963
|
-
/******/ (() => {
|
2964
|
-
/******/ // define __esModule on exports
|
2965
|
-
/******/ __webpack_require__.r = (exports) => {
|
2966
|
-
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
|
2967
|
-
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
2968
|
-
/******/ }
|
2969
|
-
/******/ Object.defineProperty(exports, '__esModule', { value: true });
|
2970
|
-
/******/ };
|
2971
|
-
/******/ })();
|
2972
|
-
/******/
|
2973
|
-
/************************************************************************/
|
2974
|
-
/******/ // startup
|
2975
|
-
/******/ // Load entry module
|
2976
|
-
/******/ __webpack_require__("./lib/main.js");
|
2977
|
-
/******/ // This entry module used 'exports' so it can't be inlined
|
2978
|
-
/******/ })()
|
2979
|
-
;
|