@tspro/ts-utils-lib 1.12.0 → 1.14.0

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/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /* TsUtilsLib v1.12.0 | (c) 2023 PahkaSoft | Licensed under the MIT License */
1
+ /* TsUtilsLib v1.14.0 | (c) 2023 PahkaSoft | Licensed under the MIT License */
2
2
  "use strict";
3
3
  var __defProp = Object.defineProperty;
4
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -30,6 +30,7 @@ __export(index_exports, {
30
30
  Map1: () => Map1,
31
31
  Map2: () => Map2,
32
32
  Map3: () => Map3,
33
+ SignedIndexArray: () => SignedIndexArray,
33
34
  SmallIntCache: () => SmallIntCache,
34
35
  Stack: () => Stack,
35
36
  Utils: () => utils_exports,
@@ -1292,10 +1293,234 @@ var SmallIntCache = class {
1292
1293
  }
1293
1294
  };
1294
1295
 
1296
+ // src/core/signed-index-array.ts
1297
+ var SignedIndexArray = class _SignedIndexArray {
1298
+ constructor(entries) {
1299
+ // for indexes >= 0
1300
+ __publicField(this, "posEl");
1301
+ __publicField(this, "hasPos");
1302
+ // for indexes < 0
1303
+ __publicField(this, "negEl");
1304
+ __publicField(this, "hasNeg");
1305
+ // number of elems
1306
+ __publicField(this, "elCount");
1307
+ if (entries instanceof _SignedIndexArray) {
1308
+ this.negEl = entries.negEl.slice();
1309
+ this.hasNeg = entries.hasNeg.slice();
1310
+ this.posEl = entries.posEl.slice();
1311
+ this.hasPos = entries.hasPos.slice();
1312
+ this.elCount = entries.elCount;
1313
+ } else {
1314
+ this.negEl = [];
1315
+ this.hasNeg = [];
1316
+ this.posEl = [];
1317
+ this.hasPos = [];
1318
+ this.elCount = 0;
1319
+ if (entries) {
1320
+ for (const [id, el] of entries) {
1321
+ this.set(id, el);
1322
+ }
1323
+ }
1324
+ }
1325
+ }
1326
+ static toNegIndex(id) {
1327
+ return -id - 1;
1328
+ }
1329
+ get size() {
1330
+ return this.elCount;
1331
+ }
1332
+ has(id) {
1333
+ if (!isInteger(id)) {
1334
+ return false;
1335
+ } else if (id >= 0) {
1336
+ return this.hasPos[id] === true;
1337
+ } else {
1338
+ return this.hasNeg[_SignedIndexArray.toNegIndex(id)] === true;
1339
+ }
1340
+ }
1341
+ set(id, el) {
1342
+ if (!isInteger(id)) {
1343
+ throw new Error("Index must be an integer");
1344
+ } else if (id >= 0) {
1345
+ if (this.hasPos[id] !== true) this.elCount++;
1346
+ this.posEl[id] = el;
1347
+ this.hasPos[id] = true;
1348
+ } else {
1349
+ if (this.hasNeg[_SignedIndexArray.toNegIndex(id)] !== true) this.elCount++;
1350
+ this.negEl[_SignedIndexArray.toNegIndex(id)] = el;
1351
+ this.hasNeg[_SignedIndexArray.toNegIndex(id)] = true;
1352
+ }
1353
+ }
1354
+ get(id) {
1355
+ if (!isInteger(id)) {
1356
+ throw new Error("Index must be an integer");
1357
+ } else if (id >= 0) {
1358
+ return this.hasPos[id] ? this.posEl[id] : void 0;
1359
+ } else {
1360
+ return this.hasNeg[_SignedIndexArray.toNegIndex(id)] ? this.negEl[_SignedIndexArray.toNegIndex(id)] : void 0;
1361
+ }
1362
+ }
1363
+ getOrDefault(id, defaultValue) {
1364
+ return this.get(id) ?? defaultValue;
1365
+ }
1366
+ getOrCreate(id, creatorOrValue) {
1367
+ if (!this.has(id)) {
1368
+ const value = isFunction(creatorOrValue) ? creatorOrValue() : creatorOrValue;
1369
+ this.set(id, value);
1370
+ return value;
1371
+ }
1372
+ return this.get(id);
1373
+ }
1374
+ delete(id) {
1375
+ if (!isInteger(id)) return false;
1376
+ const isPos = id >= 0;
1377
+ const arr = isPos ? this.posEl : this.negEl;
1378
+ const has = isPos ? this.hasPos : this.hasNeg;
1379
+ const idx = isPos ? id : _SignedIndexArray.toNegIndex(id);
1380
+ if (!has[idx]) return false;
1381
+ arr[idx] = void 0;
1382
+ has[idx] = false;
1383
+ this.elCount--;
1384
+ return true;
1385
+ }
1386
+ clear() {
1387
+ this.negEl = [];
1388
+ this.hasNeg = [];
1389
+ this.posEl = [];
1390
+ this.hasPos = [];
1391
+ this.elCount = 0;
1392
+ }
1393
+ forEach(callbackfn, thisArg) {
1394
+ for (const [id, el] of this.entries()) {
1395
+ callbackfn.call(thisArg, el, id, this);
1396
+ }
1397
+ }
1398
+ indices() {
1399
+ function* gen(self) {
1400
+ for (let id = self.negEl.length - 1; id >= 0; id--) {
1401
+ if (self.hasNeg[id]) yield _SignedIndexArray.toNegIndex(id);
1402
+ }
1403
+ for (let id = 0; id < self.posEl.length; id++) {
1404
+ if (self.hasPos[id]) yield id;
1405
+ }
1406
+ }
1407
+ return gen(this);
1408
+ }
1409
+ indicesArray() {
1410
+ return [...this.indices()];
1411
+ }
1412
+ values() {
1413
+ function* gen(self) {
1414
+ for (let id = self.negEl.length - 1; id >= 0; id--) {
1415
+ if (self.hasNeg[id]) yield self.negEl[id];
1416
+ }
1417
+ for (let id = 0; id < self.posEl.length; id++) {
1418
+ if (self.hasPos[id]) yield self.posEl[id];
1419
+ }
1420
+ }
1421
+ return gen(this);
1422
+ }
1423
+ valuesArray() {
1424
+ return [...this.values()];
1425
+ }
1426
+ *entries() {
1427
+ for (let id = this.negEl.length - 1; id >= 0; id--) {
1428
+ if (this.hasNeg[id]) yield [_SignedIndexArray.toNegIndex(id), this.negEl[id]];
1429
+ }
1430
+ for (let id = 0; id < this.posEl.length; id++) {
1431
+ if (this.hasPos[id]) yield [id, this.posEl[id]];
1432
+ }
1433
+ }
1434
+ entriesArray() {
1435
+ return [...this.entries()];
1436
+ }
1437
+ *[Symbol.iterator]() {
1438
+ yield* this.entries();
1439
+ }
1440
+ clone() {
1441
+ return new _SignedIndexArray(this);
1442
+ }
1443
+ merge(other, conflictResolver) {
1444
+ for (const [id, value] of other.entries()) {
1445
+ if (this.has(id) && conflictResolver) {
1446
+ this.set(id, conflictResolver(this.get(id), value, id));
1447
+ } else {
1448
+ this.set(id, value);
1449
+ }
1450
+ }
1451
+ return this;
1452
+ }
1453
+ some(fn) {
1454
+ for (const [id, el] of this.entries()) {
1455
+ if (fn(el, id)) return true;
1456
+ }
1457
+ return false;
1458
+ }
1459
+ every(fn) {
1460
+ for (const [id, el] of this.entries()) {
1461
+ if (!fn(el, id)) return false;
1462
+ }
1463
+ return true;
1464
+ }
1465
+ filter(fn) {
1466
+ let result = new _SignedIndexArray();
1467
+ for (const [id, el] of this.entries()) {
1468
+ if (fn(el, id)) result.set(id, el);
1469
+ }
1470
+ return result;
1471
+ }
1472
+ reduce(fn, init) {
1473
+ let iterator = this.entries();
1474
+ let first = iterator.next();
1475
+ if (first.done) {
1476
+ if (arguments.length < 2) {
1477
+ throw new TypeError("Reduce of empty SignedIndexArray with no initial value!");
1478
+ }
1479
+ return init;
1480
+ }
1481
+ let acc;
1482
+ let start;
1483
+ if (arguments.length < 2) {
1484
+ acc = first.value[1];
1485
+ start = iterator.next();
1486
+ } else {
1487
+ acc = init;
1488
+ start = first;
1489
+ }
1490
+ for (let current = start; !current.done; current = iterator.next()) {
1491
+ const [id, el] = current.value;
1492
+ acc = fn(acc, el, id);
1493
+ }
1494
+ return acc;
1495
+ }
1496
+ mapToArray(fn) {
1497
+ let result = [];
1498
+ for (const [id, el] of this.entries()) {
1499
+ result.push(fn(el, id));
1500
+ }
1501
+ return result;
1502
+ }
1503
+ map(fn) {
1504
+ let result = new _SignedIndexArray();
1505
+ for (const [id, el] of this.entries()) {
1506
+ result.set(id, fn(el, id));
1507
+ }
1508
+ return result;
1509
+ }
1510
+ toString() {
1511
+ const entries = this.entriesArray().map(([id, el]) => `${id}: ${el}`).join(", ");
1512
+ return `SignedIndexArray[ ${entries} ]`;
1513
+ }
1514
+ };
1515
+
1295
1516
  // src/core/map.ts
1296
- var Map1 = class {
1297
- constructor() {
1298
- __publicField(this, "map1", /* @__PURE__ */ new Map());
1517
+ var Map1 = class _Map1 {
1518
+ constructor(entries) {
1519
+ __publicField(this, "map1");
1520
+ this.map1 = entries instanceof _Map1 ? new Map(entries.map1) : new Map(entries);
1521
+ }
1522
+ has(key1) {
1523
+ return this.map1.has(key1);
1299
1524
  }
1300
1525
  set(key1, value) {
1301
1526
  this.map1.set(key1, value);
@@ -1304,8 +1529,16 @@ var Map1 = class {
1304
1529
  get(key1) {
1305
1530
  return this.map1.get(key1);
1306
1531
  }
1307
- has(key1) {
1308
- return this.map1.has(key1);
1532
+ getOrDefault(key1, defaultValue) {
1533
+ return this.get(key1) ?? defaultValue;
1534
+ }
1535
+ getOrCreate(key1, creatorOrValue) {
1536
+ if (!this.has(key1)) {
1537
+ const value = isFunction(creatorOrValue) ? creatorOrValue() : creatorOrValue;
1538
+ this.set(key1, value);
1539
+ return value;
1540
+ }
1541
+ return this.get(key1);
1309
1542
  }
1310
1543
  delete(key1) {
1311
1544
  return this.map1.delete(key1);
@@ -1322,20 +1555,101 @@ var Map1 = class {
1322
1555
  keys() {
1323
1556
  return this.map1.keys();
1324
1557
  }
1558
+ keysArray() {
1559
+ return [...this.keys()];
1560
+ }
1325
1561
  values() {
1326
1562
  return this.map1.values();
1327
1563
  }
1564
+ valuesArray() {
1565
+ return [...this.values()];
1566
+ }
1328
1567
  *entries() {
1329
1568
  for (const [key1, value] of this.map1)
1330
1569
  yield [key1, value];
1331
1570
  }
1571
+ entriesArray() {
1572
+ return [...this.entries()];
1573
+ }
1332
1574
  *[Symbol.iterator]() {
1333
1575
  yield* this.entries();
1334
1576
  }
1577
+ clone() {
1578
+ return new _Map1(this);
1579
+ }
1580
+ merge(other, conflictResolver) {
1581
+ for (const [key1, value] of other.entries()) {
1582
+ if (this.has(key1) && conflictResolver) {
1583
+ this.set(key1, conflictResolver(this.get(key1), value, key1));
1584
+ } else {
1585
+ this.set(key1, value);
1586
+ }
1587
+ }
1588
+ return this;
1589
+ }
1590
+ some(fn) {
1591
+ for (const [key1, value] of this.map1) {
1592
+ if (fn(value, key1)) return true;
1593
+ }
1594
+ return false;
1595
+ }
1596
+ every(fn) {
1597
+ for (const [key1, value] of this.map1) {
1598
+ if (!fn(value, key1)) return false;
1599
+ }
1600
+ return true;
1601
+ }
1602
+ filter(fn) {
1603
+ let result = new _Map1();
1604
+ for (const [key1, value] of this.map1) {
1605
+ if (fn(value, key1)) result.set(key1, value);
1606
+ }
1607
+ return result;
1608
+ }
1609
+ reduce(fn, init) {
1610
+ let acc = init;
1611
+ for (const [key1, value] of this.map1) {
1612
+ acc = fn(acc, value, key1);
1613
+ }
1614
+ return acc;
1615
+ }
1616
+ mapEntries(fn) {
1617
+ let result = [];
1618
+ for (const [key1, value] of this.map1) {
1619
+ result.push(fn(value, key1));
1620
+ }
1621
+ return result;
1622
+ }
1623
+ mapValues(fn) {
1624
+ let result = new _Map1();
1625
+ for (const [key1, value] of this.map1) {
1626
+ result.set(key1, fn(value, key1));
1627
+ }
1628
+ return result;
1629
+ }
1630
+ toMap() {
1631
+ return new Map(this.map1);
1632
+ }
1633
+ toString() {
1634
+ const entries = [...this.map1].map(([k, v]) => `${k} => ${v}`).join(", ");
1635
+ return `Map1(${this.map1.size}) { ${entries} }`;
1636
+ }
1335
1637
  };
1336
- var Map2 = class {
1337
- constructor() {
1638
+ var Map2 = class _Map2 {
1639
+ constructor(entries) {
1338
1640
  __publicField(this, "map1", /* @__PURE__ */ new Map());
1641
+ if (entries instanceof _Map2) {
1642
+ for (const [key1, inner] of entries.map1) {
1643
+ this.map1.set(key1, new Map(inner));
1644
+ }
1645
+ } else if (entries) {
1646
+ for (const [key1, key2, value] of entries) {
1647
+ this.set(key1, key2, value);
1648
+ }
1649
+ }
1650
+ }
1651
+ has(key1, key2) {
1652
+ return this.map1.get(key1)?.has(key2) ?? false;
1339
1653
  }
1340
1654
  set(key1, key2, value) {
1341
1655
  let map2 = this.map1.get(key1) ?? this.map1.set(key1, /* @__PURE__ */ new Map()).get(key1);
@@ -1345,8 +1659,16 @@ var Map2 = class {
1345
1659
  get(key1, key2) {
1346
1660
  return this.map1.get(key1)?.get(key2);
1347
1661
  }
1348
- has(key1, key2) {
1349
- return this.map1.get(key1)?.has(key2) ?? false;
1662
+ getOrDefault(key1, key2, defaultValue) {
1663
+ return this.get(key1, key2) ?? defaultValue;
1664
+ }
1665
+ getOrCreate(key1, key2, creatorOrValue) {
1666
+ if (!this.has(key1, key2)) {
1667
+ const value = isFunction(creatorOrValue) ? creatorOrValue() : creatorOrValue;
1668
+ this.set(key1, key2, value);
1669
+ return value;
1670
+ }
1671
+ return this.get(key1, key2);
1350
1672
  }
1351
1673
  delete(key1, key2) {
1352
1674
  if (key2 === void 0) return this.map1.delete(key1);
@@ -1369,12 +1691,15 @@ var Map2 = class {
1369
1691
  }
1370
1692
  keys() {
1371
1693
  function* gen(map1) {
1372
- for (const [k1, map2] of map1)
1373
- for (const k2 of map2.keys())
1374
- yield [k1, k2];
1694
+ for (const [key1, map2] of map1)
1695
+ for (const key2 of map2.keys())
1696
+ yield [key1, key2];
1375
1697
  }
1376
1698
  return gen(this.map1);
1377
1699
  }
1700
+ keysArray() {
1701
+ return [...this.keys()];
1702
+ }
1378
1703
  values() {
1379
1704
  function* gen(map1) {
1380
1705
  for (const map2 of map1.values())
@@ -1383,18 +1708,122 @@ var Map2 = class {
1383
1708
  }
1384
1709
  return gen(this.map1);
1385
1710
  }
1711
+ valuesArray() {
1712
+ return [...this.values()];
1713
+ }
1386
1714
  *entries() {
1387
1715
  for (const [key1, map2] of this.map1)
1388
1716
  for (const [key2, value] of map2)
1389
1717
  yield [key1, key2, value];
1390
1718
  }
1719
+ entriesArray() {
1720
+ return [...this.entries()];
1721
+ }
1391
1722
  *[Symbol.iterator]() {
1392
1723
  yield* this.entries();
1393
1724
  }
1725
+ clone() {
1726
+ return new _Map2(this);
1727
+ }
1728
+ merge(other, conflictResolver) {
1729
+ for (const [key1, key2, value] of other.entries()) {
1730
+ if (this.has(key1, key2) && conflictResolver) {
1731
+ this.set(key1, key2, conflictResolver(this.get(key1, key2), value, key1, key2));
1732
+ } else {
1733
+ this.set(key1, key2, value);
1734
+ }
1735
+ }
1736
+ return this;
1737
+ }
1738
+ some(fn) {
1739
+ for (const [key1, map2] of this.map1) {
1740
+ for (const [key2, value] of map2) {
1741
+ if (fn(value, key1, key2)) return true;
1742
+ }
1743
+ }
1744
+ return false;
1745
+ }
1746
+ every(fn) {
1747
+ for (const [key1, map2] of this.map1) {
1748
+ for (const [key2, value] of map2) {
1749
+ if (!fn(value, key1, key2)) return false;
1750
+ }
1751
+ }
1752
+ return true;
1753
+ }
1754
+ filter(fn) {
1755
+ let result = new _Map2();
1756
+ for (const [key1, map2] of this.map1) {
1757
+ for (const [key2, value] of map2) {
1758
+ if (fn(value, key1, key2)) result.set(key1, key2, value);
1759
+ }
1760
+ }
1761
+ return result;
1762
+ }
1763
+ reduce(fn, init) {
1764
+ let acc = init;
1765
+ for (const [key1, map2] of this.map1) {
1766
+ for (const [key2, value] of map2) {
1767
+ acc = fn(acc, value, key1, key2);
1768
+ }
1769
+ }
1770
+ return acc;
1771
+ }
1772
+ mapEntries(fn) {
1773
+ let result = [];
1774
+ for (const [key1, map2] of this.map1) {
1775
+ for (const [key2, value] of map2) {
1776
+ result.push(fn(value, key1, key2));
1777
+ }
1778
+ }
1779
+ return result;
1780
+ }
1781
+ mapValues(fn) {
1782
+ let result = new _Map2();
1783
+ for (const [key1, map2] of this.map1) {
1784
+ for (const [key2, value] of map2) {
1785
+ result.set(key1, key2, fn(value, key1, key2));
1786
+ }
1787
+ }
1788
+ return result;
1789
+ }
1790
+ toMap() {
1791
+ let result = /* @__PURE__ */ new Map();
1792
+ for (const [key1, map2] of this.map1) {
1793
+ for (const [key2, value] of map2) {
1794
+ result.set([key1, key2], value);
1795
+ }
1796
+ }
1797
+ return result;
1798
+ }
1799
+ toString() {
1800
+ const entries = [];
1801
+ for (const [key1, map2] of this.map1) {
1802
+ const inner = [...map2].map(([key2, v]) => `${key2} => ${v}`).join(", ");
1803
+ entries.push(`${key1} => { ${inner} }`);
1804
+ }
1805
+ return `Map2(${this.size}) { ${entries.join(", ")} }`;
1806
+ }
1394
1807
  };
1395
- var Map3 = class {
1396
- constructor() {
1808
+ var Map3 = class _Map3 {
1809
+ constructor(entries) {
1397
1810
  __publicField(this, "map1", /* @__PURE__ */ new Map());
1811
+ if (entries instanceof _Map3) {
1812
+ for (const [key1, map2] of entries.map1) {
1813
+ const newMap2 = /* @__PURE__ */ new Map();
1814
+ for (const [key2, map3] of map2) {
1815
+ newMap2.set(key2, new Map(map3));
1816
+ }
1817
+ this.map1.set(key1, newMap2);
1818
+ }
1819
+ } else if (entries) {
1820
+ for (const [key1, key2, key3, value] of entries) {
1821
+ this.set(key1, key2, key3, value);
1822
+ }
1823
+ }
1824
+ }
1825
+ has(key1, key2, key3) {
1826
+ return this.map1.get(key1)?.get(key2)?.has(key3) ?? false;
1398
1827
  }
1399
1828
  set(key1, key2, key3, value) {
1400
1829
  let map2 = this.map1.get(key1);
@@ -1407,8 +1836,16 @@ var Map3 = class {
1407
1836
  get(key1, key2, key3) {
1408
1837
  return this.map1.get(key1)?.get(key2)?.get(key3);
1409
1838
  }
1410
- has(key1, key2, key3) {
1411
- return this.map1.get(key1)?.get(key2)?.has(key3) ?? false;
1839
+ getOrDefault(key1, key2, key3, defaultValue) {
1840
+ return this.get(key1, key2, key3) ?? defaultValue;
1841
+ }
1842
+ getOrCreate(key1, key2, key3, creatorOrValue) {
1843
+ if (!this.has(key1, key2, key3)) {
1844
+ const value = isFunction(creatorOrValue) ? creatorOrValue() : creatorOrValue;
1845
+ this.set(key1, key2, key3, value);
1846
+ return value;
1847
+ }
1848
+ return this.get(key1, key2, key3);
1412
1849
  }
1413
1850
  delete(key1, key2, key3) {
1414
1851
  if (key3 === void 0) {
@@ -1440,13 +1877,16 @@ var Map3 = class {
1440
1877
  }
1441
1878
  keys() {
1442
1879
  function* gen(map1) {
1443
- for (const [k1, map2] of map1)
1444
- for (const [k2, map3] of map2)
1445
- for (const k3 of map3.keys())
1446
- yield [k1, k2, k3];
1880
+ for (const [key1, map2] of map1)
1881
+ for (const [key2, map3] of map2)
1882
+ for (const key3 of map3.keys())
1883
+ yield [key1, key2, key3];
1447
1884
  }
1448
1885
  return gen(this.map1);
1449
1886
  }
1887
+ keysArray() {
1888
+ return [...this.keys()];
1889
+ }
1450
1890
  values() {
1451
1891
  function* gen(map1) {
1452
1892
  for (const map2 of map1.values())
@@ -1456,15 +1896,119 @@ var Map3 = class {
1456
1896
  }
1457
1897
  return gen(this.map1);
1458
1898
  }
1899
+ valuesArray() {
1900
+ return [...this.values()];
1901
+ }
1459
1902
  *entries() {
1460
1903
  for (const [key1, map2] of this.map1)
1461
1904
  for (const [key2, map3] of map2)
1462
1905
  for (const [key3, value] of map3)
1463
1906
  yield [key1, key2, key3, value];
1464
1907
  }
1908
+ entriesArray() {
1909
+ return [...this.entries()];
1910
+ }
1465
1911
  *[Symbol.iterator]() {
1466
1912
  yield* this.entries();
1467
1913
  }
1914
+ clone() {
1915
+ return new _Map3(this);
1916
+ }
1917
+ merge(other, conflictResolver) {
1918
+ for (const [key1, key2, key3, value] of other.entries()) {
1919
+ if (this.has(key1, key2, key3) && conflictResolver) {
1920
+ this.set(key1, key2, key3, conflictResolver(this.get(key1, key2, key3), value, key1, key2, key3));
1921
+ } else {
1922
+ this.set(key1, key2, key3, value);
1923
+ }
1924
+ }
1925
+ return this;
1926
+ }
1927
+ some(fn) {
1928
+ for (const [key1, map2] of this.map1) {
1929
+ for (const [key2, map3] of map2) {
1930
+ for (const [key3, value] of map3) {
1931
+ if (fn(value, key1, key2, key3)) return true;
1932
+ }
1933
+ }
1934
+ }
1935
+ return false;
1936
+ }
1937
+ every(fn) {
1938
+ for (const [key1, map2] of this.map1) {
1939
+ for (const [key2, map3] of map2) {
1940
+ for (const [key3, value] of map3) {
1941
+ if (!fn(value, key1, key2, key3)) return false;
1942
+ }
1943
+ }
1944
+ }
1945
+ return true;
1946
+ }
1947
+ filter(fn) {
1948
+ let result = new _Map3();
1949
+ for (const [key1, map2] of this.map1) {
1950
+ for (const [key2, map3] of map2) {
1951
+ for (const [key3, value] of map3) {
1952
+ if (fn(value, key1, key2, key3)) result.set(key1, key2, key3, value);
1953
+ }
1954
+ }
1955
+ }
1956
+ return result;
1957
+ }
1958
+ reduce(fn, init) {
1959
+ let acc = init;
1960
+ for (const [key1, map2] of this.map1) {
1961
+ for (const [key2, map3] of map2) {
1962
+ for (const [key3, value] of map3) {
1963
+ acc = fn(acc, value, key1, key2, key3);
1964
+ }
1965
+ }
1966
+ }
1967
+ return acc;
1968
+ }
1969
+ mapEntries(fn) {
1970
+ let result = [];
1971
+ for (const [key1, map2] of this.map1) {
1972
+ for (const [key2, map3] of map2) {
1973
+ for (const [key3, value] of map3) {
1974
+ result.push(fn(value, key1, key2, key3));
1975
+ }
1976
+ }
1977
+ }
1978
+ return result;
1979
+ }
1980
+ mapValues(fn) {
1981
+ let result = new _Map3();
1982
+ for (const [key1, map2] of this.map1) {
1983
+ for (const [key2, map3] of map2) {
1984
+ for (const [key3, value] of map3) {
1985
+ result.set(key1, key2, key3, fn(value, key1, key2, key3));
1986
+ }
1987
+ }
1988
+ }
1989
+ return result;
1990
+ }
1991
+ toMap() {
1992
+ let result = /* @__PURE__ */ new Map();
1993
+ for (const [key1, map2] of this.map1) {
1994
+ for (const [key2, map3] of map2) {
1995
+ for (const [key3, value] of map3) {
1996
+ result.set([key1, key2, key3], value);
1997
+ }
1998
+ }
1999
+ }
2000
+ return result;
2001
+ }
2002
+ toString() {
2003
+ const entries = [];
2004
+ for (const [key1, map2] of this.map1) {
2005
+ for (const [key2, map3] of map2) {
2006
+ const inner = [...map3].map(([key3, v]) => `${key3} => ${v}`).join(", ");
2007
+ entries.push(`${key1} => ${key2} => { ${inner} }`);
2008
+ }
2009
+ }
2010
+ return `Map3(${this.size}) { ${entries.join(", ")} }`;
2011
+ }
1468
2012
  };
1469
2013
  // Annotate the CommonJS export names for ESM import in node:
1470
2014
  0 && (module.exports = {
@@ -1475,6 +2019,7 @@ var Map3 = class {
1475
2019
  Map1,
1476
2020
  Map2,
1477
2021
  Map3,
2022
+ SignedIndexArray,
1478
2023
  SmallIntCache,
1479
2024
  Stack,
1480
2025
  Utils,