@dra2020/baseclient 1.0.173 → 1.0.174
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/baseclient.js
CHANGED
|
@@ -3451,6 +3451,16 @@ function reverseBlockMapping(bm) {
|
|
|
3451
3451
|
Object.values(rev).forEach((a) => a.sort());
|
|
3452
3452
|
return rev;
|
|
3453
3453
|
}
|
|
3454
|
+
// A set of block mappings consulted as one, without copying any of them.
|
|
3455
|
+
//
|
|
3456
|
+
// Entries are either independent (e.g. one per state of a multi-state map, whose block ids never
|
|
3457
|
+
// overlap) or overlapping (a base mapping followed by overrides such as precinct updates). Overlapping
|
|
3458
|
+
// entries must be added in priority order: map() and rev() walk from the last entry back, so a later
|
|
3459
|
+
// entry wins.
|
|
3460
|
+
//
|
|
3461
|
+
// A full block mapping, and the reverse mapping computed from it, are large (TX has ~670K blocks), so
|
|
3462
|
+
// combining mappings shares them rather than copying: add() takes an already-computed reverse mapping,
|
|
3463
|
+
// and addFrom() takes both from another MultiBlockMapping.
|
|
3454
3464
|
class MultiBlockMapping {
|
|
3455
3465
|
constructor(tag, bm) {
|
|
3456
3466
|
this.entries = [];
|
|
@@ -3458,16 +3468,30 @@ class MultiBlockMapping {
|
|
|
3458
3468
|
if (tag && bm)
|
|
3459
3469
|
this.entries.push({ tag, bm });
|
|
3460
3470
|
}
|
|
3461
|
-
|
|
3462
|
-
|
|
3471
|
+
// Adds or replaces the entry for tag. Pass rbm when the reverse mapping of bm is already computed,
|
|
3472
|
+
// so it is shared rather than built again.
|
|
3473
|
+
add(tag, bm, rbm) {
|
|
3474
|
+
let e = this.entries.find(e => e.tag === tag);
|
|
3475
|
+
if (e) {
|
|
3463
3476
|
e.bm = bm;
|
|
3464
|
-
|
|
3465
|
-
|
|
3466
|
-
|
|
3467
|
-
|
|
3468
|
-
|
|
3477
|
+
if (rbm)
|
|
3478
|
+
e.rbm = rbm;
|
|
3479
|
+
else
|
|
3480
|
+
delete e.rbm;
|
|
3481
|
+
}
|
|
3482
|
+
else
|
|
3483
|
+
this.entries.push(rbm ? { tag, bm, rbm } : { tag, bm });
|
|
3469
3484
|
this.stamp++;
|
|
3470
3485
|
}
|
|
3486
|
+
// Adds the entry for tag from another mapping - or, with no tag, all of its entries in order - sharing
|
|
3487
|
+
// both the block mapping and its reverse mapping. The reverse mapping is computed on the source first
|
|
3488
|
+
// if need be, so that it is built once, there, and not separately in each mapping that shares it.
|
|
3489
|
+
addFrom(src, tag) {
|
|
3490
|
+
src.entries.forEach(e => {
|
|
3491
|
+
if (tag === undefined || e.tag === tag)
|
|
3492
|
+
this.add(e.tag, e.bm, src.rbmOf(e.tag));
|
|
3493
|
+
});
|
|
3494
|
+
}
|
|
3471
3495
|
remove(tag) {
|
|
3472
3496
|
for (let i = this.entries.length - 1; i >= 0; i--)
|
|
3473
3497
|
if (this.entries[i].tag === tag) {
|
|
@@ -3475,6 +3499,9 @@ class MultiBlockMapping {
|
|
|
3475
3499
|
this.entries.splice(i, 1);
|
|
3476
3500
|
}
|
|
3477
3501
|
}
|
|
3502
|
+
has(tag) {
|
|
3503
|
+
return this.entries.some(e => e.tag === tag);
|
|
3504
|
+
}
|
|
3478
3505
|
map(blockid) {
|
|
3479
3506
|
// Walk backwards to pick up overrides first
|
|
3480
3507
|
for (let i = this.entries.length - 1; i >= 0; i--) {
|
|
@@ -3494,6 +3521,17 @@ class MultiBlockMapping {
|
|
|
3494
3521
|
let e = this.entries.find(e => e.tag === tag);
|
|
3495
3522
|
return e ? e.bm : null;
|
|
3496
3523
|
}
|
|
3524
|
+
// The reverse mapping of the entry for tag, computed on first use.
|
|
3525
|
+
rbmOf(tag) {
|
|
3526
|
+
let e = this.entries.find(e => e.tag === tag);
|
|
3527
|
+
if (!e)
|
|
3528
|
+
return null;
|
|
3529
|
+
if (!e.rbm)
|
|
3530
|
+
e.rbm = reverseBlockMapping(e.bm);
|
|
3531
|
+
return e.rbm;
|
|
3532
|
+
}
|
|
3533
|
+
// Maps through the first entry only. Meaningful only where that entry is the base mapping and the
|
|
3534
|
+
// rest are overrides; for independent entries (a multi-state mapping) use map().
|
|
3497
3535
|
mapmain(blockid) {
|
|
3498
3536
|
return this.entries.length ? this.entries[0].bm[blockid] : undefined;
|
|
3499
3537
|
}
|
|
@@ -3507,10 +3545,18 @@ class MultiBlockMapping {
|
|
|
3507
3545
|
}
|
|
3508
3546
|
return undefined;
|
|
3509
3547
|
}
|
|
3510
|
-
//
|
|
3511
|
-
|
|
3512
|
-
|
|
3513
|
-
|
|
3548
|
+
// Walks the blocks of one entry: the one for tag, or with no tag the first. This is the right walk
|
|
3549
|
+
// over "all blocks" only when that entry is a base mapping covering them and the others are overrides
|
|
3550
|
+
// of it - it sees nothing of a multi-state mapping but its first state. See forEachBlock.
|
|
3551
|
+
forEachBase(cb, tag) {
|
|
3552
|
+
let e = tag === undefined ? this.entries[0] : this.entries.find(e => e.tag === tag);
|
|
3553
|
+
if (e)
|
|
3554
|
+
Object.keys(e.bm).forEach(blockid => cb(blockid));
|
|
3555
|
+
}
|
|
3556
|
+
// Walks the blocks of every entry. A block mapped by several entries (a base and its overrides) is
|
|
3557
|
+
// visited once for each of them; independent entries (a multi-state mapping) never repeat a block.
|
|
3558
|
+
forEachBlock(cb) {
|
|
3559
|
+
this.entries.forEach(e => Object.keys(e.bm).forEach(blockid => cb(blockid)));
|
|
3514
3560
|
}
|
|
3515
3561
|
// Walk maps in reverse order, careful to not invoke on same geoid
|
|
3516
3562
|
forEachRev(cb) {
|