@tspro/ts-utils-lib 1.15.0 → 1.17.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/CHANGELOG.md +16 -0
- package/dist/index.d.mts +418 -117
- package/dist/index.d.ts +418 -117
- package/dist/index.js +800 -257
- package/dist/index.mjs +798 -257
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* TsUtilsLib v1.
|
|
1
|
+
/* TsUtilsLib v1.17.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;
|
|
@@ -26,6 +26,7 @@ __export(index_exports, {
|
|
|
26
26
|
Assert: () => Assert,
|
|
27
27
|
Cookies: () => Cookies,
|
|
28
28
|
Device: () => Device,
|
|
29
|
+
DivRect: () => DivRect,
|
|
29
30
|
IndexArray: () => IndexArray,
|
|
30
31
|
LRUCache: () => LRUCache,
|
|
31
32
|
Map1: () => Map1,
|
|
@@ -36,6 +37,7 @@ __export(index_exports, {
|
|
|
36
37
|
SmallIntCache: () => SmallIntCache,
|
|
37
38
|
Stack: () => Stack,
|
|
38
39
|
Utils: () => utils_exports,
|
|
40
|
+
Vec: () => Vec,
|
|
39
41
|
Vec2: () => Vec2,
|
|
40
42
|
asMulti: () => asMulti
|
|
41
43
|
});
|
|
@@ -1117,28 +1119,396 @@ var Stack = class {
|
|
|
1117
1119
|
}
|
|
1118
1120
|
};
|
|
1119
1121
|
|
|
1120
|
-
// src/core/
|
|
1121
|
-
var
|
|
1122
|
-
constructor(
|
|
1123
|
-
__publicField(this, "
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1122
|
+
// src/core/vec.ts
|
|
1123
|
+
var Vec = class _Vec {
|
|
1124
|
+
constructor(...coords) {
|
|
1125
|
+
__publicField(this, "coords");
|
|
1126
|
+
if (coords.length < 2) {
|
|
1127
|
+
throw new TypeError("Vec needs minumum two coords!");
|
|
1128
|
+
}
|
|
1129
|
+
this.coords = coords;
|
|
1127
1130
|
}
|
|
1128
|
-
|
|
1129
|
-
return
|
|
1131
|
+
static vec2(x, y) {
|
|
1132
|
+
return new _Vec(x, y);
|
|
1130
1133
|
}
|
|
1131
|
-
|
|
1132
|
-
return new
|
|
1134
|
+
static vec3(x, y, z) {
|
|
1135
|
+
return new _Vec(x, y, z);
|
|
1133
1136
|
}
|
|
1134
|
-
|
|
1135
|
-
|
|
1137
|
+
static zero(dim) {
|
|
1138
|
+
if (dim < 2) {
|
|
1139
|
+
throw new TypeError("Vec.zero requires dimension >= 2");
|
|
1140
|
+
}
|
|
1141
|
+
return new _Vec(...Array(dim).fill(0));
|
|
1136
1142
|
}
|
|
1137
|
-
|
|
1138
|
-
return
|
|
1143
|
+
get length() {
|
|
1144
|
+
return Math.hypot(...this.coords);
|
|
1139
1145
|
}
|
|
1140
|
-
|
|
1141
|
-
return
|
|
1146
|
+
get x() {
|
|
1147
|
+
return this.coords[0];
|
|
1148
|
+
}
|
|
1149
|
+
get y() {
|
|
1150
|
+
return this.coords[1];
|
|
1151
|
+
}
|
|
1152
|
+
get z() {
|
|
1153
|
+
if (this.coords[2] === void 0) {
|
|
1154
|
+
throw new TypeError("Vec z-coord not available!");
|
|
1155
|
+
}
|
|
1156
|
+
return this.coords[2];
|
|
1157
|
+
}
|
|
1158
|
+
add(...args) {
|
|
1159
|
+
const otherCoords = args[0] instanceof _Vec ? args[0].coords : args;
|
|
1160
|
+
if (this.coords.length !== otherCoords.length) {
|
|
1161
|
+
throw new TypeError("Coordinate length mismatch!");
|
|
1162
|
+
}
|
|
1163
|
+
return new _Vec(...this.coords.map((coord, i) => coord + otherCoords[i]));
|
|
1164
|
+
}
|
|
1165
|
+
sub(...args) {
|
|
1166
|
+
const otherCoords = args[0] instanceof _Vec ? args[0].coords : args;
|
|
1167
|
+
if (this.coords.length !== otherCoords.length) {
|
|
1168
|
+
throw new TypeError("Coordinate length mismatch!");
|
|
1169
|
+
}
|
|
1170
|
+
return new _Vec(...this.coords.map((coord, i) => coord - otherCoords[i]));
|
|
1171
|
+
}
|
|
1172
|
+
mul(scalar) {
|
|
1173
|
+
return new _Vec(...this.coords.map((coord) => coord * scalar));
|
|
1174
|
+
}
|
|
1175
|
+
div(scalar) {
|
|
1176
|
+
return new _Vec(...this.coords.map((coord) => coord / scalar));
|
|
1177
|
+
}
|
|
1178
|
+
dot(other) {
|
|
1179
|
+
if (this.coords.length !== other.coords.length) {
|
|
1180
|
+
throw new TypeError("Coordinate length mismatch!");
|
|
1181
|
+
}
|
|
1182
|
+
return this.coords.reduce((sum2, c, i) => sum2 + c * other.coords[i], 0);
|
|
1183
|
+
}
|
|
1184
|
+
distance(other) {
|
|
1185
|
+
if (this.coords.length !== other.coords.length) {
|
|
1186
|
+
throw new TypeError("Coordinate length mismatch!");
|
|
1187
|
+
}
|
|
1188
|
+
return Math.hypot(...this.coords.map((c, i) => c - other.coords[i]));
|
|
1189
|
+
}
|
|
1190
|
+
normalize() {
|
|
1191
|
+
const len = this.length;
|
|
1192
|
+
if (len === 0) {
|
|
1193
|
+
throw new TypeError("Cannot normalize zero-length vector!");
|
|
1194
|
+
}
|
|
1195
|
+
return this.div(len);
|
|
1196
|
+
}
|
|
1197
|
+
equals(other) {
|
|
1198
|
+
return this.coords.length === other.coords.length && this.coords.every((v, i) => v === other.coords[i]);
|
|
1199
|
+
}
|
|
1200
|
+
clone() {
|
|
1201
|
+
return new _Vec(...this.coords);
|
|
1202
|
+
}
|
|
1203
|
+
toObject() {
|
|
1204
|
+
return { x: this.x, y: this.y, z: this.z };
|
|
1205
|
+
}
|
|
1206
|
+
[Symbol.iterator]() {
|
|
1207
|
+
return this.coords[Symbol.iterator]();
|
|
1208
|
+
}
|
|
1209
|
+
toString() {
|
|
1210
|
+
return `Vec(${this.coords.join(", ")})`;
|
|
1211
|
+
}
|
|
1212
|
+
};
|
|
1213
|
+
|
|
1214
|
+
// src/core/div-rect.ts
|
|
1215
|
+
var DivRect = class _DivRect {
|
|
1216
|
+
constructor(...args) {
|
|
1217
|
+
__publicField(this, "left");
|
|
1218
|
+
__publicField(this, "centerX");
|
|
1219
|
+
__publicField(this, "right");
|
|
1220
|
+
__publicField(this, "top");
|
|
1221
|
+
__publicField(this, "centerY");
|
|
1222
|
+
__publicField(this, "bottom");
|
|
1223
|
+
if (args.length === 6) {
|
|
1224
|
+
this.left = args[0];
|
|
1225
|
+
this.centerX = args[1];
|
|
1226
|
+
this.right = args[2];
|
|
1227
|
+
this.top = args[3];
|
|
1228
|
+
this.centerY = args[4];
|
|
1229
|
+
this.bottom = args[5];
|
|
1230
|
+
} else if (args.length === 4) {
|
|
1231
|
+
this.left = args[0];
|
|
1232
|
+
this.right = args[1];
|
|
1233
|
+
this.centerX = (this.left + this.right) / 2;
|
|
1234
|
+
this.top = args[2];
|
|
1235
|
+
this.bottom = args[3];
|
|
1236
|
+
this.centerY = (this.top + this.bottom) / 2;
|
|
1237
|
+
} else if (args.length === 0) {
|
|
1238
|
+
this.left = this.centerX = this.right = 0;
|
|
1239
|
+
this.top = this.centerY = this.bottom = 0;
|
|
1240
|
+
} else {
|
|
1241
|
+
throw new TypeError(`Invalid DivRect args: ${args}`);
|
|
1242
|
+
}
|
|
1243
|
+
}
|
|
1244
|
+
/**
|
|
1245
|
+
* Create rect from basic left, top, width and height arguments.
|
|
1246
|
+
*
|
|
1247
|
+
* @param left - Left coordinate.
|
|
1248
|
+
* @param top - Top coordinate.
|
|
1249
|
+
* @param width - Width.
|
|
1250
|
+
* @param height - Height.
|
|
1251
|
+
* @returns - DivRect.
|
|
1252
|
+
*/
|
|
1253
|
+
static create(left, top, width, height) {
|
|
1254
|
+
return new _DivRect(left, left + width, top, top + height);
|
|
1255
|
+
}
|
|
1256
|
+
/**
|
|
1257
|
+
* Create rect from centerX, centerY, width, height arguments.
|
|
1258
|
+
*
|
|
1259
|
+
* @param centerX - Center x-coordinate.
|
|
1260
|
+
* @param centerY - Center y-coordinate.
|
|
1261
|
+
* @param width - Width.
|
|
1262
|
+
* @param height - Height.
|
|
1263
|
+
* @returns - DivRect.
|
|
1264
|
+
*/
|
|
1265
|
+
static createCentered(centerX, centerY, width, height) {
|
|
1266
|
+
return new _DivRect(
|
|
1267
|
+
centerX - width / 2,
|
|
1268
|
+
centerX,
|
|
1269
|
+
centerX + width / 2,
|
|
1270
|
+
centerY - height / 2,
|
|
1271
|
+
centerY,
|
|
1272
|
+
centerY + height / 2
|
|
1273
|
+
);
|
|
1274
|
+
}
|
|
1275
|
+
/**
|
|
1276
|
+
* Create rect from sections.
|
|
1277
|
+
*
|
|
1278
|
+
* @param leftw - Left section width.
|
|
1279
|
+
* @param rightw - Right section width.
|
|
1280
|
+
* @param toph - Top section height.
|
|
1281
|
+
* @param bottomh - Bottomsection height.
|
|
1282
|
+
* @returns - DivRect.
|
|
1283
|
+
*/
|
|
1284
|
+
static createSections(leftw, rightw, toph, bottomh) {
|
|
1285
|
+
return new _DivRect(-leftw, 0, rightw, -toph, 0, bottomh);
|
|
1286
|
+
}
|
|
1287
|
+
/**
|
|
1288
|
+
* Width getter.
|
|
1289
|
+
*/
|
|
1290
|
+
get width() {
|
|
1291
|
+
return this.right - this.left;
|
|
1292
|
+
}
|
|
1293
|
+
/**
|
|
1294
|
+
* Height getter.
|
|
1295
|
+
*/
|
|
1296
|
+
get height() {
|
|
1297
|
+
return this.bottom - this.top;
|
|
1298
|
+
}
|
|
1299
|
+
/**
|
|
1300
|
+
* Left section width getter.
|
|
1301
|
+
*/
|
|
1302
|
+
get leftw() {
|
|
1303
|
+
return this.centerX - this.left;
|
|
1304
|
+
}
|
|
1305
|
+
/**
|
|
1306
|
+
* Right section width getter.
|
|
1307
|
+
*/
|
|
1308
|
+
get rightw() {
|
|
1309
|
+
return this.right - this.centerX;
|
|
1310
|
+
}
|
|
1311
|
+
/**
|
|
1312
|
+
* Top section height getter.
|
|
1313
|
+
*/
|
|
1314
|
+
get toph() {
|
|
1315
|
+
return this.centerY - this.top;
|
|
1316
|
+
}
|
|
1317
|
+
/**
|
|
1318
|
+
* Bottom section height getter.
|
|
1319
|
+
*/
|
|
1320
|
+
get bottomh() {
|
|
1321
|
+
return this.bottom - this.centerY;
|
|
1322
|
+
}
|
|
1323
|
+
/**
|
|
1324
|
+
* Does this Rect contain given (x, y)-point?
|
|
1325
|
+
*
|
|
1326
|
+
* @param x - X-coordinate.
|
|
1327
|
+
* @param y - Y-coordinate.
|
|
1328
|
+
* @returns - True/false.
|
|
1329
|
+
*/
|
|
1330
|
+
contains(x, y) {
|
|
1331
|
+
return x >= this.left && x <= this.right && y >= this.top && y <= this.bottom;
|
|
1332
|
+
}
|
|
1333
|
+
/**
|
|
1334
|
+
* Do a and b rects overlap?
|
|
1335
|
+
*
|
|
1336
|
+
* @param a - DivRect a.
|
|
1337
|
+
* @param b - DivRect b.
|
|
1338
|
+
* @returns - True/false.
|
|
1339
|
+
*/
|
|
1340
|
+
static overlap(a, b) {
|
|
1341
|
+
return a.right > b.left && a.left < b.right && a.bottom > b.top && a.top < b.bottom;
|
|
1342
|
+
}
|
|
1343
|
+
/**
|
|
1344
|
+
* Do horizontal measures of a and b rects overlap?
|
|
1345
|
+
*
|
|
1346
|
+
* @param a - DivRect a.
|
|
1347
|
+
* @param b - DivRect b.
|
|
1348
|
+
* @returns - True/false.
|
|
1349
|
+
*/
|
|
1350
|
+
static overlapX(a, b) {
|
|
1351
|
+
return a.right > b.left && a.left < b.right;
|
|
1352
|
+
}
|
|
1353
|
+
/**
|
|
1354
|
+
* Check if given rects are equal.
|
|
1355
|
+
* @param a - DivRect a.
|
|
1356
|
+
* @param b - DivRect b.
|
|
1357
|
+
* @returns - True/false.
|
|
1358
|
+
*/
|
|
1359
|
+
static equals(a, b) {
|
|
1360
|
+
if (a == null && b == null) {
|
|
1361
|
+
return true;
|
|
1362
|
+
} else if (a == null || b == null) {
|
|
1363
|
+
return false;
|
|
1364
|
+
} else {
|
|
1365
|
+
return a === b || a.left === b.left && a.centerX === b.centerX && a.right === b.right && a.top === b.top && a.centerY === b.centerY && a.bottom === b.bottom;
|
|
1366
|
+
}
|
|
1367
|
+
}
|
|
1368
|
+
/**
|
|
1369
|
+
* Check if this rect equals with another rect.
|
|
1370
|
+
* @param other - The other rect.
|
|
1371
|
+
* @returns - True/false.
|
|
1372
|
+
*/
|
|
1373
|
+
equals(other) {
|
|
1374
|
+
return _DivRect.equals(this, other);
|
|
1375
|
+
}
|
|
1376
|
+
/**
|
|
1377
|
+
* Check if edges of given rects are equal, ignoring centerX and centerY.
|
|
1378
|
+
*
|
|
1379
|
+
* @param a - DivRect a.
|
|
1380
|
+
* @param b - DivRect b.
|
|
1381
|
+
* @returns - True/false.
|
|
1382
|
+
*/
|
|
1383
|
+
static equalsEdges(a, b) {
|
|
1384
|
+
if (a == null && b == null) {
|
|
1385
|
+
return true;
|
|
1386
|
+
} else if (a == null || b == null) {
|
|
1387
|
+
return false;
|
|
1388
|
+
} else {
|
|
1389
|
+
return a === b || a.left === b.left && a.right === b.right && a.top === b.top && a.bottom === b.bottom;
|
|
1390
|
+
}
|
|
1391
|
+
}
|
|
1392
|
+
/**
|
|
1393
|
+
* Check if edges of this Rect equals with given Rect, ignoring centerX and centerY.
|
|
1394
|
+
*
|
|
1395
|
+
* @param other - The other DivRect.
|
|
1396
|
+
* @returns - True/false.
|
|
1397
|
+
*/
|
|
1398
|
+
equalsEdges(other) {
|
|
1399
|
+
return _DivRect.equalsEdges(this, other);
|
|
1400
|
+
}
|
|
1401
|
+
/**
|
|
1402
|
+
* Created duplicate of this Rect.
|
|
1403
|
+
*
|
|
1404
|
+
* @returns - Duplicate.
|
|
1405
|
+
*/
|
|
1406
|
+
copy() {
|
|
1407
|
+
return new _DivRect(this.left, this.centerX, this.right, this.top, this.centerY, this.bottom);
|
|
1408
|
+
}
|
|
1409
|
+
/**
|
|
1410
|
+
* Move this rect by (dx, dy). Modifies this Rect.
|
|
1411
|
+
*
|
|
1412
|
+
* @param dx - Offset amount in x-direction.
|
|
1413
|
+
* @param dy - Offset amount in y-direction.
|
|
1414
|
+
* @returns - This DivRect instance.
|
|
1415
|
+
*/
|
|
1416
|
+
offsetInPlace(dx, dy) {
|
|
1417
|
+
this.left += dx;
|
|
1418
|
+
this.centerX += dx;
|
|
1419
|
+
this.right += dx;
|
|
1420
|
+
this.top += dy;
|
|
1421
|
+
this.centerY += dy;
|
|
1422
|
+
this.bottom += dy;
|
|
1423
|
+
return this;
|
|
1424
|
+
}
|
|
1425
|
+
/**
|
|
1426
|
+
* Move this rect by (dx, dy). Immutable, returns modified copy.
|
|
1427
|
+
*
|
|
1428
|
+
* @param dx - Offset amount in x-direction.
|
|
1429
|
+
* @param dy - Offset amount in y-direction.
|
|
1430
|
+
* @returns - DivRect copy with applied offset.
|
|
1431
|
+
*/
|
|
1432
|
+
offsetCopy(dx, dy) {
|
|
1433
|
+
return this.copy().offsetInPlace(dx, dy);
|
|
1434
|
+
}
|
|
1435
|
+
/**
|
|
1436
|
+
* Expand this Rect by given Rect. Modifies this Rect.
|
|
1437
|
+
*
|
|
1438
|
+
* @param rect - DivRect to expand this instance with.
|
|
1439
|
+
* @returns - This DivRect instance.
|
|
1440
|
+
*/
|
|
1441
|
+
expandInPlace(rect) {
|
|
1442
|
+
this.left = Math.min(this.left, rect.left);
|
|
1443
|
+
this.right = Math.max(this.right, rect.right);
|
|
1444
|
+
this.top = Math.min(this.top, rect.top);
|
|
1445
|
+
this.bottom = Math.max(this.bottom, rect.bottom);
|
|
1446
|
+
return this;
|
|
1447
|
+
}
|
|
1448
|
+
/**
|
|
1449
|
+
* Expand this Rect by given Rect. Immutable, returns modified copy.
|
|
1450
|
+
*
|
|
1451
|
+
* @param rect - DivRect to expand this instance with.
|
|
1452
|
+
* @returns - Expanded copy of this DivRect.
|
|
1453
|
+
*/
|
|
1454
|
+
expandCopy(rect) {
|
|
1455
|
+
return this.copy().expandInPlace(rect);
|
|
1456
|
+
}
|
|
1457
|
+
/**
|
|
1458
|
+
* Clip this Rect by given Rect. Mmodifies this Rect.
|
|
1459
|
+
*
|
|
1460
|
+
* @param clipRect - DivRect to clip this instance with.
|
|
1461
|
+
* @returns - This DivRect instance.
|
|
1462
|
+
*/
|
|
1463
|
+
clipInPlace(clipRect) {
|
|
1464
|
+
this.left = Math.max(this.left, clipRect.left);
|
|
1465
|
+
this.right = Math.min(this.right, clipRect.right);
|
|
1466
|
+
this.centerX = clamp(this.centerX, this.left, this.right);
|
|
1467
|
+
this.top = Math.max(this.top, clipRect.top);
|
|
1468
|
+
this.bottom = Math.min(this.bottom, clipRect.bottom);
|
|
1469
|
+
this.centerY = clamp(this.centerY, this.top, this.bottom);
|
|
1470
|
+
return this;
|
|
1471
|
+
}
|
|
1472
|
+
/**
|
|
1473
|
+
* Clip this Rect by given Rect. Immutable, return modified copy.
|
|
1474
|
+
*
|
|
1475
|
+
* @param clipRect - DivRecto to clip this instance with.
|
|
1476
|
+
* @returns - Clipped DivRect copy.
|
|
1477
|
+
*/
|
|
1478
|
+
clipCopy(clipRect) {
|
|
1479
|
+
return this.copy().clipInPlace(clipRect);
|
|
1480
|
+
}
|
|
1481
|
+
/**
|
|
1482
|
+
* Scale Rect. Anchor pos is (centerX, centerY). Modifies this Rect.
|
|
1483
|
+
*
|
|
1484
|
+
* @param scaleX - Scale x-amount.
|
|
1485
|
+
* @param scaleY - Scale y-amount. If undefined then scale x-amount is used.
|
|
1486
|
+
* @returns This DivRect instance.
|
|
1487
|
+
*/
|
|
1488
|
+
scaleInPlace(scaleX, scaleY) {
|
|
1489
|
+
scaleY = scaleY ?? scaleX;
|
|
1490
|
+
this.left = this.centerX - this.leftw * scaleX;
|
|
1491
|
+
this.right = this.centerX + this.rightw * scaleX;
|
|
1492
|
+
this.top = this.centerY - this.toph * scaleY;
|
|
1493
|
+
this.bottom = this.centerY + this.bottomh * scaleY;
|
|
1494
|
+
return this;
|
|
1495
|
+
}
|
|
1496
|
+
/**
|
|
1497
|
+
* Scale Rect. Anchor pos is (centerX, centerY). Immutable, returns modified copy.
|
|
1498
|
+
*
|
|
1499
|
+
* @param scaleX - Scale x-amount.
|
|
1500
|
+
* @param scaleY - Scale y-amount. If undefined then scale x-amount is used.
|
|
1501
|
+
* @returns Scaled copy of this DivRect.
|
|
1502
|
+
*/
|
|
1503
|
+
scaleCopy(scaleX, scaleY) {
|
|
1504
|
+
return this.copy().scaleInPlace(scaleX, scaleY);
|
|
1505
|
+
}
|
|
1506
|
+
/**
|
|
1507
|
+
* Get this DivRect instance.
|
|
1508
|
+
* @returns - This DivRect instance.
|
|
1509
|
+
*/
|
|
1510
|
+
getRect() {
|
|
1511
|
+
return this;
|
|
1142
1512
|
}
|
|
1143
1513
|
};
|
|
1144
1514
|
|
|
@@ -1239,107 +1609,54 @@ var LRUCache = class {
|
|
|
1239
1609
|
}
|
|
1240
1610
|
};
|
|
1241
1611
|
|
|
1242
|
-
// src/core/small-int-cache.ts
|
|
1243
|
-
var SmallIntCache = class {
|
|
1244
|
-
// for keys < 0
|
|
1245
|
-
constructor() {
|
|
1246
|
-
__publicField(this, "pos");
|
|
1247
|
-
// for keys >= 0
|
|
1248
|
-
__publicField(this, "neg");
|
|
1249
|
-
this.pos = [];
|
|
1250
|
-
this.neg = [];
|
|
1251
|
-
}
|
|
1252
|
-
set(key, value) {
|
|
1253
|
-
if (!isInteger(key)) {
|
|
1254
|
-
throw new Error("Key must be an integer");
|
|
1255
|
-
} else if (key >= 0) {
|
|
1256
|
-
this.pos[key] = value;
|
|
1257
|
-
} else {
|
|
1258
|
-
this.neg[-key - 1] = value;
|
|
1259
|
-
}
|
|
1260
|
-
}
|
|
1261
|
-
get(key) {
|
|
1262
|
-
if (!isInteger(key)) {
|
|
1263
|
-
throw new Error("Key must be an integer");
|
|
1264
|
-
} else if (key >= 0) {
|
|
1265
|
-
return this.pos[key];
|
|
1266
|
-
} else {
|
|
1267
|
-
return this.neg[-key - 1];
|
|
1268
|
-
}
|
|
1269
|
-
}
|
|
1270
|
-
has(key) {
|
|
1271
|
-
if (!isInteger(key)) {
|
|
1272
|
-
return false;
|
|
1273
|
-
} else if (key >= 0) {
|
|
1274
|
-
return key in this.pos;
|
|
1275
|
-
} else {
|
|
1276
|
-
return -key - 1 in this.neg;
|
|
1277
|
-
}
|
|
1278
|
-
}
|
|
1279
|
-
delete(key) {
|
|
1280
|
-
if (!isInteger(key)) {
|
|
1281
|
-
return;
|
|
1282
|
-
} else if (key >= 0) {
|
|
1283
|
-
delete this.pos[key];
|
|
1284
|
-
} else {
|
|
1285
|
-
delete this.neg[-key - 1];
|
|
1286
|
-
}
|
|
1287
|
-
}
|
|
1288
|
-
clear() {
|
|
1289
|
-
this.pos = [];
|
|
1290
|
-
this.neg = [];
|
|
1291
|
-
}
|
|
1292
|
-
};
|
|
1293
|
-
|
|
1294
1612
|
// src/core/index-array.ts
|
|
1295
1613
|
var IndexArray = class _IndexArray {
|
|
1296
1614
|
constructor(entries) {
|
|
1297
|
-
|
|
1298
|
-
__publicField(this, "posEl");
|
|
1615
|
+
__publicField(this, "posVal");
|
|
1299
1616
|
__publicField(this, "hasPos");
|
|
1300
|
-
//
|
|
1301
|
-
__publicField(this, "
|
|
1617
|
+
// Number of values
|
|
1618
|
+
__publicField(this, "valCount");
|
|
1302
1619
|
if (entries instanceof _IndexArray) {
|
|
1303
|
-
this.
|
|
1620
|
+
this.posVal = entries.posVal.slice();
|
|
1304
1621
|
this.hasPos = entries.hasPos.slice();
|
|
1305
|
-
this.
|
|
1622
|
+
this.valCount = entries.valCount;
|
|
1306
1623
|
} else {
|
|
1307
|
-
this.
|
|
1624
|
+
this.posVal = [];
|
|
1308
1625
|
this.hasPos = [];
|
|
1309
|
-
this.
|
|
1626
|
+
this.valCount = 0;
|
|
1310
1627
|
if (entries) {
|
|
1311
|
-
for (const [id,
|
|
1312
|
-
this.set(id,
|
|
1628
|
+
for (const [id, value] of entries) {
|
|
1629
|
+
this.set(id, value);
|
|
1313
1630
|
}
|
|
1314
1631
|
}
|
|
1315
1632
|
}
|
|
1316
1633
|
}
|
|
1317
|
-
static toNegIndex(id) {
|
|
1318
|
-
return -id - 1;
|
|
1319
|
-
}
|
|
1320
1634
|
static validateIndex(id) {
|
|
1321
1635
|
if (!isIntegerGte(id, 0)) throw new Error(`Invalid index ${id} - must be an integer >= 0!`);
|
|
1322
1636
|
return id;
|
|
1323
1637
|
}
|
|
1324
|
-
get size() {
|
|
1325
|
-
return this.elCount;
|
|
1326
|
-
}
|
|
1327
1638
|
get posLen() {
|
|
1328
1639
|
return this.hasPos.length;
|
|
1329
1640
|
}
|
|
1641
|
+
get size() {
|
|
1642
|
+
return this.valCount;
|
|
1643
|
+
}
|
|
1644
|
+
isEmpty() {
|
|
1645
|
+
return this.size === 0;
|
|
1646
|
+
}
|
|
1330
1647
|
has(id) {
|
|
1331
1648
|
_IndexArray.validateIndex(id);
|
|
1332
1649
|
return this.hasPos[id] === true;
|
|
1333
1650
|
}
|
|
1334
|
-
set(id,
|
|
1651
|
+
set(id, value) {
|
|
1335
1652
|
_IndexArray.validateIndex(id);
|
|
1336
|
-
if (this.hasPos[id] !== true) this.
|
|
1337
|
-
this.
|
|
1653
|
+
if (this.hasPos[id] !== true) this.valCount++;
|
|
1654
|
+
this.posVal[id] = value;
|
|
1338
1655
|
this.hasPos[id] = true;
|
|
1339
1656
|
}
|
|
1340
1657
|
get(id) {
|
|
1341
1658
|
_IndexArray.validateIndex(id);
|
|
1342
|
-
return this.hasPos[id] ? this.
|
|
1659
|
+
return this.hasPos[id] ? this.posVal[id] : void 0;
|
|
1343
1660
|
}
|
|
1344
1661
|
getOrDefault(id, defaultValue) {
|
|
1345
1662
|
return this.get(id) ?? defaultValue;
|
|
@@ -1355,19 +1672,19 @@ var IndexArray = class _IndexArray {
|
|
|
1355
1672
|
delete(id) {
|
|
1356
1673
|
_IndexArray.validateIndex(id);
|
|
1357
1674
|
if (!this.hasPos[id]) return false;
|
|
1358
|
-
this.
|
|
1675
|
+
this.posVal[id] = void 0;
|
|
1359
1676
|
this.hasPos[id] = false;
|
|
1360
|
-
this.
|
|
1677
|
+
this.valCount--;
|
|
1361
1678
|
return true;
|
|
1362
1679
|
}
|
|
1363
1680
|
clear() {
|
|
1364
|
-
this.
|
|
1681
|
+
this.posVal = [];
|
|
1365
1682
|
this.hasPos = [];
|
|
1366
|
-
this.
|
|
1683
|
+
this.valCount = 0;
|
|
1367
1684
|
}
|
|
1368
1685
|
forEach(callbackfn, thisArg) {
|
|
1369
|
-
for (const [id,
|
|
1370
|
-
callbackfn.call(thisArg,
|
|
1686
|
+
for (const [id, value] of this.entries()) {
|
|
1687
|
+
callbackfn.call(thisArg, value, id, this);
|
|
1371
1688
|
}
|
|
1372
1689
|
}
|
|
1373
1690
|
*indices() {
|
|
@@ -1375,25 +1692,40 @@ var IndexArray = class _IndexArray {
|
|
|
1375
1692
|
if (this.hasPos[id]) yield id;
|
|
1376
1693
|
}
|
|
1377
1694
|
}
|
|
1378
|
-
indicesArray() {
|
|
1379
|
-
return [...this.indices()];
|
|
1380
|
-
}
|
|
1381
1695
|
*values() {
|
|
1382
1696
|
for (let id = 0; id < this.posLen; id++) {
|
|
1383
|
-
if (this.hasPos[id]) yield this.
|
|
1697
|
+
if (this.hasPos[id]) yield this.posVal[id];
|
|
1384
1698
|
}
|
|
1385
1699
|
}
|
|
1386
|
-
valuesArray() {
|
|
1387
|
-
return [...this.values()];
|
|
1388
|
-
}
|
|
1389
1700
|
*entries() {
|
|
1390
1701
|
for (let id = 0; id < this.posLen; id++) {
|
|
1391
|
-
if (this.hasPos[id]) yield [id, this.
|
|
1702
|
+
if (this.hasPos[id]) yield [id, this.posVal[id]];
|
|
1392
1703
|
}
|
|
1393
1704
|
}
|
|
1705
|
+
indicesArray() {
|
|
1706
|
+
return [...this.indices()];
|
|
1707
|
+
}
|
|
1708
|
+
valuesArray() {
|
|
1709
|
+
return [...this.values()];
|
|
1710
|
+
}
|
|
1394
1711
|
entriesArray() {
|
|
1395
1712
|
return [...this.entries()];
|
|
1396
1713
|
}
|
|
1714
|
+
*kvKeys() {
|
|
1715
|
+
for (const id of this.indices()) {
|
|
1716
|
+
yield [id];
|
|
1717
|
+
}
|
|
1718
|
+
}
|
|
1719
|
+
*kvValues() {
|
|
1720
|
+
for (const value of this.values()) {
|
|
1721
|
+
yield value;
|
|
1722
|
+
}
|
|
1723
|
+
}
|
|
1724
|
+
*kvEntries() {
|
|
1725
|
+
for (const [id, value] of this.entries()) {
|
|
1726
|
+
yield [[id], value];
|
|
1727
|
+
}
|
|
1728
|
+
}
|
|
1397
1729
|
*[Symbol.iterator]() {
|
|
1398
1730
|
yield* this.entries();
|
|
1399
1731
|
}
|
|
@@ -1411,21 +1743,21 @@ var IndexArray = class _IndexArray {
|
|
|
1411
1743
|
return this;
|
|
1412
1744
|
}
|
|
1413
1745
|
some(fn) {
|
|
1414
|
-
for (const [id,
|
|
1415
|
-
if (fn(
|
|
1746
|
+
for (const [id, value] of this.entries()) {
|
|
1747
|
+
if (fn(value, id)) return true;
|
|
1416
1748
|
}
|
|
1417
1749
|
return false;
|
|
1418
1750
|
}
|
|
1419
1751
|
every(fn) {
|
|
1420
|
-
for (const [id,
|
|
1421
|
-
if (!fn(
|
|
1752
|
+
for (const [id, value] of this.entries()) {
|
|
1753
|
+
if (!fn(value, id)) return false;
|
|
1422
1754
|
}
|
|
1423
1755
|
return true;
|
|
1424
1756
|
}
|
|
1425
|
-
filter(
|
|
1426
|
-
|
|
1427
|
-
for (const [id,
|
|
1428
|
-
if (
|
|
1757
|
+
filter(predicate) {
|
|
1758
|
+
const result = new this.constructor();
|
|
1759
|
+
for (const [id, value] of this.entries()) {
|
|
1760
|
+
if (predicate(value, id, this)) result.set(id, value);
|
|
1429
1761
|
}
|
|
1430
1762
|
return result;
|
|
1431
1763
|
}
|
|
@@ -1448,22 +1780,22 @@ var IndexArray = class _IndexArray {
|
|
|
1448
1780
|
start = first;
|
|
1449
1781
|
}
|
|
1450
1782
|
for (let current = start; !current.done; current = iterator.next()) {
|
|
1451
|
-
const [id,
|
|
1452
|
-
acc = fn(acc,
|
|
1783
|
+
const [id, value] = current.value;
|
|
1784
|
+
acc = fn(acc, value, id);
|
|
1453
1785
|
}
|
|
1454
1786
|
return acc;
|
|
1455
1787
|
}
|
|
1456
1788
|
mapToArray(fn) {
|
|
1457
1789
|
let result = [];
|
|
1458
|
-
for (const [id,
|
|
1459
|
-
result.push(fn(
|
|
1790
|
+
for (const [id, value] of this.entries()) {
|
|
1791
|
+
result.push(fn(value, id));
|
|
1460
1792
|
}
|
|
1461
1793
|
return result;
|
|
1462
1794
|
}
|
|
1463
1795
|
map(fn) {
|
|
1464
1796
|
let result = new _IndexArray();
|
|
1465
|
-
for (const [id,
|
|
1466
|
-
result.set(id, fn(
|
|
1797
|
+
for (const [id, value] of this.entries()) {
|
|
1798
|
+
result.set(id, fn(value, id));
|
|
1467
1799
|
}
|
|
1468
1800
|
return result;
|
|
1469
1801
|
}
|
|
@@ -1475,13 +1807,13 @@ var IndexArray = class _IndexArray {
|
|
|
1475
1807
|
const hasA = this.hasPos[i];
|
|
1476
1808
|
const hasB = other.hasPos[i];
|
|
1477
1809
|
if (hasA !== hasB) return false;
|
|
1478
|
-
if (hasA && !eq(this.
|
|
1810
|
+
if (hasA && !eq(this.posVal[i], other.posVal[i])) return false;
|
|
1479
1811
|
}
|
|
1480
1812
|
return true;
|
|
1481
1813
|
}
|
|
1482
1814
|
toString() {
|
|
1483
1815
|
if (this.size === 0) return `IndexArray[ ]`;
|
|
1484
|
-
const entries = this.entriesArray().map(([id,
|
|
1816
|
+
const entries = this.entriesArray().map(([id, value]) => `${id}: ${value}`).join(", ");
|
|
1485
1817
|
return `IndexArray[ ${entries} ]`;
|
|
1486
1818
|
}
|
|
1487
1819
|
};
|
|
@@ -1489,29 +1821,29 @@ var IndexArray = class _IndexArray {
|
|
|
1489
1821
|
// src/core/signed-index-array.ts
|
|
1490
1822
|
var SignedIndexArray = class _SignedIndexArray {
|
|
1491
1823
|
constructor(entries) {
|
|
1492
|
-
//
|
|
1493
|
-
__publicField(this, "
|
|
1824
|
+
// For indexes >= 0
|
|
1825
|
+
__publicField(this, "posVal");
|
|
1494
1826
|
__publicField(this, "hasPos");
|
|
1495
|
-
//
|
|
1496
|
-
__publicField(this, "
|
|
1827
|
+
// For indexes < 0
|
|
1828
|
+
__publicField(this, "negVal");
|
|
1497
1829
|
__publicField(this, "hasNeg");
|
|
1498
|
-
//
|
|
1499
|
-
__publicField(this, "
|
|
1830
|
+
// Number of values
|
|
1831
|
+
__publicField(this, "valCount");
|
|
1500
1832
|
if (entries instanceof _SignedIndexArray) {
|
|
1501
|
-
this.
|
|
1833
|
+
this.negVal = entries.negVal.slice();
|
|
1502
1834
|
this.hasNeg = entries.hasNeg.slice();
|
|
1503
|
-
this.
|
|
1835
|
+
this.posVal = entries.posVal.slice();
|
|
1504
1836
|
this.hasPos = entries.hasPos.slice();
|
|
1505
|
-
this.
|
|
1837
|
+
this.valCount = entries.valCount;
|
|
1506
1838
|
} else {
|
|
1507
|
-
this.
|
|
1839
|
+
this.negVal = [];
|
|
1508
1840
|
this.hasNeg = [];
|
|
1509
|
-
this.
|
|
1841
|
+
this.posVal = [];
|
|
1510
1842
|
this.hasPos = [];
|
|
1511
|
-
this.
|
|
1843
|
+
this.valCount = 0;
|
|
1512
1844
|
if (entries) {
|
|
1513
|
-
for (const [id,
|
|
1514
|
-
this.set(id,
|
|
1845
|
+
for (const [id, value] of entries) {
|
|
1846
|
+
this.set(id, value);
|
|
1515
1847
|
}
|
|
1516
1848
|
}
|
|
1517
1849
|
}
|
|
@@ -1524,7 +1856,10 @@ var SignedIndexArray = class _SignedIndexArray {
|
|
|
1524
1856
|
return id;
|
|
1525
1857
|
}
|
|
1526
1858
|
get size() {
|
|
1527
|
-
return this.
|
|
1859
|
+
return this.valCount;
|
|
1860
|
+
}
|
|
1861
|
+
isEmpty() {
|
|
1862
|
+
return this.size === 0;
|
|
1528
1863
|
}
|
|
1529
1864
|
get posLen() {
|
|
1530
1865
|
return this.hasPos.length;
|
|
@@ -1540,26 +1875,26 @@ var SignedIndexArray = class _SignedIndexArray {
|
|
|
1540
1875
|
return this.hasNeg[_SignedIndexArray.toNegIndex(id)] === true;
|
|
1541
1876
|
}
|
|
1542
1877
|
}
|
|
1543
|
-
set(id,
|
|
1878
|
+
set(id, value) {
|
|
1544
1879
|
_SignedIndexArray.validateIndex(id);
|
|
1545
1880
|
if (id >= 0) {
|
|
1546
|
-
if (this.hasPos[id] !== true) this.
|
|
1547
|
-
this.
|
|
1881
|
+
if (this.hasPos[id] !== true) this.valCount++;
|
|
1882
|
+
this.posVal[id] = value;
|
|
1548
1883
|
this.hasPos[id] = true;
|
|
1549
1884
|
} else {
|
|
1550
1885
|
let negId = _SignedIndexArray.toNegIndex(id);
|
|
1551
|
-
if (this.hasNeg[negId] !== true) this.
|
|
1552
|
-
this.
|
|
1886
|
+
if (this.hasNeg[negId] !== true) this.valCount++;
|
|
1887
|
+
this.negVal[negId] = value;
|
|
1553
1888
|
this.hasNeg[negId] = true;
|
|
1554
1889
|
}
|
|
1555
1890
|
}
|
|
1556
1891
|
get(id) {
|
|
1557
1892
|
_SignedIndexArray.validateIndex(id);
|
|
1558
1893
|
if (id >= 0) {
|
|
1559
|
-
return this.hasPos[id] ? this.
|
|
1894
|
+
return this.hasPos[id] ? this.posVal[id] : void 0;
|
|
1560
1895
|
} else {
|
|
1561
1896
|
let negId = _SignedIndexArray.toNegIndex(id);
|
|
1562
|
-
return this.hasNeg[negId] ? this.
|
|
1897
|
+
return this.hasNeg[negId] ? this.negVal[negId] : void 0;
|
|
1563
1898
|
}
|
|
1564
1899
|
}
|
|
1565
1900
|
getOrDefault(id, defaultValue) {
|
|
@@ -1576,25 +1911,25 @@ var SignedIndexArray = class _SignedIndexArray {
|
|
|
1576
1911
|
delete(id) {
|
|
1577
1912
|
_SignedIndexArray.validateIndex(id);
|
|
1578
1913
|
const isPos = id >= 0;
|
|
1579
|
-
const arr = isPos ? this.
|
|
1914
|
+
const arr = isPos ? this.posVal : this.negVal;
|
|
1580
1915
|
const has = isPos ? this.hasPos : this.hasNeg;
|
|
1581
1916
|
const idx = isPos ? id : _SignedIndexArray.toNegIndex(id);
|
|
1582
1917
|
if (!has[idx]) return false;
|
|
1583
1918
|
arr[idx] = void 0;
|
|
1584
1919
|
has[idx] = false;
|
|
1585
|
-
this.
|
|
1920
|
+
this.valCount--;
|
|
1586
1921
|
return true;
|
|
1587
1922
|
}
|
|
1588
1923
|
clear() {
|
|
1589
|
-
this.
|
|
1924
|
+
this.negVal = [];
|
|
1590
1925
|
this.hasNeg = [];
|
|
1591
|
-
this.
|
|
1926
|
+
this.posVal = [];
|
|
1592
1927
|
this.hasPos = [];
|
|
1593
|
-
this.
|
|
1928
|
+
this.valCount = 0;
|
|
1594
1929
|
}
|
|
1595
1930
|
forEach(callbackfn, thisArg) {
|
|
1596
|
-
for (const [id,
|
|
1597
|
-
callbackfn.call(thisArg,
|
|
1931
|
+
for (const [id, value] of this.entries()) {
|
|
1932
|
+
callbackfn.call(thisArg, value, id, this);
|
|
1598
1933
|
}
|
|
1599
1934
|
}
|
|
1600
1935
|
*indices() {
|
|
@@ -1605,31 +1940,46 @@ var SignedIndexArray = class _SignedIndexArray {
|
|
|
1605
1940
|
if (this.hasPos[id]) yield id;
|
|
1606
1941
|
}
|
|
1607
1942
|
}
|
|
1608
|
-
indicesArray() {
|
|
1609
|
-
return [...this.indices()];
|
|
1610
|
-
}
|
|
1611
1943
|
*values() {
|
|
1612
1944
|
for (let id = this.negLen - 1; id >= 0; id--) {
|
|
1613
|
-
if (this.hasNeg[id]) yield this.
|
|
1945
|
+
if (this.hasNeg[id]) yield this.negVal[id];
|
|
1614
1946
|
}
|
|
1615
1947
|
for (let id = 0; id < this.posLen; id++) {
|
|
1616
|
-
if (this.hasPos[id]) yield this.
|
|
1948
|
+
if (this.hasPos[id]) yield this.posVal[id];
|
|
1617
1949
|
}
|
|
1618
1950
|
}
|
|
1619
|
-
valuesArray() {
|
|
1620
|
-
return [...this.values()];
|
|
1621
|
-
}
|
|
1622
1951
|
*entries() {
|
|
1623
1952
|
for (let id = this.negLen - 1; id >= 0; id--) {
|
|
1624
|
-
if (this.hasNeg[id]) yield [_SignedIndexArray.toNegIndex(id), this.
|
|
1953
|
+
if (this.hasNeg[id]) yield [_SignedIndexArray.toNegIndex(id), this.negVal[id]];
|
|
1625
1954
|
}
|
|
1626
1955
|
for (let id = 0; id < this.posLen; id++) {
|
|
1627
|
-
if (this.hasPos[id]) yield [id, this.
|
|
1956
|
+
if (this.hasPos[id]) yield [id, this.posVal[id]];
|
|
1628
1957
|
}
|
|
1629
1958
|
}
|
|
1959
|
+
indicesArray() {
|
|
1960
|
+
return [...this.indices()];
|
|
1961
|
+
}
|
|
1962
|
+
valuesArray() {
|
|
1963
|
+
return [...this.values()];
|
|
1964
|
+
}
|
|
1630
1965
|
entriesArray() {
|
|
1631
1966
|
return [...this.entries()];
|
|
1632
1967
|
}
|
|
1968
|
+
*kvKeys() {
|
|
1969
|
+
for (const id of this.indices()) {
|
|
1970
|
+
yield [id];
|
|
1971
|
+
}
|
|
1972
|
+
}
|
|
1973
|
+
*kvValues() {
|
|
1974
|
+
for (const value of this.values()) {
|
|
1975
|
+
yield value;
|
|
1976
|
+
}
|
|
1977
|
+
}
|
|
1978
|
+
*kvEntries() {
|
|
1979
|
+
for (const [id, value] of this.entries()) {
|
|
1980
|
+
yield [[id], value];
|
|
1981
|
+
}
|
|
1982
|
+
}
|
|
1633
1983
|
*[Symbol.iterator]() {
|
|
1634
1984
|
yield* this.entries();
|
|
1635
1985
|
}
|
|
@@ -1647,21 +1997,21 @@ var SignedIndexArray = class _SignedIndexArray {
|
|
|
1647
1997
|
return this;
|
|
1648
1998
|
}
|
|
1649
1999
|
some(fn) {
|
|
1650
|
-
for (const [id,
|
|
1651
|
-
if (fn(
|
|
2000
|
+
for (const [id, value] of this.entries()) {
|
|
2001
|
+
if (fn(value, id)) return true;
|
|
1652
2002
|
}
|
|
1653
2003
|
return false;
|
|
1654
2004
|
}
|
|
1655
2005
|
every(fn) {
|
|
1656
|
-
for (const [id,
|
|
1657
|
-
if (!fn(
|
|
2006
|
+
for (const [id, value] of this.entries()) {
|
|
2007
|
+
if (!fn(value, id)) return false;
|
|
1658
2008
|
}
|
|
1659
2009
|
return true;
|
|
1660
2010
|
}
|
|
1661
|
-
filter(
|
|
1662
|
-
|
|
1663
|
-
for (const [id,
|
|
1664
|
-
if (
|
|
2011
|
+
filter(predicate) {
|
|
2012
|
+
const result = new this.constructor();
|
|
2013
|
+
for (const [id, value] of this.entries()) {
|
|
2014
|
+
if (predicate(value, id, this)) result.set(id, value);
|
|
1665
2015
|
}
|
|
1666
2016
|
return result;
|
|
1667
2017
|
}
|
|
@@ -1684,22 +2034,22 @@ var SignedIndexArray = class _SignedIndexArray {
|
|
|
1684
2034
|
start = first;
|
|
1685
2035
|
}
|
|
1686
2036
|
for (let current = start; !current.done; current = iterator.next()) {
|
|
1687
|
-
const [id,
|
|
1688
|
-
acc = fn(acc,
|
|
2037
|
+
const [id, value] = current.value;
|
|
2038
|
+
acc = fn(acc, value, id);
|
|
1689
2039
|
}
|
|
1690
2040
|
return acc;
|
|
1691
2041
|
}
|
|
1692
2042
|
mapToArray(fn) {
|
|
1693
2043
|
let result = [];
|
|
1694
|
-
for (const [id,
|
|
1695
|
-
result.push(fn(
|
|
2044
|
+
for (const [id, value] of this.entries()) {
|
|
2045
|
+
result.push(fn(value, id));
|
|
1696
2046
|
}
|
|
1697
2047
|
return result;
|
|
1698
2048
|
}
|
|
1699
2049
|
map(fn) {
|
|
1700
2050
|
let result = new _SignedIndexArray();
|
|
1701
|
-
for (const [id,
|
|
1702
|
-
result.set(id, fn(
|
|
2051
|
+
for (const [id, value] of this.entries()) {
|
|
2052
|
+
result.set(id, fn(value, id));
|
|
1703
2053
|
}
|
|
1704
2054
|
return result;
|
|
1705
2055
|
}
|
|
@@ -1711,25 +2061,25 @@ var SignedIndexArray = class _SignedIndexArray {
|
|
|
1711
2061
|
const hasA = this.hasPos[i];
|
|
1712
2062
|
const hasB = other.hasPos[i];
|
|
1713
2063
|
if (hasA !== hasB) return false;
|
|
1714
|
-
if (hasA && !eq(this.
|
|
2064
|
+
if (hasA && !eq(this.posVal[i], other.posVal[i])) return false;
|
|
1715
2065
|
}
|
|
1716
2066
|
const negLen = Math.max(this.negLen, other.negLen);
|
|
1717
2067
|
for (let i = 0; i < negLen; ++i) {
|
|
1718
2068
|
const hasA = this.hasNeg[i];
|
|
1719
2069
|
const hasB = other.hasNeg[i];
|
|
1720
2070
|
if (hasA !== hasB) return false;
|
|
1721
|
-
if (hasA && !eq(this.
|
|
2071
|
+
if (hasA && !eq(this.negVal[i], other.negVal[i])) return false;
|
|
1722
2072
|
}
|
|
1723
2073
|
return true;
|
|
1724
2074
|
}
|
|
1725
2075
|
toString() {
|
|
1726
2076
|
if (this.size === 0) return `SignedIndexArray[ ]`;
|
|
1727
|
-
const entries = this.entriesArray().map(([id,
|
|
2077
|
+
const entries = this.entriesArray().map(([id, value]) => `${id}: ${value}`).join(", ");
|
|
1728
2078
|
return `SignedIndexArray[ ${entries} ]`;
|
|
1729
2079
|
}
|
|
1730
2080
|
};
|
|
1731
2081
|
|
|
1732
|
-
// src/core/
|
|
2082
|
+
// src/core/map1.ts
|
|
1733
2083
|
var Map1 = class _Map1 {
|
|
1734
2084
|
constructor(entries) {
|
|
1735
2085
|
__publicField(this, "map1");
|
|
@@ -1765,28 +2115,46 @@ var Map1 = class _Map1 {
|
|
|
1765
2115
|
get size() {
|
|
1766
2116
|
return this.map1.size;
|
|
1767
2117
|
}
|
|
2118
|
+
isEmpty() {
|
|
2119
|
+
return this.size === 0;
|
|
2120
|
+
}
|
|
1768
2121
|
forEach(callbackfn, thisArg) {
|
|
1769
2122
|
this.map1.forEach((value, key1) => callbackfn.call(thisArg, value, key1, this));
|
|
1770
2123
|
}
|
|
1771
|
-
keys() {
|
|
1772
|
-
|
|
2124
|
+
*keys() {
|
|
2125
|
+
yield* this.map1.keys();
|
|
2126
|
+
}
|
|
2127
|
+
*values() {
|
|
2128
|
+
yield* this.map1.values();
|
|
2129
|
+
}
|
|
2130
|
+
*entries() {
|
|
2131
|
+
for (const [key1, value] of this.map1)
|
|
2132
|
+
yield [key1, value];
|
|
1773
2133
|
}
|
|
1774
2134
|
keysArray() {
|
|
1775
2135
|
return [...this.keys()];
|
|
1776
2136
|
}
|
|
1777
|
-
values() {
|
|
1778
|
-
return this.map1.values();
|
|
1779
|
-
}
|
|
1780
2137
|
valuesArray() {
|
|
1781
2138
|
return [...this.values()];
|
|
1782
2139
|
}
|
|
1783
|
-
*entries() {
|
|
1784
|
-
for (const [key1, value] of this.map1)
|
|
1785
|
-
yield [key1, value];
|
|
1786
|
-
}
|
|
1787
2140
|
entriesArray() {
|
|
1788
2141
|
return [...this.entries()];
|
|
1789
2142
|
}
|
|
2143
|
+
*kvKeys() {
|
|
2144
|
+
for (const key of this.keys()) {
|
|
2145
|
+
yield [key];
|
|
2146
|
+
}
|
|
2147
|
+
}
|
|
2148
|
+
*kvValues() {
|
|
2149
|
+
for (const el of this.values()) {
|
|
2150
|
+
yield el;
|
|
2151
|
+
}
|
|
2152
|
+
}
|
|
2153
|
+
*kvEntries() {
|
|
2154
|
+
for (const [key, el] of this.entries()) {
|
|
2155
|
+
yield [[key], el];
|
|
2156
|
+
}
|
|
2157
|
+
}
|
|
1790
2158
|
*[Symbol.iterator]() {
|
|
1791
2159
|
yield* this.entries();
|
|
1792
2160
|
}
|
|
@@ -1815,16 +2183,33 @@ var Map1 = class _Map1 {
|
|
|
1815
2183
|
}
|
|
1816
2184
|
return true;
|
|
1817
2185
|
}
|
|
1818
|
-
filter(
|
|
1819
|
-
|
|
2186
|
+
filter(predicate) {
|
|
2187
|
+
const result = new this.constructor();
|
|
1820
2188
|
for (const [key1, value] of this.map1) {
|
|
1821
|
-
if (
|
|
2189
|
+
if (predicate(value, key1, this)) result.set(key1, value);
|
|
1822
2190
|
}
|
|
1823
2191
|
return result;
|
|
1824
2192
|
}
|
|
1825
2193
|
reduce(fn, init) {
|
|
1826
|
-
let
|
|
1827
|
-
|
|
2194
|
+
let iterator = this.entries();
|
|
2195
|
+
let first = iterator.next();
|
|
2196
|
+
if (first.done) {
|
|
2197
|
+
if (arguments.length < 2) {
|
|
2198
|
+
throw new TypeError("Reduce of empty Map1 with no initial value!");
|
|
2199
|
+
}
|
|
2200
|
+
return init;
|
|
2201
|
+
}
|
|
2202
|
+
let acc;
|
|
2203
|
+
let start;
|
|
2204
|
+
if (arguments.length < 2) {
|
|
2205
|
+
acc = first.value[1];
|
|
2206
|
+
start = iterator.next();
|
|
2207
|
+
} else {
|
|
2208
|
+
acc = init;
|
|
2209
|
+
start = first;
|
|
2210
|
+
}
|
|
2211
|
+
for (let current = start; !current.done; current = iterator.next()) {
|
|
2212
|
+
const [key1, value] = current.value;
|
|
1828
2213
|
acc = fn(acc, value, key1);
|
|
1829
2214
|
}
|
|
1830
2215
|
return acc;
|
|
@@ -1848,9 +2233,11 @@ var Map1 = class _Map1 {
|
|
|
1848
2233
|
}
|
|
1849
2234
|
toString() {
|
|
1850
2235
|
const entries = [...this.map1].map(([k, v]) => `${k} => ${v}`).join(", ");
|
|
1851
|
-
return `Map1(${this.
|
|
2236
|
+
return entries.length === 0 ? `Map1(0){ }` : `Map1(${this.size}){ ${entries} }`;
|
|
1852
2237
|
}
|
|
1853
2238
|
};
|
|
2239
|
+
|
|
2240
|
+
// src/core/map2.ts
|
|
1854
2241
|
var Map2 = class _Map2 {
|
|
1855
2242
|
constructor(entries) {
|
|
1856
2243
|
__publicField(this, "map1", /* @__PURE__ */ new Map());
|
|
@@ -1902,39 +2289,48 @@ var Map2 = class _Map2 {
|
|
|
1902
2289
|
}
|
|
1903
2290
|
return count;
|
|
1904
2291
|
}
|
|
2292
|
+
isEmpty() {
|
|
2293
|
+
return this.size === 0;
|
|
2294
|
+
}
|
|
1905
2295
|
forEach(callbackfn, thisArg) {
|
|
1906
2296
|
this.map1.forEach((map2, key1) => map2.forEach((value, key2) => callbackfn.call(thisArg, value, key1, key2, this)));
|
|
1907
2297
|
}
|
|
1908
|
-
keys() {
|
|
1909
|
-
|
|
1910
|
-
for (const
|
|
1911
|
-
|
|
1912
|
-
yield [key1, key2];
|
|
1913
|
-
}
|
|
1914
|
-
return gen(this.map1);
|
|
1915
|
-
}
|
|
1916
|
-
keysArray() {
|
|
1917
|
-
return [...this.keys()];
|
|
1918
|
-
}
|
|
1919
|
-
values() {
|
|
1920
|
-
function* gen(map1) {
|
|
1921
|
-
for (const map2 of map1.values())
|
|
1922
|
-
for (const value of map2.values())
|
|
1923
|
-
yield value;
|
|
1924
|
-
}
|
|
1925
|
-
return gen(this.map1);
|
|
2298
|
+
*keys() {
|
|
2299
|
+
for (const [key1, map2] of this.map1)
|
|
2300
|
+
for (const key2 of map2.keys())
|
|
2301
|
+
yield [key1, key2];
|
|
1926
2302
|
}
|
|
1927
|
-
|
|
1928
|
-
|
|
2303
|
+
*values() {
|
|
2304
|
+
for (const map2 of this.map1.values())
|
|
2305
|
+
for (const value of map2.values())
|
|
2306
|
+
yield value;
|
|
1929
2307
|
}
|
|
1930
2308
|
*entries() {
|
|
1931
2309
|
for (const [key1, map2] of this.map1)
|
|
1932
2310
|
for (const [key2, value] of map2)
|
|
1933
2311
|
yield [key1, key2, value];
|
|
1934
2312
|
}
|
|
2313
|
+
keysArray() {
|
|
2314
|
+
return [...this.keys()];
|
|
2315
|
+
}
|
|
2316
|
+
valuesArray() {
|
|
2317
|
+
return [...this.values()];
|
|
2318
|
+
}
|
|
1935
2319
|
entriesArray() {
|
|
1936
2320
|
return [...this.entries()];
|
|
1937
2321
|
}
|
|
2322
|
+
*kvKeys() {
|
|
2323
|
+
for (const [key1, key2] of this.keys())
|
|
2324
|
+
yield [key1, key2];
|
|
2325
|
+
}
|
|
2326
|
+
*kvValues() {
|
|
2327
|
+
for (const el of this.values())
|
|
2328
|
+
yield el;
|
|
2329
|
+
}
|
|
2330
|
+
*kvEntries() {
|
|
2331
|
+
for (const [key1, key2, el] of this.entries())
|
|
2332
|
+
yield [[key1, key2], el];
|
|
2333
|
+
}
|
|
1938
2334
|
*[Symbol.iterator]() {
|
|
1939
2335
|
yield* this.entries();
|
|
1940
2336
|
}
|
|
@@ -1967,21 +2363,36 @@ var Map2 = class _Map2 {
|
|
|
1967
2363
|
}
|
|
1968
2364
|
return true;
|
|
1969
2365
|
}
|
|
1970
|
-
filter(
|
|
1971
|
-
|
|
2366
|
+
filter(predicate) {
|
|
2367
|
+
const result = new this.constructor();
|
|
1972
2368
|
for (const [key1, map2] of this.map1) {
|
|
1973
2369
|
for (const [key2, value] of map2) {
|
|
1974
|
-
if (
|
|
2370
|
+
if (predicate(value, key1, key2, this)) result.set(key1, key2, value);
|
|
1975
2371
|
}
|
|
1976
2372
|
}
|
|
1977
2373
|
return result;
|
|
1978
2374
|
}
|
|
1979
2375
|
reduce(fn, init) {
|
|
1980
|
-
let
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
2376
|
+
let iterator = this.entries();
|
|
2377
|
+
let first = iterator.next();
|
|
2378
|
+
if (first.done) {
|
|
2379
|
+
if (arguments.length < 2) {
|
|
2380
|
+
throw new TypeError("Reduce of empty Map2 with no initial value!");
|
|
1984
2381
|
}
|
|
2382
|
+
return init;
|
|
2383
|
+
}
|
|
2384
|
+
let acc;
|
|
2385
|
+
let start;
|
|
2386
|
+
if (arguments.length < 2) {
|
|
2387
|
+
acc = first.value[2];
|
|
2388
|
+
start = iterator.next();
|
|
2389
|
+
} else {
|
|
2390
|
+
acc = init;
|
|
2391
|
+
start = first;
|
|
2392
|
+
}
|
|
2393
|
+
for (let current = start; !current.done; current = iterator.next()) {
|
|
2394
|
+
const [key1, key2, value] = current.value;
|
|
2395
|
+
acc = fn(acc, value, key1, key2);
|
|
1985
2396
|
}
|
|
1986
2397
|
return acc;
|
|
1987
2398
|
}
|
|
@@ -2018,9 +2429,11 @@ var Map2 = class _Map2 {
|
|
|
2018
2429
|
const inner = [...map2].map(([key2, v]) => `${key2} => ${v}`).join(", ");
|
|
2019
2430
|
entries.push(`${key1} => { ${inner} }`);
|
|
2020
2431
|
}
|
|
2021
|
-
return `Map2(${this.size})
|
|
2432
|
+
return entries.length === 0 ? `Map2(0){ }` : `Map2(${this.size}){ ${entries} }`;
|
|
2022
2433
|
}
|
|
2023
2434
|
};
|
|
2435
|
+
|
|
2436
|
+
// src/core/map3.ts
|
|
2024
2437
|
var Map3 = class _Map3 {
|
|
2025
2438
|
constructor(entries) {
|
|
2026
2439
|
__publicField(this, "map1", /* @__PURE__ */ new Map());
|
|
@@ -2088,32 +2501,23 @@ var Map3 = class _Map3 {
|
|
|
2088
2501
|
}
|
|
2089
2502
|
return count;
|
|
2090
2503
|
}
|
|
2504
|
+
isEmpty() {
|
|
2505
|
+
return this.size === 0;
|
|
2506
|
+
}
|
|
2091
2507
|
forEach(callbackfn, thisArg) {
|
|
2092
2508
|
this.map1.forEach((map2, key1) => map2.forEach((map3, key2) => map3.forEach((value, key3) => callbackfn.call(thisArg, value, key1, key2, key3, this))));
|
|
2093
2509
|
}
|
|
2094
|
-
keys() {
|
|
2095
|
-
|
|
2096
|
-
for (const [
|
|
2097
|
-
for (const
|
|
2098
|
-
|
|
2099
|
-
yield [key1, key2, key3];
|
|
2100
|
-
}
|
|
2101
|
-
return gen(this.map1);
|
|
2102
|
-
}
|
|
2103
|
-
keysArray() {
|
|
2104
|
-
return [...this.keys()];
|
|
2105
|
-
}
|
|
2106
|
-
values() {
|
|
2107
|
-
function* gen(map1) {
|
|
2108
|
-
for (const map2 of map1.values())
|
|
2109
|
-
for (const map3 of map2.values())
|
|
2110
|
-
for (const value of map3.values())
|
|
2111
|
-
yield value;
|
|
2112
|
-
}
|
|
2113
|
-
return gen(this.map1);
|
|
2510
|
+
*keys() {
|
|
2511
|
+
for (const [key1, map2] of this.map1)
|
|
2512
|
+
for (const [key2, map3] of map2)
|
|
2513
|
+
for (const key3 of map3.keys())
|
|
2514
|
+
yield [key1, key2, key3];
|
|
2114
2515
|
}
|
|
2115
|
-
|
|
2116
|
-
|
|
2516
|
+
*values() {
|
|
2517
|
+
for (const map2 of this.map1.values())
|
|
2518
|
+
for (const map3 of map2.values())
|
|
2519
|
+
for (const value of map3.values())
|
|
2520
|
+
yield value;
|
|
2117
2521
|
}
|
|
2118
2522
|
*entries() {
|
|
2119
2523
|
for (const [key1, map2] of this.map1)
|
|
@@ -2121,9 +2525,27 @@ var Map3 = class _Map3 {
|
|
|
2121
2525
|
for (const [key3, value] of map3)
|
|
2122
2526
|
yield [key1, key2, key3, value];
|
|
2123
2527
|
}
|
|
2528
|
+
keysArray() {
|
|
2529
|
+
return [...this.keys()];
|
|
2530
|
+
}
|
|
2531
|
+
valuesArray() {
|
|
2532
|
+
return [...this.values()];
|
|
2533
|
+
}
|
|
2124
2534
|
entriesArray() {
|
|
2125
2535
|
return [...this.entries()];
|
|
2126
2536
|
}
|
|
2537
|
+
*kvKeys() {
|
|
2538
|
+
for (const [key1, key2, key3] of this.keys())
|
|
2539
|
+
yield [key1, key2, key3];
|
|
2540
|
+
}
|
|
2541
|
+
*kvValues() {
|
|
2542
|
+
for (const el of this.values())
|
|
2543
|
+
yield el;
|
|
2544
|
+
}
|
|
2545
|
+
*kvEntries() {
|
|
2546
|
+
for (const [key1, key2, key3, el] of this.entries())
|
|
2547
|
+
yield [[key1, key2, key3], el];
|
|
2548
|
+
}
|
|
2127
2549
|
*[Symbol.iterator]() {
|
|
2128
2550
|
yield* this.entries();
|
|
2129
2551
|
}
|
|
@@ -2160,25 +2582,38 @@ var Map3 = class _Map3 {
|
|
|
2160
2582
|
}
|
|
2161
2583
|
return true;
|
|
2162
2584
|
}
|
|
2163
|
-
filter(
|
|
2164
|
-
|
|
2585
|
+
filter(predicate) {
|
|
2586
|
+
const result = new this.constructor();
|
|
2165
2587
|
for (const [key1, map2] of this.map1) {
|
|
2166
2588
|
for (const [key2, map3] of map2) {
|
|
2167
2589
|
for (const [key3, value] of map3) {
|
|
2168
|
-
if (
|
|
2590
|
+
if (predicate(value, key1, key2, key3, this)) result.set(key1, key2, key3, value);
|
|
2169
2591
|
}
|
|
2170
2592
|
}
|
|
2171
2593
|
}
|
|
2172
2594
|
return result;
|
|
2173
2595
|
}
|
|
2174
2596
|
reduce(fn, init) {
|
|
2175
|
-
let
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
|
|
2179
|
-
|
|
2180
|
-
}
|
|
2597
|
+
let iterator = this.entries();
|
|
2598
|
+
let first = iterator.next();
|
|
2599
|
+
if (first.done) {
|
|
2600
|
+
if (arguments.length < 2) {
|
|
2601
|
+
throw new TypeError("Reduce of empty Map3 with no initial value!");
|
|
2181
2602
|
}
|
|
2603
|
+
return init;
|
|
2604
|
+
}
|
|
2605
|
+
let acc;
|
|
2606
|
+
let start;
|
|
2607
|
+
if (arguments.length < 2) {
|
|
2608
|
+
acc = first.value[3];
|
|
2609
|
+
start = iterator.next();
|
|
2610
|
+
} else {
|
|
2611
|
+
acc = init;
|
|
2612
|
+
start = first;
|
|
2613
|
+
}
|
|
2614
|
+
for (let current = start; !current.done; current = iterator.next()) {
|
|
2615
|
+
const [key1, key2, key3, value] = current.value;
|
|
2616
|
+
acc = fn(acc, value, key1, key2, key3);
|
|
2182
2617
|
}
|
|
2183
2618
|
return acc;
|
|
2184
2619
|
}
|
|
@@ -2223,7 +2658,7 @@ var Map3 = class _Map3 {
|
|
|
2223
2658
|
entries.push(`${key1} => ${key2} => { ${inner} }`);
|
|
2224
2659
|
}
|
|
2225
2660
|
}
|
|
2226
|
-
return `Map3(${this.size})
|
|
2661
|
+
return entries.length === 0 ? `Map3(0){ }` : `Map3(${this.size}){ ${entries.join(", ")} }`;
|
|
2227
2662
|
}
|
|
2228
2663
|
};
|
|
2229
2664
|
|
|
@@ -2232,6 +2667,12 @@ var MultiContainer = class {
|
|
|
2232
2667
|
constructor(base) {
|
|
2233
2668
|
this.base = base;
|
|
2234
2669
|
}
|
|
2670
|
+
isEmpty() {
|
|
2671
|
+
return this.base.isEmpty();
|
|
2672
|
+
}
|
|
2673
|
+
clear() {
|
|
2674
|
+
this.base.clear?.();
|
|
2675
|
+
}
|
|
2235
2676
|
add(...keysAndValue) {
|
|
2236
2677
|
const keys = keysAndValue.slice(0, -1);
|
|
2237
2678
|
const value = keysAndValue[keysAndValue.length - 1];
|
|
@@ -2254,23 +2695,124 @@ var MultiContainer = class {
|
|
|
2254
2695
|
return this.base.get(...keys) ?? [];
|
|
2255
2696
|
}
|
|
2256
2697
|
*iterAll(...keys) {
|
|
2257
|
-
|
|
2258
|
-
|
|
2259
|
-
|
|
2698
|
+
yield* this.getAll(...keys);
|
|
2699
|
+
}
|
|
2700
|
+
*values() {
|
|
2701
|
+
for (const keys of this.keys()) {
|
|
2702
|
+
yield* this.getAll(...keys);
|
|
2260
2703
|
}
|
|
2261
2704
|
}
|
|
2262
|
-
|
|
2263
|
-
this.base.
|
|
2705
|
+
*keys() {
|
|
2706
|
+
for (const keys of this.base.kvKeys()) {
|
|
2707
|
+
yield keys;
|
|
2708
|
+
}
|
|
2709
|
+
}
|
|
2710
|
+
*entries() {
|
|
2711
|
+
for (const keys of this.keys()) {
|
|
2712
|
+
const arr = this.getAll(...keys);
|
|
2713
|
+
if (arr.length > 0) yield [keys, arr];
|
|
2714
|
+
}
|
|
2715
|
+
}
|
|
2716
|
+
[Symbol.iterator]() {
|
|
2717
|
+
return this.entries();
|
|
2718
|
+
}
|
|
2719
|
+
toString() {
|
|
2720
|
+
const entries = [];
|
|
2721
|
+
for (const keys of this.keys()) {
|
|
2722
|
+
const arr = this.getAll(...keys);
|
|
2723
|
+
const keyStr = Array.isArray(keys) ? `[${keys.map((k) => JSON.stringify(k)).join(", ")}]` : `[${JSON.stringify(keys)}]`;
|
|
2724
|
+
const valuesStr = Array.isArray(arr) ? `[${arr.map((v) => JSON.stringify(v)).join(", ")}]` : "[]";
|
|
2725
|
+
entries.push(`${keyStr} => ${valuesStr}`);
|
|
2726
|
+
}
|
|
2727
|
+
return `MultiContainer{ ${entries.join(", ")} }`;
|
|
2264
2728
|
}
|
|
2265
2729
|
};
|
|
2266
2730
|
function asMulti(base) {
|
|
2267
2731
|
return new MultiContainer(base);
|
|
2268
2732
|
}
|
|
2733
|
+
|
|
2734
|
+
// src/core/deprecated/vec2.ts
|
|
2735
|
+
var Vec2 = class _Vec2 {
|
|
2736
|
+
constructor(x, y) {
|
|
2737
|
+
__publicField(this, "x");
|
|
2738
|
+
__publicField(this, "y");
|
|
2739
|
+
this.x = x ?? 0;
|
|
2740
|
+
this.y = y ?? 0;
|
|
2741
|
+
}
|
|
2742
|
+
length() {
|
|
2743
|
+
return Math.sqrt(this.x * this.x + this.y * this.y);
|
|
2744
|
+
}
|
|
2745
|
+
add(a) {
|
|
2746
|
+
return new _Vec2(this.x + a.x, this.y + a.y);
|
|
2747
|
+
}
|
|
2748
|
+
sub(a) {
|
|
2749
|
+
return new _Vec2(this.x - a.x, this.y - a.y);
|
|
2750
|
+
}
|
|
2751
|
+
mul(a) {
|
|
2752
|
+
return new _Vec2(this.x * a, this.y * a);
|
|
2753
|
+
}
|
|
2754
|
+
div(a) {
|
|
2755
|
+
return new _Vec2(this.x / a, this.y / a);
|
|
2756
|
+
}
|
|
2757
|
+
};
|
|
2758
|
+
|
|
2759
|
+
// src/core/deprecated/small-int-cache.ts
|
|
2760
|
+
var SmallIntCache = class {
|
|
2761
|
+
// for keys < 0
|
|
2762
|
+
constructor() {
|
|
2763
|
+
__publicField(this, "pos");
|
|
2764
|
+
// for keys >= 0
|
|
2765
|
+
__publicField(this, "neg");
|
|
2766
|
+
this.pos = [];
|
|
2767
|
+
this.neg = [];
|
|
2768
|
+
}
|
|
2769
|
+
set(key, value) {
|
|
2770
|
+
if (!isInteger(key)) {
|
|
2771
|
+
throw new Error("Key must be an integer");
|
|
2772
|
+
} else if (key >= 0) {
|
|
2773
|
+
this.pos[key] = value;
|
|
2774
|
+
} else {
|
|
2775
|
+
this.neg[-key - 1] = value;
|
|
2776
|
+
}
|
|
2777
|
+
}
|
|
2778
|
+
get(key) {
|
|
2779
|
+
if (!isInteger(key)) {
|
|
2780
|
+
throw new Error("Key must be an integer");
|
|
2781
|
+
} else if (key >= 0) {
|
|
2782
|
+
return this.pos[key];
|
|
2783
|
+
} else {
|
|
2784
|
+
return this.neg[-key - 1];
|
|
2785
|
+
}
|
|
2786
|
+
}
|
|
2787
|
+
has(key) {
|
|
2788
|
+
if (!isInteger(key)) {
|
|
2789
|
+
return false;
|
|
2790
|
+
} else if (key >= 0) {
|
|
2791
|
+
return key in this.pos;
|
|
2792
|
+
} else {
|
|
2793
|
+
return -key - 1 in this.neg;
|
|
2794
|
+
}
|
|
2795
|
+
}
|
|
2796
|
+
delete(key) {
|
|
2797
|
+
if (!isInteger(key)) {
|
|
2798
|
+
return;
|
|
2799
|
+
} else if (key >= 0) {
|
|
2800
|
+
delete this.pos[key];
|
|
2801
|
+
} else {
|
|
2802
|
+
delete this.neg[-key - 1];
|
|
2803
|
+
}
|
|
2804
|
+
}
|
|
2805
|
+
clear() {
|
|
2806
|
+
this.pos = [];
|
|
2807
|
+
this.neg = [];
|
|
2808
|
+
}
|
|
2809
|
+
};
|
|
2269
2810
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2270
2811
|
0 && (module.exports = {
|
|
2271
2812
|
Assert,
|
|
2272
2813
|
Cookies,
|
|
2273
2814
|
Device,
|
|
2815
|
+
DivRect,
|
|
2274
2816
|
IndexArray,
|
|
2275
2817
|
LRUCache,
|
|
2276
2818
|
Map1,
|
|
@@ -2281,6 +2823,7 @@ function asMulti(base) {
|
|
|
2281
2823
|
SmallIntCache,
|
|
2282
2824
|
Stack,
|
|
2283
2825
|
Utils,
|
|
2826
|
+
Vec,
|
|
2284
2827
|
Vec2,
|
|
2285
2828
|
asMulti
|
|
2286
2829
|
});
|