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